-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.go
50 lines (41 loc) · 898 Bytes
/
score.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
package score
import (
"log"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/nsogame/common"
)
type ScoreServer struct {
config *Config
db *common.DB
rds *common.RedisAPI
web *echo.Echo
}
func NewInstance(config *Config) (score *ScoreServer, err error) {
// db
db, err := common.ConnectDB(config.DbProvider, config.DbConnection)
if err != nil {
return
}
// router
web := echo.New()
web.Debug = config.Debug
web.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "method=${method}, uri=${uri}, status=${status}\n",
}))
web.Use(middleware.Recover())
score = &ScoreServer{
config: config,
db: db,
web: web,
}
score.router(web)
return
}
func (score *ScoreServer) close() {
score.db.Close()
}
func (score *ScoreServer) Run() {
defer score.close()
log.Fatal(score.web.Start(score.config.BindAddr))
}