Skip to content

Modernize build pipeline, enhance proxy robustness, and upgrade Go#15

Merged
stn1slv merged 5 commits into
mainfrom
refactoring
Mar 19, 2026
Merged

Modernize build pipeline, enhance proxy robustness, and upgrade Go#15
stn1slv merged 5 commits into
mainfrom
refactoring

Conversation

@stn1slv
Copy link
Copy Markdown
Owner

@stn1slv stn1slv commented Mar 19, 2026

This pull request introduces several improvements and modernizations to the project's build, release, and code quality processes, as well as some code refactoring and test updates. The most significant changes include upgrading dependencies and build tooling, adding linting and formatting support, streamlining cross-platform builds and releases, and improving code safety and maintainability.

Build and Release Pipeline Modernization:

  • Upgraded GitHub Actions workflows to use the latest versions of actions/checkout and actions/setup-go, updated Go version to 1.26.1, and replaced deprecated dependency installation commands with go mod download. Added race detection to tests and linting via golangci-lint.
  • Simplified and unified the release workflow: replaced multiple platform-specific build and upload steps with a loop, and switched to softprops/action-gh-release for creating releases and uploading assets. Added required permissions.
  • Updated the Dockerfile to use Go 1.26, a multi-stage build with distroless/static for a minimal, non-root image, and improved build flags for smaller binaries.
  • Introduced a Makefile to standardize local development tasks for setup, testing (with race detection), linting, formatting, building, and running the app.

Code Quality and Linting Enhancements:

  • Added a .golangci.yml configuration to enable a comprehensive set of linters, including security, style, and correctness checks, and configured exclusions for test files.

Code Refactoring and Maintenance:

  • Updated Go module version to 1.26.1 in go.mod.
  • Refactored the highlight.go utility for more idiomatic Go, improved color wrapping, and made XML highlighting more robust and maintainable. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
  • Replaced the global int32 request counter with a more robust atomic.Int64 for thread safety, and added a maximum log body size constant to prevent excessive memory usage.
  • Improved resource cleanup in body decoding by ensuring all readers are closed safely.
  • Removed the redundant coloredTimeWithColor function and refactored related code and tests to use a single coloredTime function with a color parameter. [1] [2] [3] [4] [5] [6]

General Improvements:

  • Removed outdated comments and streamlined workflow files for clarity.

These changes collectively improve the reliability, maintainability, and security of the codebase and its CI/CD pipeline.

stn1slv added 2 commits March 19, 2026 15:49
Add golangci-lint configuration and a Makefile, and update the Dockerfile to use a proper builder stage and distroless runtime. Harden proxy code: introduce maxLogBodySize, validate target URL, use http.Server with timeouts, and avoid excessive memory copies by using bytes.NewReader. Improve highlight.go: introduce xmlnsPrefix, use wrapColor for punctuation, handle EOF with errors.Is, tighten XML attribute handling and whitespace checks, and add a 1xx status color branch. Also ensure response body readers are safely closed.
Upgrade Go toolchain and workflows, add linting and race detection, and refactor logging/proxy internals.

- CI: update actions (checkout v4, setup-go v5), set go version 1.26.1, add go mod download and golangci-lint, run tests with -race. Simplify release workflow: add permissions, use checkout@v4, setup-go@v5, download deps, run race tests, build all target platforms in a loop and create release via softprops/action-gh-release.
- Bump Dockerfile base image and go.mod to Go 1.26/1.26.1.
- Code: switch reqCounter to atomic.Int64 and use Add; refactor coloredTime to accept a color parameter and use wrapColor/fmt.Sprintf consistently; update logging to use wrapColor and fmt, and include NO_COLOR env var handling. Replace custom ReverseProxy director with the newer httputil.ReverseProxy Rewrite-based setup.
- Tests: adjust tests to the new coloredTime signature and simplify assertions.
- Minor fixes: small XML/token handling cleanup.

These changes modernize the build/release pipeline, enable race checks and linting, keep dependencies current, and simplify cross-platform release artifacts.
@stn1slv stn1slv requested a review from Copilot March 19, 2026 15:38

This comment was marked as resolved.

stn1slv added 2 commits March 19, 2026 16:43
Introduce main_test.go with helpers to compress gzip/deflate/brotli and a suite of tests covering decodeBody and DebugTransport.RoundTrip. Tests verify handling of compressed responses (gzip, deflate, brotli), proxying behavior, POST request bodies, unreachable upstream errors, large-body behavior, logging flag interactions, and environment/flag-based configuration helpers (getEnv, getListenAddress, getTarget). Also includes a test ensuring JSON response bodies are preserved exactly for proxying while allowing reformatting for logging.
Pin golangci-lint action to v2.11.3 in CI and add a Makefile hint to install gofumpt. Add a test asserting 1xx status uses the expected color. Clarify maxLogBodySize comment to state large bodies are still buffered but not highlighted to avoid expensive formatting. Improve target URL parsing and error messages by preserving the raw target, reporting parse errors with details, and validating that scheme and host are present.
@stn1slv stn1slv requested a review from Copilot March 19, 2026 15:47
Copy link
Copy Markdown

Copilot AI left a 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 modernizes the Go build/release pipeline (CI workflows, Docker image, Makefile, golangci-lint config) and refactors the proxy/logger implementation to be more robust (safer URL parsing, server timeouts, atomic request counter, log-body truncation), alongside updates to highlighting utilities and test coverage.

Changes:

  • Added a Makefile and a new .golangci.yml, and updated GitHub Actions workflows to run lint + race tests and streamline releases.
  • Updated the proxy runtime behavior (atomic counter, NO_COLOR support, target validation, server timeouts, response log truncation).
  • Refactored highlight utilities (colored time API, XML/JSON highlighting improvements) and added/updated tests.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Makefile Adds standard local dev targets (setup/test/lint/format/build/run).
main.go Improves proxy robustness (validation, timeouts) and logging behavior (atomic counter, truncation, NO_COLOR).
main_test.go Adds extensive tests for decoding, RoundTrip behavior, and helpers.
highlight.go Refactors time coloring and improves XML/JSON highlighting robustness.
highlight_test.go Updates tests for new coloredTime signature and status coloring.
go.mod Updates Go version directive.
Dockerfile Moves to multi-stage build and distroless runtime image.
.golangci.yml Introduces golangci-lint configuration.
.github/workflows/build.yml Updates CI to Go 1.26.1, adds linting, runs race tests.
.github/workflows/release.yml Streamlines release builds/uploads and adds race tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread main.go
Comment on lines 92 to 96
bodyBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}
// restore body for client
Update project documentation with tooling, testing, and runtime details: bump Go requirement to 1.26; describe http.Server timeouts in main.go and use of DebugTransport; document added test files (main_test.go, highlight_test.go) and HTTP testing with httptest; replace command list with Makefile targets (setup, build, test, lint, format, run); add NO_COLOR env var support and mention no-color.org convention; note concurrency uses atomic.Int64 and error handling uses log.Fatal/Fatalf; require gofumpt formatting and golangci-lint config; document response body truncation behavior for large bodies; clarify proxy implementation (ReverseProxy with Rewrite) and server timeouts; add Docker multi-stage/distroless details and CI (GitHub Actions) notes.
@stn1slv stn1slv merged commit 5c95caf into main Mar 19, 2026
2 checks passed
@stn1slv stn1slv deleted the refactoring branch March 19, 2026 16:28
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.

2 participants