diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2568d13 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 ./... diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6eb8ced..1118621 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -4,8 +4,6 @@ on: push: branches: [main] tags: ["v*"] - pull_request: - branches: [main] permissions: contents: read @@ -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 }} @@ -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 diff --git a/cmd/api.go b/cmd/api.go index c207d34..ed3cc69 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -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 { diff --git a/internal/json/json.go b/internal/json/json.go index 563c34e..fd0d4ee 100644 --- a/internal/json/json.go +++ b/internal/json/json.go @@ -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) + } } @@ -21,4 +24,3 @@ func Read(r *http.Request, dst any) error { return nil } -