-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.go
49 lines (41 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
47
48
49
/*
@File: server.go
@Contact: lucien@lucien.ink
@Licence: (C)Copyright 2019 Lucien Shui
@Modify Time @Author @Version @Description
------------ ------- -------- -----------
2019-06-21 08:37 Lucien 1.0 Init
*/
package server
import (
"fmt"
"github.com/PasteUs/PasteMeGoBackend/flag"
"github.com/gin-gonic/gin"
"github.com/wonderivan/logger"
)
var router *gin.Engine
func init() {
if !flag.Debug {
gin.SetMode(gin.ReleaseMode)
}
router = gin.Default()
api := router.Group("/api")
{
api.GET("/", beat)
api.GET("/:token", query)
api.POST("/", permanentCreator)
api.POST("/once", readOnceCreator)
api.PUT("/:key", temporaryCreator)
// router.NoRoute(notFoundHandler)
}
router.Static("/pasteme_frontend/", "pasteme_frontend/")
router.Static("/usr/", "pasteme_frontend/usr/")
router.NoRoute(func(requests *gin.Context) {
requests.File("pasteme_frontend/index.html")
})
}
func Run(address string, port uint16) {
if err := router.Run(fmt.Sprintf("%s:%d", address, port)); err != nil {
logger.Painc("Run server failed: " + err.Error())
}
}