-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
47 lines (37 loc) · 1.12 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
package main
import (
"os"
"github.com/gin-gonic/gin"
"github.com/gin-contrib/static"
log "github.com/sirupsen/logrus"
routers "github.com/mazeForGit/Wordlist/routers"
)
func port() string {
port := os.Getenv("PORT")
if len(port) == 0 {
port = "5000"
}
return ":" + port
}
func main() {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
router := gin.Default()
router.RedirectTrailingSlash = false
router.LoadHTMLGlob("public/*.html")
router.Use(static.Serve("/", static.LocalFile("./public", false)))
router.GET("/index", routers.Index)
router.NoRoute(routers.NotFoundError)
router.GET("/500", routers.InternalServerError)
router.GET("/health", routers.HealthGET)
router.GET("/words", routers.WordsGET)
router.POST("/words", routers.WordsPOST)
router.GET("/words/:id", routers.WordsByIdGET)
router.DELETE("/words/:id", routers.WordsByIdDELETE)
router.GET("/tests", routers.TestsGET)
router.GET("/wordlist", routers.WordListGET)
router.PUT("/wordlist", routers.WordListPUT)
router.DELETE("/wordlist", routers.WordListDELETE)
log.Info("Starting server on port " + port())
router.Run(port())
}