-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
39 lines (36 loc) · 936 Bytes
/
Copy pathmain.go
File metadata and controls
39 lines (36 loc) · 936 Bytes
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
package main
import (
"CephMonitorAPI/api/server"
"context"
"github.com/swaggo/files"
"github.com/swaggo/gin-swagger"
"log"
"net/http"
"os"
"os/signal"
"time"
)
func main() {
router := server.NewRouter()
svc := &http.Server{
Handler: router,
Addr: ":10086",
}
url := ginSwagger.URL("http://localhost:10086/swagger/doc.json") // The url pointing to API definition
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
go func() {
if err := svc.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("listen: %s \n", err)
}
}()
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
log.Println("Shutdown server... free MyCephConn!!")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := svc.Shutdown(ctx); err != nil {
log.Fatal("Server Shutdown:", err)
}
log.Println("Server exiting...")
}