-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (57 loc) · 1.42 KB
/
Copy pathmain.go
File metadata and controls
73 lines (57 loc) · 1.42 KB
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
73
package main
import (
"fmt"
"github.com/goris/conf/yaml"
"github.com/goris/router"
"github.com/goris/utils/types"
"github.com/kataras/iris"
"github.com/kataras/iris/mvc"
"strconv"
)
const (
assetsDir = "assets"
)
//错误句柄
func onError(ctx iris.Context) {
ctx.ViewData("", types.Err{"发生错误", ctx.GetStatusCode()})
ctx.View("public/error.html")
}
//读取基本配置
func loadConfig() error {
//读取数据库配置
c, err := yaml.DataBaseConf()
if err != nil {
return err
}
host, port, database, user, pass := c.String("host"), c.Int("port"), c.String("database"), c.String("user"), c.String("pass")
yaml.DB_SOURCE = user + ":" + pass + "@tcp(" + host + ":" + strconv.Itoa(port) + ")/" + database + "?charset=utf8"
//读取redis配置
c, err = yaml.RedisConf()
if err != nil {
return err
}
yaml.REDIS_SOURCE = c.String("host") + ":" + strconv.Itoa(c.Int("port"))
//读取业务配置
c, err = yaml.BusinessConf()
if err != nil {
return err
}
return nil
}
//主进程
func main() {
//加载配置
err := loadConfig()
if err != nil {
fmt.Println(err)
return
}
app := iris.New()
app.RegisterView(iris.HTML("apps/home/views", ".html").Layout("public/layout.html"))
//静态文件
app.StaticWeb("/static", assetsDir)
app.OnAnyErrorCode(onError)
mvc.Configure(app.Party("/"), router.HomeRouters)
mvc.Configure(app.Party("/admin"), router.AdminRouters)
app.Run(iris.Addr(":8080"))
}