Skip to content

feat: post with custom params - #75

Open
abergasov wants to merge 201 commits into
mainfrom
_post_with_custom_params
Open

feat: post with custom params#75
abergasov wants to merge 201 commits into
mainfrom
_post_with_custom_params

Conversation

@abergasov

@abergasov abergasov commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor
    • Enhanced HTTP request handling with improved response decoding configuration capabilities, enabling more flexible and customizable network communication workflows throughout the system.

✏️ Tip: You can customize this high-level summary in your review settings.

abergasov and others added 25 commits November 3, 2025 13:22
* new field in confgi

* version bump

* version bump

* rename field
feat: add gateway utilities to common library
feat: migrate proxy utilities to common library
* identity code added
* hash missed field

* tests fix
* slice util helpers

* Update pkg/utils/sliceutil_test.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* dynamic config helpers

* validate chainid

* test fix
* ttl upsert method

* review fixes
* pin runners to hash
* added DoAndApply
feat: add generic RotatingFileWriter utility
fix: make TestRenewConfig skip on timeout instead of failing
fix: address all golangci-lint issues
@coderabbitai

coderabbitai Bot commented Jan 7, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This change introduces a configurable decoding mechanism for HTTP responses in the request utility package using the options pattern. A new CurlConf[T] struct encapsulates a custom decoder function, applied via CurlOpts[T] functional options. The WithDecoder helper enables consumers to provide custom decoders. Existing functions—PostCurl, CurlWithBody, and PatchCurl—are updated to accept and thread this configuration through the request execution flow, with CurlWithBody conditionally using the provided decoder if available.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


📜 Recent review details

Configuration used: Repository: getoptimum/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 2f0b620 and d5f17f2.

📒 Files selected for processing (1)
  • pkg/utils/request.go
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (Custom checks)

Watch for goroutine leaks, unbounded channels, and racy access; ensure contexts are plumbed and respected

Files:

  • pkg/utils/request.go

⚙️ CodeRabbit configuration file

Review Go code for: idiomatic patterns, error handling (check all errors), concurrency safety (context propagation, goroutine cleanup), test coverage for changed logic, exported API stability, memory efficiency (avoid unnecessary allocations), and prefer standard library over third-party when reasonable.

Files:

  • pkg/utils/request.go
**/*

⚙️ CodeRabbit configuration file

**/*: When you find the same underlying issue in multiple locations (same pattern, same fix):

  • Do NOT post separate comments for each occurrence.
  • Post a single primary comment on the first occurrence.
  • In that comment, include a short list of “Also at: file:line” references
    for the other locations (e.g. 'Also at: foo.go:42, bar.go:17').
    Prioritize signal over volume: one strong comment that references multiple
    locations is preferred over many near-identical comments.

Files:

  • pkg/utils/request.go
🔇 Additional comments (2)
pkg/utils/request.go (2)

13-23: LGTM! Clean options pattern implementation.

The functional options pattern is idiomatic and allows for future extensibility. The generic types are properly constrained.


33-43: LGTM! Options pattern correctly implemented.

The variadic options parameter is backwards-compatible, and the config building logic is clean and idiomatic.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
pkg/utils/request.go (4)

25-31: Add options support to align with PostCurl and GetCurl.

PatchCurl does not support custom decoders via options, while PostCurl (line 33) and GetCurl (line 67) both do. This API inconsistency limits functionality and creates an uneven developer experience.

🔧 Proposed fix to add options support
-func PatchCurl[T any](ctx context.Context, targetURL string, payload any, headers map[string]string) (res *T, statusCode int, err error) {
+func PatchCurl[T any](ctx context.Context, targetURL string, payload any, headers map[string]string, opts ...CurlOpts[T]) (res *T, statusCode int, err error) {
+	config := &CurlConf[T]{}
+	for _, opt := range opts {
+		opt(config)
+	}
 	payloadJSON, err := json.Marshal(payload)
 	if err != nil {
 		return res, 0, fmt.Errorf("unable to marshal payload: %w", err)
 	}
-	return CurlWithBody[T](ctx, http.MethodPatch, targetURL, payloadJSON, headers, nil)
+	return CurlWithBody[T](ctx, http.MethodPatch, targetURL, payloadJSON, headers, config)
 }

45-60: LGTM! Decoder configuration properly threaded through.

The conditional logic correctly handles both nil and non-nil config cases. Context propagation is proper.

Optional micro-optimization: The two branches (lines 56-59) could be unified since both may pass a nil decoder:

decoder := (*func(io.Reader) error)(nil)
if cfg != nil {
	decoder = cfg.Decoder
}
return executeWithDefaultClient[T](req, decoder)

However, the current approach is equally clear.


90-92: Decoder usage returns nil result, breaking the function contract.

When a custom decoder is provided, the function returns nil for the result (line 91) while the signature promises *T. Callers may expect to receive both a decoded result and use the decoder for side effects, leading to nil pointer dereferences.

Consider returning a zero value or documenting that decoders are responsible for all result handling and that the returned *T must be ignored.


82-88: Address the timeout TODO for production reliability.

The TODO (line 82) correctly identifies that http.DefaultClient lacks timeout configuration, allowing requests to hang indefinitely. This impacts all exported functions: PostCurl, PatchCurl, GetCurl, and CurlWithBody.

Consider creating a package-level client with sensible defaults:

var defaultClient = &http.Client{
	Timeout: 30 * time.Second,
}

Then use defaultClient.Do(req) instead of http.DefaultClient.Do(req) at line 85.

📜 Review details

Configuration used: Repository: getoptimum/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 2f0b620 and d5f17f2.

📒 Files selected for processing (1)
  • pkg/utils/request.go
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (Custom checks)

Watch for goroutine leaks, unbounded channels, and racy access; ensure contexts are plumbed and respected

Files:

  • pkg/utils/request.go

⚙️ CodeRabbit configuration file

Review Go code for: idiomatic patterns, error handling (check all errors), concurrency safety (context propagation, goroutine cleanup), test coverage for changed logic, exported API stability, memory efficiency (avoid unnecessary allocations), and prefer standard library over third-party when reasonable.

Files:

  • pkg/utils/request.go
**/*

⚙️ CodeRabbit configuration file

**/*: When you find the same underlying issue in multiple locations (same pattern, same fix):

  • Do NOT post separate comments for each occurrence.
  • Post a single primary comment on the first occurrence.
  • In that comment, include a short list of “Also at: file:line” references
    for the other locations (e.g. 'Also at: foo.go:42, bar.go:17').
    Prioritize signal over volume: one strong comment that references multiple
    locations is preferred over many near-identical comments.

Files:

  • pkg/utils/request.go
🔇 Additional comments (2)
pkg/utils/request.go (2)

13-23: LGTM! Clean options pattern implementation.

The functional options pattern is idiomatic and allows for future extensibility. The generic types are properly constrained.


33-43: LGTM! Options pattern correctly implemented.

The variadic options parameter is backwards-compatible, and the config building logic is clean and idiomatic.

hpsing
hpsing previously approved these changes May 18, 2026
@abergasov
abergasov dismissed hpsing’s stale review July 7, 2026 15:15

The merge-base changed after approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants