Skip to content

refactor: reorganize code structure and improve request handling - #12

Merged
kazeburo merged 2 commits into
masterfrom
feat/refactor-pkg
Sep 4, 2026
Merged

kazeburo merged 2 commits into
masterfrom
feat/refactor-pkg

Conversation

@kazeburo

@kazeburo kazeburo commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

PR Type

Enhancement, Tests


Description

  • Adopt flagrun command execution framework.

  • Extract HTTP request handling into request.go.

  • Add client-wide timeout and statistical calculations.

  • Add comprehensive request and metrics tests.


Diagram Walkthrough

flowchart LR
  Opt["CLI options"] 
  Flagrun["flagrun command runner"]
  Client["Configured HTTP client"]
  Request["Request timing helper"]
  Metrics["RTT metrics output"]
  Opt -- "runs through" --> Flagrun
  Opt -- "creates" --> Client
  Client -- "executes" --> Request
  Request -- "produces timings for" --> Metrics
Loading

File Walkthrough

Relevant files
Enhancement
main.go
Refactor command execution and RTT metric collection         

main.go

  • Replace manual CLI parsing with flagrun.
  • Convert options into the exported Opt command type.
  • Build configured HTTP clients with whole-request timeouts.
  • Calculate RTT metrics through stats and write to a supplied writer.
+59/-93 
request.go
Extract and harden HTTP request timing                                     

request.go

  • Extract request creation into an Opt method.
  • Move first-byte response timing into doRequest.
  • Safely drain and close response bodies.
  • Handle EOF reads using errors.Is.
+32/-0   
Tests
main_test.go
Add comprehensive HTTP statistics command tests                   

main_test.go

  • Add end-to-end tests for metric collection scenarios.
  • Cover invalid URLs, failures, redirects, intervals, and keepalive
    settings.
  • Validate output format and calculated statistics.
  • Add getStats benchmark coverage.
+303/-0 
request_test.go
Test HTTP request creation and timing                                       

request_test.go

  • Test request creation for valid and invalid URLs.
  • Cover response statuses, client errors, timeouts, and body handling.
  • Verify large responses and trailing-slash requests.
  • Add a request timing benchmark.
+150/-0 
testutil_test.go
Add reusable HTTP metrics test utilities                                 

testutil_test.go

  • Add reusable HTTP server and client test helpers.
  • Provide metric parsing and assertion utilities.
  • Support both tests and benchmarks through testingT.
+105/-0 
Dependencies
go.mod
Add command statistics and test dependencies                         

go.mod

  • Add flagrun for command parsing and execution.
  • Add stats for RTT aggregate calculations.
  • Add testify and its indirect test dependencies.
  • Update indirect golang.org/x/sys dependency.
+13/-2   

@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit af66d2c)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit af66d2c

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@kazeburo
kazeburo merged commit 8e7fe70 into master Sep 4, 2026
3 checks passed
@kazeburo
kazeburo deleted the feat/refactor-pkg branch September 4, 2026 14:09
@github-actions github-actions Bot mentioned this pull request Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant