diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eacc966..73a0e7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,35 @@ jobs: with: go-version: "1.23.0" + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest + - name: Tests - run: go test ./... -cover \ No newline at end of file + run: go test ./... -cover + + - name: Security Checks + run: gosec ./... + + style: + name: Style + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.23.0" + + - name: Install staticcheck + uses: dominikh/staticcheck-action@v1 + with: + version: "latest" + + - name: Style + run: test -z $(go fmt ./...) + + - name: Linting + run: test -z $(go fmt ./...) \ No newline at end of file diff --git a/json.go b/json.go index 1e6e798..7ee5351 100644 --- a/json.go +++ b/json.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "log" "net/http" ) @@ -30,5 +31,9 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) { return } w.WriteHeader(code) - w.Write(dat) + _, err = w.Write(dat) + if err != nil { + fmt.Printf("Error wiring response: %s", err.Error()) + return + } } diff --git a/main.go b/main.go index 19d7366..7f48a6c 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "os" + "time" "github.com/go-chi/chi" "github.com/go-chi/cors" @@ -89,8 +90,9 @@ func main() { router.Mount("/v1", v1Router) srv := &http.Server{ - Addr: ":" + port, - Handler: router, + Addr: ":" + port, + Handler: router, + ReadHeaderTimeout: time.Second * 30, } log.Printf("Serving on port: %s\n", port)