refactor: split handlers.go and centralize config

Signed-off-by: skidoodle <contact@albert.lol>
This commit is contained in:
2026-01-18 19:25:35 +01:00
parent aca7267301
commit 00e5c95fe3
7 changed files with 447 additions and 458 deletions
+5 -12
View File
@@ -10,17 +10,10 @@ import (
"os/signal"
"path/filepath"
"syscall"
"time"
"github.com/skidoodle/safebin/internal/app"
)
const (
permUserRWX = 0o700
serverTimeout = 10 * time.Minute
shutdownTimeout = 10 * time.Second
)
func main() {
cfg := app.LoadConfig()
logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
@@ -34,7 +27,7 @@ func main() {
)
tmpDir := filepath.Join(cfg.StorageDir, "tmp")
if err := os.MkdirAll(tmpDir, permUserRWX); err != nil {
if err := os.MkdirAll(tmpDir, app.PermUserRWX); err != nil {
logger.Error("Failed to initialize storage directory", "err", err)
os.Exit(1)
}
@@ -53,9 +46,9 @@ func main() {
srv := &http.Server{
Addr: cfg.Addr,
Handler: application.Routes(),
ReadTimeout: serverTimeout,
WriteTimeout: serverTimeout,
IdleTimeout: serverTimeout,
ReadTimeout: app.ServerTimeout,
WriteTimeout: app.ServerTimeout,
IdleTimeout: app.ServerTimeout,
}
go func() {
@@ -70,7 +63,7 @@ func main() {
<-ctx.Done()
application.Logger.Info("Shutting down gracefully...")
shutdownCtx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
shutdownCtx, cancel := context.WithTimeout(context.Background(), app.ShutdownTimeout)
defer cancel()
if err := srv.Shutdown(shutdownCtx); err != nil {