feat: major api improvements#58
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #58 +/- ##
==========================================
+ Coverage 73.88% 74.40% +0.52%
==========================================
Files 28 25 -3
Lines 873 801 -72
==========================================
- Hits 645 596 -49
+ Misses 203 181 -22
+ Partials 25 24 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
ec6c930 to
5ab6aca
Compare
aad4e60 to
5a8f0fb
Compare
moreirathomas
left a comment
There was a problem hiding this comment.
Very nice, it brings much needed simplicity 👍
Dropping the Config struct make the whole thing much lighter.
Single concern I have: now that we configure the Runner via its public fields, nothing prevents the user from mutating its values after initialization. I agree that's a stupid thing to do from them, yet doable and I think we can manage an api that prevents this. That's on the todo list I think, you're refactor already brings value that largely outweights this single drawback (for now?).
As it's been quite a long time, I suggest we simply merge, what do you think?
My intuition is that it would be difficult to achieve without losing simplicity (and Go users are used to it, e.g. with |
- ParseRepresentation -> UnmarshalRepresentation: change signature so it matches json.Unmarshal style - implement Representation.Unmarshal: alias to UnmarshalRepresentation - update JSON accordingly
- remove Config.Override, Config.WithFields, Config.Equal - remove related tests - update tests relying on removed Config methods
Unmarshal -> ParseInto
- run go mod tidy
- module github.com/benchttp/engine -> github.com/benchttp/sdk - package runner -> benchttp
Irrelevant method, use Runner.OnProgress instead.
- simplify with less declarations - move into fie runner.go - more accurate docs
Allows convenient chaining, e.g. when using de default runner:
DefaultRunner().WithNewRequest("", "http://a.b", nil).Run(ctx)
- Runner.WithRequest
- Runner.WithNewRequest
ced71cd to
3492ed9
Compare
Description
Introduction of major changes to the SDK for a more intuitive and convenient usage.
Usage
Minimal configuration: before
Minimal configuration: after
Advanced configuration: before
Advanced configuration: after
Changes
Global changes
github.com/benchttp/engine➡️github.com/benchttp/sdk. It implies to change this repository name tosdkafter this PR is merged.runner➡️benchttp: more intuitive naming, such asrunner := benchttp.Runner{}orreport := benchttp.Report{}orerrors.Is(err, benchttp.ErrCanceled)runnerToConfig(v interface{}) ConfigtoToConfig(dst *Config), which significantly reduces complexity.ConfigFieldstypes and values: they're became unnecessary after removal of Config overriding logicsConfig.Requesttype to*http.Request: the runner needs an actual request, not an intermediary representation to be compiled as a request.config,reportConfig, useRunnerfields insteadRunner.onRecordingProgresstoRunner.OnProgress(public field)New: no internal setup needed, public fields are enough.configparsejson.Unmarshal(b []byte, dst interface{})) . This has two advantages:dst: no need to remember assigned fields then use Config overriding logicsNotes