-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflute.go
51 lines (44 loc) · 997 Bytes
/
flute.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
package flute
import (
"github.com/robfig/config"
"os"
)
var Flute *Router
var Message map[string]string
var Config *config.Config
func init() {
Flute = NewRouter()
Message = make(map[string]string)
disableLog()
initAppConfig()
}
// 启动服务器, 需要传入一个地址
func Start() error {
addr, e := Config.String(Message["env"], "addr")
if e != nil {
return e
}
return Flute.Start(addr)
}
// 基础路由
func HandleFunc(path string, method string, f func(c *Context)) {
Flute.AddFunc(path, method, f)
}
// restful 路由风格
func Resources(path string, controller ControllerInterface, middlewares ...MiddlewareInterface) {
Flute.Resources(path, controller, middlewares)
}
// 加载配置文件到Message里面去
func LoadConfig() error {
if env := os.Getenv("FLUTEENV"); env != "" {
Message["env"] = env
} else {
Message["env"] = "development"
}
c, e := config.ReadDefault("./config/app_config.conf")
if e != nil {
return e
}
Config = c
return nil
}