-
Notifications
You must be signed in to change notification settings - Fork 1
Breaking: refactor usage to delay type specification #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the hoglet circuit breaker library to decouple the Circuit from specific function types, enabling reuse of a single Circuit instance across multiple functions. The key architectural change replaces the generic Circuit[IN, OUT] type with a non-generic Circuit struct, and introduces a new Wrap function to adapt user functions to the circuit breaker pattern. This improves API flexibility and reduces type parameter complexity.
Key Changes
- Replaced generic
Circuit[IN, OUT]with non-genericCircuitstruct, moving function wrapping logic fromNewCircuitto a newWrapfunction - Updated Go version to 1.24.0 and bumped
golang.org/x/syncdependency to v0.18.0 - Updated all tests and examples to use the new API pattern with
Wrap(circuit, func)instead ofcircuit.Call(...)
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| hoglet.go | Core API refactor: removed generics from Circuit type, introduced Wrap function, renamed WrappedFunc to WrappableFunc |
| hoglet_test.go | Updated tests and benchmarks to use new Wrap API, improved benchmark setup by caching wrapped functions, removed obsolete tt := tt pattern |
| options_test.go | Changed package to hoglet_test for better test isolation, updated tests to use new Wrap API |
| example_test.go | Updated all examples to demonstrate new Wrap API pattern |
| go.mod | Updated Go version to 1.24.0 and golang.org/x/sync to v0.18.0, removed unused protobuf dependency |
| go.sum | Updated checksums for dependency changes |
| .gitignore | Added *.profile pattern for profiling artifacts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // [ErrCircuitOpen]. | ||
| // Wrap wraps the provided function with the given [Circuit]. | ||
| // | ||
| // Calling the returned function if the circuit is closed and returns the result of the wrapped function. |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar issue: "Calling the returned function if the circuit is closed" should be "Calls the returned function if the circuit is closed" or "The returned function calls the wrapped function if the circuit is closed".
| // Calling the returned function if the circuit is closed and returns the result of the wrapped function. | |
| // The returned function calls the wrapped function if the circuit is closed and returns its result. |
This makes the circuit itself type-agnostic, allowing reuse of circuits for multiple functions with different types. BREAKING CHANGE: circuit initialization now does not require the function and does not provide the Call() method anymore, instead relying on the package-level Wrap().
0b4fb83 to
f99c9ae
Compare
This pull request introduces a significant refactor to the
hogletcircuit breaker library, focusing on simplifying the API, improving type safety, and modernizing the codebase. The most notable change is the removal of the genericCircuittype in favor of a non-genericCircuitstruct, with a newWrapfunction to adapt user functions to the circuit breaker. The tests and examples have been updated to use the new API. Additionally, dependencies and the Go version have been updated.❌ Old
🟢 New
This allows reusing the same circuit for multiple different functions.
Details:
API Refactor and Simplification:
Replaced the generic
Circuit[IN, OUT]type with a non-genericCircuitstruct, and removed the function parameter fromNewCircuit. Instead, user functions are now wrapped using a new genericWrapfunction, which applies the circuit breaker to any compatible function. (hoglet.go,example_test.go,hoglet_test.go,options_test.go) [1] [2] [3] [4] [5] [6] [7] [8]Updated all usages in tests and examples to use
Wrap(circuit, func)instead of the previouscircuit.Call(...)method, ensuring consistency and demonstrating the new API. (example_test.go,hoglet_test.go,options_test.go) [1] [2] [3] [4] [5] [6] [7]Type and Naming Improvements:
WrappableFuncas the new type for functions that can be wrapped by aCircuit, replacing the oldWrappedFunctype. (hoglet.go)Dependency and Go Version Updates:
golang.org/x/syncto v0.18.0 ingo.mod. Also removed an unused indirect dependency. (go.mod)Testing Improvements:
options_test.gotohoglet_testfor improved test isolation and updated imports accordingly. (options_test.go)The change also brings some improvements to micro-benchmarks: