-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
77 lines (61 loc) · 1.7 KB
/
main.go
File metadata and controls
77 lines (61 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"context"
"fmt"
"log"
"log/slog"
"os"
"os/signal"
"syscall"
"github.com/generate/selfserve/config"
"github.com/generate/selfserve/docs"
"github.com/generate/selfserve/internal/service"
"github.com/sethvargo/go-envconfig"
)
// @title SelfServe API
// @version 1.0
// @description SelfServe backend API documentation
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.email support@selfserve.com
// @license.name MIT
// @license.url https://opensource.org/licenses/MIT
// @host localhost:8080
// @BasePath /api/v1
// @schemes http https
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @description Your Clerk JWT token (prefixed with "Bearer ")
func main() {
// Load environment variables
ctx := context.Background()
var cfg config.Config
if err := envconfig.Process(ctx, &cfg); err != nil {
log.Fatal("failed to process config:", err)
}
docs.SwaggerInfo.Host = cfg.Application.Host
app, err := service.InitApp(&cfg)
if err != nil {
log.Fatal("failed to initialize app:", err)
}
defer func() {
if err := app.Close(); err != nil {
panic(fmt.Sprintf("failed to close app resources: %v", err))
}
}()
go func() {
if err := app.Server.Listen(":" + cfg.Application.Port); err != nil {
log.Fatal("Failed to start server:", err)
}
}()
// gracefully shutdown the server
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
slog.Info("Server is shutting down...")
if err := app.Server.ShutdownWithContext(ctx); err != nil {
log.Fatal("Failed to shutdown server:", err)
}
slog.Info("Server shut down successfully")
}