Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI

on:
pull_request:
branches: [main]

permissions:
contents: read

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.64.8
install-mode: goinstall

- name: Build check
run: go build ./...
5 changes: 1 addition & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]

permissions:
contents: read
Expand Down Expand Up @@ -37,7 +35,6 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
Expand All @@ -47,7 +44,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
Expand Down
4 changes: 3 additions & 1 deletion cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func (app *API) healthCheck(w http.ResponseWriter, r *http.Request) {
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
if _, err := w.Write([]byte("ok")); err != nil {
slog.Error("Failed to write health check response", "error", err)
}
}

type config struct {
Expand Down
6 changes: 4 additions & 2 deletions internal/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
func Write(w http.ResponseWriter, status int, data any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(data)

if err := json.NewEncoder(w).Encode(data); err != nil {
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
}
Comment on lines 10 to +14

Copilot AI Feb 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WriteHeader(status) is called before encoding the JSON. If Encode fails, the response status/headers are already committed and http.Error cannot reliably change the status to 500; it can also produce a partially-written/invalid JSON response. Consider encoding to a buffer first (then write status/body only on success), or change Write to return an error so callers can decide how to respond before headers are written.

Copilot uses AI. Check for mistakes.

}

Expand All @@ -21,4 +24,3 @@ func Read(r *http.Request, dst any) error {

return nil
}