-
Notifications
You must be signed in to change notification settings - Fork 590
/
main.go
75 lines (58 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
69
70
71
72
package main
import (
"fmt"
"os"
"time"
"strconv"
_ "github.com/jinzhu/gorm/dialects/mysql"
"github.com/jinzhu/gorm"
"gopkg.in/kataras/iris.v6"
"gopkg.in/kataras/iris.v6/adaptors/httprouter"
"gopkg.in/kataras/iris.v6/adaptors/sessions"
"wemall/config"
"wemall/model"
"wemall/route"
)
func init() {
db, err := gorm.Open(config.DBConfig.Dialect, config.DBConfig.URL)
if err != nil {
fmt.Println(err.Error())
os.Exit(-1)
}
if config.DBConfig.SQLLog {
db.LogMode(true)
}
db.DB().SetMaxIdleConns(config.DBConfig.MaxIdleConns);
db.DB().SetMaxOpenConns(config.DBConfig.MaxOpenConns)
model.DB = db;
}
func main() {
app := iris.New(iris.Configuration{
Gzip : true,
Charset : "UTF-8",
})
if config.ServerConfig.Debug {
app.Adapt(iris.DevLogger())
}
app.Adapt(sessions.New(sessions.Config{
Cookie: config.ServerConfig.SessionID,
Expires: time.Minute * 20,
}))
app.Adapt(httprouter.New())
route.Route(app)
app.OnError(iris.StatusNotFound, func(ctx *iris.Context) {
ctx.JSON(iris.StatusOK, iris.Map{
"errNo" : model.ErrorCode.NotFound,
"msg" : "Not Found",
"data" : iris.Map{},
})
})
app.OnError(500, func(ctx *iris.Context) {
ctx.JSON(iris.StatusInternalServerError, iris.Map{
"errNo" : model.ErrorCode.ERROR,
"msg" : "error",
"data" : iris.Map{},
})
})
app.Listen(":" + strconv.Itoa(config.ServerConfig.Port))
}