-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
45 lines (33 loc) · 932 Bytes
/
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
package server
import (
"github.com/Buhrietoe/brood/server/apiv1"
"github.com/Buhrietoe/brood/server/middleware"
"github.com/gin-gonic/gin"
)
type Server struct {
Address string
Port string
ListenString string // Complete string of address:port to listen on
}
// BuildServer configures the web server
func BuildServer() *gin.Engine {
// The 'root' routes are configured here
gin.SetMode(gin.ReleaseMode)
// Default() automatically implements the recovery and logger middlewares
router := gin.Default()
// Default server header
router.Use(middleware.ServerHeader("brood"))
// Root redirect
router.GET("/", func(c *gin.Context) {
c.Redirect(301, "/static/")
})
// Health endpoint
router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
// Serve embedded GUI
router.StaticFS("/static", assetFS())
// API v1 endpoint
apiv1.APIV1(*router.Group("/api/v1/"))
return router
}