generated from IBM/template-go-gin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
46 lines (36 loc) · 1.08 KB
/
server.go
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
package main
import (
"github.com/IBM/go-gin-app/routers"
// "goginapp/plugins" if you create your own plugins import them here
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"os"
)
func port() string {
port := os.Getenv("PORT")
if len(port) == 0 {
port = "8080"
}
return ":" + port
}
func main() {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
router := gin.Default()
router.RedirectTrailingSlash = false
// Swagger endpoints
router.GET("/explorer", routers.SwaggerExplorerRedirect)
router.GET("/swagger/api", routers.SwaggerAPI)
router.Use(static.Serve("/explorer/", static.LocalFile("./public/swagger-ui/", true)))
// Static webpage content endpoints
router.LoadHTMLGlob("public/*.html")
router.Use(static.Serve("/", static.LocalFile("./public", false)))
router.GET("/", routers.Index)
router.NoRoute(routers.NotFoundError)
router.GET("/500", routers.InternalServerError)
// Health endpoint
router.GET("/health", routers.HealthGET)
log.Info("Starting Server on port " + port())
router.Run(port())
}