Modernize build pipeline, enhance proxy robustness, and upgrade Go#15
Merged
Conversation
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.
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.
There was a problem hiding this comment.
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 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
actions/checkoutandactions/setup-go, updated Go version to 1.26.1, and replaced deprecated dependency installation commands withgo mod download. Added race detection to tests and linting viagolangci-lint.softprops/action-gh-releasefor creating releases and uploading assets. Added required permissions.Dockerfileto use Go 1.26, a multi-stage build withdistroless/staticfor a minimal, non-root image, and improved build flags for smaller binaries.Makefileto standardize local development tasks for setup, testing (with race detection), linting, formatting, building, and running the app.Code Quality and Linting Enhancements:
.golangci.ymlconfiguration to enable a comprehensive set of linters, including security, style, and correctness checks, and configured exclusions for test files.Code Refactoring and Maintenance:
go.mod.highlight.goutility 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]int32request counter with a more robustatomic.Int64for thread safety, and added a maximum log body size constant to prevent excessive memory usage.coloredTimeWithColorfunction and refactored related code and tests to use a singlecoloredTimefunction with a color parameter. [1] [2] [3] [4] [5] [6]General Improvements:
These changes collectively improve the reliability, maintainability, and security of the codebase and its CI/CD pipeline.