diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a571394 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + + - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 + with: + go-version-file: go.mod + cache: true + + - name: go vet + run: go vet ./... + + - name: go test + run: go test ./... + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + + - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 + with: + go-version-file: go.mod + cache: true + + - name: golangci-lint + uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 + with: + version: v2.11.3 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..7679fd5 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,19 @@ +version: "2" + +linters: + default: none + enable: + - errcheck + - govet + - staticcheck + settings: + errcheck: + # Report errors from type assertions (e.g. v, ok := x.(T) when ok is ignored) + check-type-assertions: true + # Report when errors are assigned to the blank identifier + check-blank: true + +issues: + # Don't limit the number of issues per linter + max-issues-per-linter: 0 + max-same-issues: 0 diff --git a/Dockerfile b/Dockerfile index 8ef38ac..47d85fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,8 +25,8 @@ RUN chown -R appuser:appuser /app USER appuser -EXPOSE 8080 +EXPOSE 3000 -HEALTHCHECK --interval=10s --timeout=3s CMD wget -qO- http://localhost:8080/healthz || exit 1 +HEALTHCHECK --interval=10s --timeout=3s CMD wget -qO- http://127.0.0.1:3000/healthz || exit 1 CMD ["/bin/ingest"] diff --git a/internal/server/middleware.go b/internal/server/middleware.go index 5205554..ec41854 100644 --- a/internal/server/middleware.go +++ b/internal/server/middleware.go @@ -26,7 +26,10 @@ func RequestID() fiber.Handler { // RequestLogger logs each incoming request with structured fields. func RequestLogger(logger *slog.Logger) fiber.Handler { return func(c fiber.Ctx) error { - requestID, _ := c.Locals("request_id").(string) + var requestID string + if id, ok := c.Locals("request_id").(string); ok { + requestID = id + } logger.Info("request started", "request_id", requestID, @@ -70,8 +73,6 @@ func GzipDecompress() fiber.Handler { "error": "invalid gzip body", }) } - defer reader.Close() - decompressed, err := io.ReadAll(reader) if err != nil { return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ @@ -79,6 +80,12 @@ func GzipDecompress() fiber.Handler { }) } + if err := reader.Close(); err != nil { + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ + "error": "invalid gzip body", + }) + } + // Replace the request body with decompressed content c.Request().SetBody(decompressed) c.Request().Header.Del("Content-Encoding") diff --git a/mise.toml b/mise.toml index 9d07a62..3e50aec 100644 --- a/mise.toml +++ b/mise.toml @@ -1,6 +1,7 @@ [tools] go = "1.26" air = "latest" +golangci-lint = "2.11.3" [env] CGO_ENABLED = "0"