Skip to content

Commit 8af41ba

Browse files
committed
fix controller and health checks
1 parent e1df41d commit 8af41ba

4 files changed

Lines changed: 25 additions & 8 deletions

File tree

api/health/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func NewController(
2020
}
2121

2222
func (c *controller) MountRoutes(group *gin.RouterGroup) {
23-
group.GET("/", c.getHealthHandler)
23+
group.GET("", c.getHealthHandler)
2424
}
2525

2626
func (c *controller) getHealthHandler(ctx *gin.Context) {

docker-compose.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ services:
3636
networks:
3737
- goserve-postgres-network
3838
healthcheck:
39-
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$DB_NAME"]
40-
interval: 3s
41-
timeout: 3s
42-
retries: 10
39+
test:
40+
[
41+
"CMD-SHELL",
42+
"pg_isready -h localhost -p 5432 -U \"$${POSTGRES_USER}\" -d \"$${POSTGRES_DB}\""
43+
]
44+
interval: 10s
45+
timeout: 5s
46+
retries: 5
47+
start_period: 20s
4348

4449
redis:
4550
image: redis:8.4.0
@@ -53,10 +58,17 @@ services:
5358
networks:
5459
- goserve-postgres-network
5560
healthcheck:
56-
test: ["CMD-SHELL", "redis-cli -a ${REDIS_PASSWORD} ping | grep PONG"]
57-
interval: 5s
61+
test:
62+
[
63+
"CMD",
64+
"redis-cli",
65+
"-a", "${REDIS_PASSWORD}",
66+
"ping"
67+
]
68+
interval: 10s
5869
timeout: 3s
5970
retries: 5
71+
start_period: 10s
6072

6173
migrate:
6274
image: migrate/migrate

startup/module.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ func (m *module) GetInstance() *module {
3636
return m
3737
}
3838

39+
// OpenControllers are controllers that do not require api key authentication
40+
func (m *module) OpenControllers() []network.Controller {
41+
return []network.Controller{health.NewController(m.HealthService)}
42+
}
43+
3944
func (m *module) Controllers() []network.Controller {
4045
return []network.Controller{
41-
health.NewController(m.HealthService),
4246
auth.NewController(m.AuthenticationProvider(), m.AuthorizationProvider(), m.AuthService),
4347
user.NewController(m.AuthenticationProvider(), m.AuthorizationProvider(), m.UserService),
4448
blog.NewController(m.AuthenticationProvider(), m.AuthorizationProvider(), m.BlogService),

startup/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func create(env *config.Env) (network.Router, Module, Shutdown) {
5050

5151
router := network.NewRouter(env.GoMode)
5252
router.RegisterValidationParsers(network.CustomTagNameFunc())
53+
router.LoadControllers(module.GetInstance().OpenControllers())
5354
router.LoadRootMiddlewares(module.RootMiddlewares())
5455
router.LoadControllers(module.Controllers())
5556

0 commit comments

Comments
 (0)