From ca26f59f1d8eacc93ba9dccc9e31a60eb588b807 Mon Sep 17 00:00:00 2001 From: Michael Madden Date: Sat, 14 Nov 2026 08:04:50 -0600 Subject: [PATCH 1/3] Fix golangci-lint v2 config and harden HTTP handling - Migrate .golangci.yml to valid v2 schema; the old file failed config verify, so linter selection was being ignored. - Use an HTTP client with a 10s timeout, close the response body, and reject non-200 responses. - Decode JSON directly from the body. - Print errors to stderr and exit 1 instead of panicking. - Add package comment. - Add TODO.md with remaining review items. Co-Authored-By: Claude Opus 5.5 --- .golangci.yml | 44 ++++++++++++++++++++--------------------- TODO.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ github_status.go | 18 +++++++++++------ 3 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 TODO.md diff --git a/.golangci.yml b/.golangci.yml index 8695057..8c02cb6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,31 +1,29 @@ -version: 2 +version: "2" linters: - disable-all: true + default: none enable: - # --- The Critical Checks (Gap Fixers) --- - - errcheck # Catches your file.Close errors - - gosec # Catches your G304 security issue - - revive # Catches your missing comment issues - - govet # Standard Go vetting + - errcheck + - gosec + - revive + - govet + settings: + revive: + rules: + - name: exported + arguments: + - disableStutteringCheck + exclusions: + paths: + - third_party + - builtin + - examples formatters: enable: - gofmt - goimports - -linters-settings: - revive: - rules: - - name: exported - arguments: - - disableStutteringCheck - - goimports: - local-prefixes: github.com/mikemadden42 - -issues: - exclude-dirs: - - third_party - - builtin - - examples + settings: + goimports: + local-prefixes: + - github.com/mikemadden42 diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..80e181d --- /dev/null +++ b/TODO.md @@ -0,0 +1,51 @@ +# TODO + +## Bugs / correctness + +- [x] Fix `.golangci.yml`. It fails `golangci-lint config verify` (v2), so the + linter selection is ignored (staticcheck runs despite "disable-all"): + - [x] `version: 2` should be `version: "2"` + - [x] `linters.disable-all` should be `linters.default: none` + - [x] `linters-settings` should be `linters.settings` + - [x] goimports settings go under `formatters.settings.goimports.local-prefixes` (list) + - [x] `issues.exclude-dirs` should be `linters.exclusions.paths` +- [ ] Fix `.goreleaser.yaml`. It fails `goreleaser check`: + - [ ] Add `version: 2` + - [ ] `snapshot.name_template` should be `snapshot.version_template` + - [ ] Remove the no-op `go generate ./...` hook +- [x] HTTP handling in `github_status.go`: + - [x] Use an `http.Client` with a timeout instead of `http.Get` + - [x] Close `response.Body` + - [x] Check `response.StatusCode` before decoding +- [x] Replace `panic` with an error message on stderr and `os.Exit(1)` (or `log.Fatal`) + +## Code quality + +- [ ] Trim the `summary` struct to the fields actually used; `interface{}` should be `any` +- [ ] Print the overall status (`Status.Description`) +- [ ] Replace the if/else chain with a `switch` (staticcheck QF1003) covering + `operational`, `degraded_performance`, `partial_outage`, `major_outage`, + `under_maintenance` +- [ ] Filter the "Visit www.githubstatus.com for more information" filler row +- [x] Use `json.NewDecoder(resp.Body).Decode` instead of `io.ReadAll` + `Unmarshal` +- [ ] Use the readable URL `https://www.githubstatus.com/api/v2/summary.json` +- [x] Add a package comment (revive) +- [ ] Exit non-zero when any component isn't operational + +## Tests / CI + +- [ ] Split into `fetch(url)` and `render(w io.Writer, summary)`; test `render` + with a JSON fixture and `fetch` with `httptest.NewServer` +- [ ] Add a lint job (`golangci/golangci-lint-action`) to CI +- [ ] Align Go versions: `go.mod` says 1.18, CI tests 1.23–1.25. Pick a floor + and test through current +- [ ] Bump `actions/setup-go` / `actions/checkout` +- [ ] Update dependencies (`go get -u ./... && go mod tidy`); `x/sys` v0.25.0 → v0.50.0, + `fatih/color` v1.18.0 → v1.19.0 + +## Housekeeping + +- [ ] Delete the Jenkinsfile unless Jenkins is in use (build-only, no tests, echo-only post blocks) +- [ ] `make release` uses `--snapshot`, so it never publishes. Rename the target or drop the flag +- [ ] Add `dist/` and `github_status` to `.gitignore` +- [ ] Expand the README with usage, install and example output diff --git a/github_status.go b/github_status.go index bf57f95..e941b76 100644 --- a/github_status.go +++ b/github_status.go @@ -1,3 +1,4 @@ +// Command github_status prints the status of each GitHub component. package main // https://tutorialedge.net/golang/consuming-restful-api-with-go/ @@ -6,8 +7,9 @@ package main import ( "encoding/json" "fmt" - "io" "net/http" + "os" + "time" "github.com/fatih/color" ) @@ -43,14 +45,17 @@ type summary struct { } func main() { - response, err := http.Get("https://kctbh9vrtdwd.statuspage.io/api/v2/summary.json") + client := &http.Client{Timeout: 10 * time.Second} + response, err := client.Get("https://kctbh9vrtdwd.statuspage.io/api/v2/summary.json") checkErr(err) + defer func() { _ = response.Body.Close() }() - responseData, err := io.ReadAll(response.Body) - checkErr(err) + if response.StatusCode != http.StatusOK { + checkErr(fmt.Errorf("unexpected HTTP status: %s", response.Status)) + } var responseObject summary - err = json.Unmarshal(responseData, &responseObject) + err = json.NewDecoder(response.Body).Decode(&responseObject) checkErr(err) for _, component := range responseObject.Components { @@ -70,6 +75,7 @@ func main() { func checkErr(err error) { if err != nil { - panic(err) + fmt.Fprintln(os.Stderr, "error:", err) + os.Exit(1) } } From 5011c9f1e35483d20e382fd56052a1334069cf78 Mon Sep 17 00:00:00 2001 From: Michael Madden Date: Sat, 14 Nov 2026 08:05:28 -0600 Subject: [PATCH 2/3] CI: test against Go oldstable and stable Use actions/setup-go version aliases instead of pinned minor versions so the matrix tracks the two supported Go releases automatically. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/go.yml | 2 +- TODO.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index df66a09..42fd8d6 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -10,7 +10,7 @@ jobs: build: strategy: matrix: - go-version: [1.23.x, 1.24.x, 1.25.x] + go-version: [oldstable, stable] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: diff --git a/TODO.md b/TODO.md index 80e181d..9a7574e 100644 --- a/TODO.md +++ b/TODO.md @@ -37,8 +37,8 @@ - [ ] Split into `fetch(url)` and `render(w io.Writer, summary)`; test `render` with a JSON fixture and `fetch` with `httptest.NewServer` - [ ] Add a lint job (`golangci/golangci-lint-action`) to CI -- [ ] Align Go versions: `go.mod` says 1.18, CI tests 1.23–1.25. Pick a floor - and test through current +- [x] CI targets Go `oldstable` and `stable` (via `actions/setup-go` aliases) +- [ ] `go.mod` still says `go 1.18`, which CI no longer tests; consider raising it - [ ] Bump `actions/setup-go` / `actions/checkout` - [ ] Update dependencies (`go get -u ./... && go mod tidy`); `x/sys` v0.25.0 → v0.50.0, `fatih/color` v1.18.0 → v1.19.0 From 63ffaca48372de62b865f014de903d387a549793 Mon Sep 17 00:00:00 2001 From: Michael Madden Date: Sat, 14 Nov 2026 08:05:54 -0600 Subject: [PATCH 3/3] Raise go directive to 1.26 Match the oldest Go version CI tests (oldstable). Co-Authored-By: Claude Opus 5.5 --- TODO.md | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index 9a7574e..84b01e5 100644 --- a/TODO.md +++ b/TODO.md @@ -38,7 +38,7 @@ with a JSON fixture and `fetch` with `httptest.NewServer` - [ ] Add a lint job (`golangci/golangci-lint-action`) to CI - [x] CI targets Go `oldstable` and `stable` (via `actions/setup-go` aliases) -- [ ] `go.mod` still says `go 1.18`, which CI no longer tests; consider raising it +- [x] Raise `go.mod` to `go 1.26` to match the oldest Go version CI tests - [ ] Bump `actions/setup-go` / `actions/checkout` - [ ] Update dependencies (`go get -u ./... && go mod tidy`); `x/sys` v0.25.0 → v0.50.0, `fatih/color` v1.18.0 → v1.19.0 diff --git a/go.mod b/go.mod index ec040de..ba00820 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/mikemadden42/github_status -go 1.18 +go 1.26 require github.com/fatih/color v1.18.0