-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (57 loc) · 1.38 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"log"
"os"
"shisha-log-backend/handler"
"shisha-log-backend/lib"
"shisha-log-backend/model/diary"
"shisha-log-backend/model/flavor"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
const location = "Asia/Tokyo"
func init() {
loc, err := time.LoadLocation(location)
if err != nil {
loc = time.FixedZone(location, 9*60*60)
}
time.Local = loc
}
func main() {
userDiaries := diary.NewUserDiaries()
userEquipments := handler.NewUserEquipments()
flavorBrand := &flavor.FlavorBrand{}
_, err := os.Stat(".env")
if err == nil {
err := godotenv.Load(".env")
if err != nil {
log.Fatal(err)
}
}
lib.DBOpen()
defer lib.DBClose()
r := gin.Default()
r.Use(cors.New(cors.Config{
AllowOrigins: []string{
os.Getenv("SHISHA_LOG_CLIENT_URL"),
os.Getenv("SHISHA_LOG_CLIENT_STG_URL"),
},
AllowMethods: []string{"GET", "POST"},
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"},
}))
r.GET("/diary/:user_id", handler.GetUserDiaries(userDiaries))
r.POST("/diary", handler.CreateDiary)
r.GET("/user/:user_id/equipment", handler.UserEquipmentsGet(userEquipments))
flavor := r.Group("/flavor")
{
flavor.POST("", handler.CreateFlavor())
flavor.POST("/brand", handler.CreateFlavorBrand(flavorBrand))
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
r.Run(":" + port)
}