Skip to content

Commit

Permalink
Added healthcheck endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
gapidobri committed Aug 14, 2024
1 parent 24c0179 commit 5f30b84
Show file tree
Hide file tree
Showing 22 changed files with 2,328 additions and 42 deletions.
4 changes: 4 additions & 0 deletions api/admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ definitions:
type: object
Game:
properties:
google_sheet_id:
type: string
google_sheet_tab_name:
type: string
id:
type: string
name:
Expand Down
4 changes: 4 additions & 0 deletions api/public.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ definitions:
type: object
Game:
properties:
google_sheet_id:
type: string
google_sheet_tab_name:
type: string
id:
type: string
name:
Expand Down
13 changes: 9 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ go 1.22
require (
cloud.google.com/go/maps v1.11.7
github.com/Masterminds/squirrel v1.5.4
github.com/elliotxx/healthcheck v0.2.1
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/validator/v10 v10.22.0
github.com/google/uuid v1.6.0
github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9
github.com/mattbaird/gochimp v0.0.0-20200820164431-f1082bcdf63f
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.46.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
google.golang.org/api v0.191.0
google.golang.org/genproto v0.0.0-20240730163845-b1a4ccb954bf
)
Expand All @@ -24,16 +30,15 @@ require (
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.10.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/s2a-go v0.1.8 // indirect
Expand All @@ -47,19 +52,19 @@ require (
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattbaird/gochimp v0.0.0-20200820164431-f1082bcdf63f // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
Expand Down
14 changes: 9 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.115.0 h1:CnFSK6Xo3lDYRoBKEcAtia6VSC837/ZkJuRduSFnr14=
cloud.google.com/go v0.115.0/go.mod h1:8jIM5vVgoAEoiVxQ/O4BFTfHqulPZgs/ufEzMcFMdWU=
cloud.google.com/go/auth v0.8.0 h1:y8jUJLl/Fg+qNBWxP/Hox2ezJvjkrPb952PC1p0G6A4=
cloud.google.com/go/auth v0.8.0/go.mod h1:qGVp/Y3kDRSDZ5gFD/XPUfYQ9xW1iI7q8RIRoCyBbJc=
cloud.google.com/go/auth/oauth2adapt v0.2.3 h1:MlxF+Pd3OmSudg/b1yZ5lJwoXCEaeedAguodky1PcKI=
Expand Down Expand Up @@ -31,6 +29,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elliotxx/healthcheck v0.2.1 h1:LwhK8Y0C5AGdrywIAG5+ivcNoUI5H4ry4j2ejzGBQaA=
github.com/elliotxx/healthcheck v0.2.1/go.mod h1:y6VW57YGHpqascrlQQBmLciXt66Cfx+l2bnv5fddbtg=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand All @@ -52,6 +52,8 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
Expand All @@ -76,14 +78,16 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM=
github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA=
Expand Down Expand Up @@ -167,6 +171,7 @@ github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down Expand Up @@ -290,4 +295,3 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
6 changes: 3 additions & 3 deletions internal/api/admin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/gapidobri/prizer/internal/api"
"github.com/gapidobri/prizer/internal/service"
"github.com/gin-gonic/gin"
"github.com/jmoiron/sqlx"
log "github.com/sirupsen/logrus"
)

Expand All @@ -17,14 +18,15 @@ type Server struct {
}

func NewServer(
db *sqlx.DB,
gameService *service.GameService,
userService *service.UserService,
prizeService *service.PrizeService,
wonPrizeService *service.WonPrizeService,
participationMethodService *service.ParticipationMethodService,
) *Server {
return &Server{
engine: gin.Default(),
engine: api.NewServer(db),
gameService: gameService,
userService: userService,
prizeService: prizeService,
Expand All @@ -34,8 +36,6 @@ func NewServer(
}

func (s *Server) Run(address string) {
s.engine.Use(api.ErrorHandler)

s.gameRoutes()
s.userRoutes()
s.prizeRoutes()
Expand Down
7 changes: 3 additions & 4 deletions internal/api/public/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/gapidobri/prizer/internal/api"
"github.com/gapidobri/prizer/internal/service"
"github.com/gin-gonic/gin"
"github.com/jmoiron/sqlx"
log "github.com/sirupsen/logrus"
)

Expand All @@ -12,16 +13,14 @@ type Server struct {
gameService *service.GameService
}

func NewServer(gameService *service.GameService) *Server {
func NewServer(db *sqlx.DB, gameService *service.GameService) *Server {
return &Server{
engine: gin.Default(),
engine: api.NewServer(db),
gameService: gameService,
}
}

func (s *Server) Run(address string) {
s.engine.Use(api.ErrorHandler)

s.participationMethodRoutes()

log.Infof("Public API listening on %s", address)
Expand Down
22 changes: 22 additions & 0 deletions internal/api/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package api

import (
"github.com/elliotxx/healthcheck"
"github.com/elliotxx/healthcheck/checks"
"github.com/gin-gonic/gin"
"github.com/jmoiron/sqlx"
)

func NewServer(db *sqlx.DB) *gin.Engine {
engine := gin.Default()

_ = healthcheck.Register(&engine.RouterGroup)

engine.GET("/readyz", healthcheck.NewHandler(
healthcheck.NewDefaultHandlerConfigFor(checks.NewSQLCheck(db.DB))),
)

engine.Use(ErrorHandler)

return engine
}
7 changes: 4 additions & 3 deletions internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"github.com/gapidobri/prizer/internal/api/public"
"github.com/gapidobri/prizer/internal/database"
"github.com/gapidobri/prizer/internal/pkg/clients/addressvalidation"
"github.com/gapidobri/prizer/internal/pkg/clients/mandrill"
"github.com/gapidobri/prizer/internal/pkg/clients/sheets"
"github.com/gapidobri/prizer/internal/pkg/models/config"
"github.com/gapidobri/prizer/internal/service"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"github.com/mattbaird/gochimp"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"os"
Expand All @@ -38,7 +38,7 @@ func Run() {
log.WithError(err).Fatal("Failed to create address validation client")
}

mandrillClient, err := gochimp.NewMandrill(cfg.Mandrill.ApiKey)
mandrillClient, err := mandrill.NewClient(cfg.Mandrill.ApiKey)
if err != nil {
log.WithError(err).Fatal("Failed to create mandrill client")
}
Expand Down Expand Up @@ -78,8 +78,9 @@ func Run() {
participationMethodService := service.NewParticipationMethodService(participationMethodRepository)

// APIs
publicApi := public.NewServer(gameService)
publicApi := public.NewServer(db, gameService)
adminApi := admin.NewServer(
db,
gameService,
userService,
prizeService,
Expand Down
Loading

0 comments on commit 5f30b84

Please sign in to comment.