From 235622cc1500df737f34870b463fa2e7feeb33f2 Mon Sep 17 00:00:00 2001 From: ddrmin Date: Thu, 19 Feb 2026 14:47:51 +0530 Subject: [PATCH 1/3] feat: Add GitHub Actions workflows for CI (linting and build) and Docker image building/pushing. --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ .github/workflows/docker.yml | 5 +---- 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9eece8c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +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: latest + + - 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 From b3eba216e5eaac2f441237bcde1b48ee042d8245 Mon Sep 17 00:00:00 2001 From: ddrmin Date: Thu, 19 Feb 2026 14:51:34 +0530 Subject: [PATCH 2/3] ci: Add GitHub Actions workflow for Go linting and build checks. --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9eece8c..2568d13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,8 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: latest + version: v1.64.8 + install-mode: goinstall - name: Build check run: go build ./... From 15ddc414c53a18825ec435256a1221bbf15d3a19 Mon Sep 17 00:00:00 2001 From: ddrmin Date: Thu, 19 Feb 2026 14:54:18 +0530 Subject: [PATCH 3/3] feat: Implement core API server with product and order endpoints and common JSON utilities. --- cmd/api.go | 4 +++- internal/json/json.go | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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 } -