-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
59 lines (55 loc) · 1.41 KB
/
app.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
package bgin
import (
"github.com/foursking/bgin/helper/config"
"github.com/foursking/bgin/option"
"github.com/foursking/bgin/types"
"github.com/foursking/golib/utils/logger"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
"net/http"
)
var app *types.App
func New(options ...option.App) *types.App {
app = &types.App{}
*app = *types.DefaultApp
for key, value := range config.AppMap() {
switch key {
case "name":
app.Name = cast.ToString(value)
case "log_dir":
app.Logger.Dir = cast.ToString(value)
case "http_addr":
app.Server.Addr = cast.ToString(value)
case "version":
app.Version.Latest = cast.ToString(value)
case "version_key":
app.Version.Key = cast.ToString(value)
case "sign_key":
app.Sign.Key = cast.ToString(value)
case "sign_time_key":
app.Sign.TimeKey = cast.ToString(value)
case "sign_expiration":
app.Sign.Expiration = cast.ToInt64(value)
case "session_key":
app.Session.Key = cast.ToString(value)
case "session_key_prefix":
app.Session.KeyPrefix = cast.ToString(value)
case "session_expiration":
app.Session.Expiration = cast.ToInt64(value)
}
}
for _, opt := range options {
opt(app)
}
app.Server.Http = &http.Server{
Handler: gin.New(),
Addr: app.Server.Addr,
ReadTimeout: app.Server.ReadTimeout,
WriteTimeout: app.Server.WriteTimeout,
}
logger.SetLoggerDir(app.Logger.Dir)
return app
}
func App() *types.App {
return app
}