-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (59 loc) · 1.34 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 (
"os"
"strings"
"time"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/your-overtime/api/api"
docs "github.com/your-overtime/api/docs"
"github.com/your-overtime/api/internal/data"
"github.com/your-overtime/api/internal/service"
log "github.com/sirupsen/logrus"
)
var version = "1.0.0"
// @title Your Overtime API
// @version 1.0
// @BasePath /api/v1
// @securityDefinitions.basic BasicAuth
//
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
// @securityDefinitions.apikey AdminAuth
// @in query
// @name adminToken
func main() {
docs.SwaggerInfo.Schemes = []string{"https", "http"}
docs.SwaggerInfo.Version = version
godotenv.Load()
log.SetFormatter(&log.TextFormatter{
DisableColors: true,
FullTimestamp: true,
})
log.SetReportCaller(true)
if strings.ToLower(os.Getenv("DEBUG")) == "true" {
log.SetLevel(log.DebugLevel)
} else {
gin.SetMode(gin.ReleaseMode)
}
if len(os.Getenv("TZ")) > 0 {
loc, err := time.LoadLocation(os.Getenv("TZ"))
if err != nil {
panic(err)
}
time.Local = loc
}
db, err := data.Init(
os.Getenv("DB_USER"),
os.Getenv("DB_PASSWORD"),
os.Getenv("DB_HOST"),
os.Getenv("DB_NAME"),
)
if err != nil {
panic(err)
}
ovs := service.Init(db)
api := api.Init(ovs, os.Getenv("ADMIN_TOKEN"))
api.Start(os.Getenv("HOST"))
}