diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 110183d..2bd511d 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -23,7 +23,7 @@ jobs: - name: 'Setup Go' uses: actions/setup-go@v5 with: - go-version: 1.22 + go-version: 1.23 - name: 'Install dependencies' run: go mod download diff --git a/build/migrator/Dockerfile b/build/migrator/Dockerfile index d85230c..bbaf39f 100644 --- a/build/migrator/Dockerfile +++ b/build/migrator/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.22-alpine3.20 as build +FROM golang:1.23-alpine3.20 as build WORKDIR /build COPY . . diff --git a/build/service/Dockerfile b/build/service/Dockerfile index a962a02..be8e4c4 100644 --- a/build/service/Dockerfile +++ b/build/service/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.22-alpine3.20 as build +FROM golang:1.23-alpine3.20 as build WORKDIR /build COPY . . diff --git a/cmd/service/main.go b/cmd/service/main.go index c537e49..4c669a6 100644 --- a/cmd/service/main.go +++ b/cmd/service/main.go @@ -8,6 +8,7 @@ import ( "os/signal" "github.com/nijeti/healthcheck" + "github.com/nijeti/healthcheck/servers/fasthttp" "github.com/nijeti/cinema-keeper/internal/db" "github.com/nijeti/cinema-keeper/internal/discord" @@ -18,7 +19,6 @@ import ( "github.com/nijeti/cinema-keeper/internal/handlers/unlock" cfgPkg "github.com/nijeti/cinema-keeper/internal/pkg/config" "github.com/nijeti/cinema-keeper/internal/pkg/dbUtils" - "github.com/nijeti/cinema-keeper/internal/pkg/hcServer" ) type config struct { @@ -77,7 +77,9 @@ func main() { }, } discord.RegisterCommands(discordSession, commands, cfg.Discord.Guild) - defer discord.UnregisterCommands(discordSession, commands, cfg.Discord.Guild) + defer discord.UnregisterCommands( + discordSession, commands, cfg.Discord.Guild, + ) discordProbe := discord.NewProbe(discordSession) @@ -87,8 +89,14 @@ func main() { healthcheck.WithProbe("db", dbProbe), healthcheck.WithProbe("discord", discordProbe), ) - hcs := hcServer.Serve(":8080", hc) - defer hcs.Shutdown() + hcs := fasthttp.New( + hc, + fasthttp.WithLogger(hcLogger), + fasthttp.WithAddress(":8080"), + fasthttp.WithRoute("/health"), + ) + hcs.Start() + defer hcs.Stop() // run log.Println("startup complete") diff --git a/go.mod b/go.mod index 1751b30..5ae7c1d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/nijeti/cinema-keeper -go 1.22.1 +go 1.23 require ( github.com/bwmarrin/discordgo v0.28.1 @@ -10,8 +10,9 @@ require ( github.com/knadh/koanf/providers/file v1.0.0 github.com/knadh/koanf/v2 v2.1.1 github.com/lib/pq v1.10.9 + github.com/nijeti/healthcheck v1.0.0-beta.2 + github.com/nijeti/healthcheck/servers/fasthttp v1.0.0-beta.2 github.com/stretchr/testify v1.9.0 - github.com/valyala/fasthttp v1.55.0 ) require ( @@ -29,11 +30,11 @@ require ( github.com/kr/pretty v0.3.1 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect - github.com/nijeti/healthcheck v1.0.0-beta.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasthttp v1.55.0 // indirect golang.org/x/arch v0.8.0 // indirect golang.org/x/crypto v0.25.0 // indirect golang.org/x/sys v0.22.0 // indirect diff --git a/go.sum b/go.sum index 2449bef..854fea7 100644 --- a/go.sum +++ b/go.sum @@ -48,8 +48,10 @@ github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa1 github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/nijeti/healthcheck v1.0.0-beta.1 h1:qUaW2UTRBQVzkxl7zcq4+T1Qlrx0+Z7tQGM32IKMJLg= -github.com/nijeti/healthcheck v1.0.0-beta.1/go.mod h1:7FrjSzn+K+GgOcqrgpUCaj01Elnn2F5+Ri3IixIizaA= +github.com/nijeti/healthcheck v1.0.0-beta.2 h1:99dRxvH5rSj7mseQgb4e9nt/PGuAwVeMJW40RTmFWTc= +github.com/nijeti/healthcheck v1.0.0-beta.2/go.mod h1:YOvJznQqQ7qUbHOJhjS/gNMxEWyBkgsNeYWxLViOi70= +github.com/nijeti/healthcheck/servers/fasthttp v1.0.0-beta.2 h1:CObHhO7XSorPZVYXUDbDOtaZLDWUg4o+PaM9OYXOWlo= +github.com/nijeti/healthcheck/servers/fasthttp v1.0.0-beta.2/go.mod h1:sqZTsoePDrrqFWVOQYPPSNeLuG0WWlhumZzSkWDCrnw= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= diff --git a/internal/pkg/hcServer/server.go b/internal/pkg/hcServer/server.go deleted file mode 100644 index ea4324b..0000000 --- a/internal/pkg/hcServer/server.go +++ /dev/null @@ -1,38 +0,0 @@ -package hcServer - -import ( - "log" - - "github.com/nijeti/healthcheck" - "github.com/valyala/fasthttp" -) - -func Serve(address string, hc *healthcheck.Healthcheck) *fasthttp.Server { - s := &fasthttp.Server{ - GetOnly: true, - Handler: func(ctx *fasthttp.RequestCtx) { - if string(ctx.Path()) != "/health" { - ctx.NotFound() - return - } - - status := hc.Handle(ctx) - - if status == healthcheck.StatusHealthy { - ctx.SetStatusCode(fasthttp.StatusOK) - } else { - ctx.SetStatusCode(fasthttp.StatusServiceUnavailable) - } - ctx.SetBodyString(status.String()) - }, - } - - go func() { - err := s.ListenAndServe(address) - if err != nil { - log.Fatalln("healthcheck server error", "error", err) - } - }() - - return s -}