Skip to content

Commit 15997a9

Browse files
Shutdown timeout in config
1 parent a9a55b5 commit 15997a9

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

cmd/articles-server/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"os"
99
"os/signal"
1010
"syscall"
11-
"time"
1211

1312
"github.com/go-playground/validator/v10"
1413
"github.com/massivemadness/articles-server/internal/api"
@@ -77,12 +76,16 @@ func main() {
7776
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
7877
<-sigChan
7978

80-
shutdownCtx, shutdownRelease := context.WithTimeout(context.Background(), 10*time.Second)
79+
shutdownCtx, shutdownRelease := context.WithTimeout(context.Background(), cfg.HttpServer.ShutdownTimeout)
8180
defer shutdownRelease()
8281

8382
if err := httpServer.Shutdown(shutdownCtx); err != nil {
8483
zapLogger.Error("HTTP shutdown error", zap.Error(err))
8584
}
8685

86+
if err := httpPrivateServer.Shutdown(shutdownCtx); err != nil {
87+
zapLogger.Error("HTTP shutdown error private", zap.Error(err))
88+
}
89+
8790
zapLogger.Info("Server stopped")
8891
}

config/dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ http_server:
77
private_port: 8081
88
timeout: 4s
99
idle_timeout: 60s
10+
shutdown_timeout: 10s
1011

1112
database:
1213
host: "postgres"

config/local.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ http_server:
77
private_port: 8081
88
timeout: 4s
99
idle_timeout: 60s
10+
shutdown_timeout: 10s
1011

1112
database:
1213
host: "postgres" # service name from docker compose

config/prod.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ http_server:
77
private_port: 8081
88
timeout: 4s
99
idle_timeout: 60s
10+
shutdown_timeout: 10s
1011

1112
database:
1213
host: "postgres"

internal/config/config.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ type Application struct {
2525
}
2626

2727
type HTTPServer struct {
28-
Address string `yaml:"address" env-default:"localhost"`
29-
PublicPort int `yaml:"public_port" env-default:"8080"`
30-
PrivatePort int `yaml:"private_port" env-default:"8081"`
31-
Timeout time.Duration `yaml:"timeout" env-default:"4s"`
32-
IdleTimeout time.Duration `yaml:"idle_timeout" env-default:"60s"`
28+
Address string `yaml:"address" env-default:"localhost"`
29+
PublicPort int `yaml:"public_port" env-default:"8080"`
30+
PrivatePort int `yaml:"private_port" env-default:"8081"`
31+
Timeout time.Duration `yaml:"timeout" env-default:"4s"`
32+
IdleTimeout time.Duration `yaml:"idle_timeout" env-default:"60s"`
33+
ShutdownTimeout time.Duration `yaml:"shutdown_timeout" env-default:"10s"`
3334
}
3435

3536
type Database struct {

0 commit comments

Comments
 (0)