-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (36 loc) · 794 Bytes
/
main.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 main
import (
"embed"
"flag"
"fmt"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"github.com/tz039e/water_sub/controllers"
"github.com/tz039e/water_sub/models"
)
//go:embed frontend/build
var frontendFS embed.FS
func main() {
// flags
addr := flag.String("addr", "", "listen address")
port := flag.String("port", "", "port")
flag.Parse()
if *port == "" {
panic("port is empty")
}
// gin
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
// routing
r.Use(static.Serve("/", EmbedDir(frontendFS, "frontend/build")))
api := r.Group("/api")
{
api.GET("/record", controllers.GetRecords)
api.POST("/record", controllers.PostRecord)
}
// db setup
models.ConnectDB()
// run
fmt.Println("listening on port", *port)
r.Run(*addr + ":" + *port)
}