-
Notifications
You must be signed in to change notification settings - Fork 179
/
main.go
64 lines (53 loc) · 1.71 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
package main
import (
"fmt"
"github.com/devfeel/dotweb"
"github.com/devfeel/dotweb/config"
"github.com/devfeel/dotweb/framework/json"
)
func main() {
//初始化DotServer
app := dotweb.New()
//注册HttpHandler
RegisterHandler(app.HttpServer)
//xml config
//appConfig, err := config.InitConfig("d:/gotmp/dotweb.conf")
//json config
//appConfig, err := config.InitConfig("d:/gotmp/dotweb.json", "json")
//yaml config
appConfig, err := config.InitConfig("d:/gotmp/dotweb.yaml", "yaml")
if err != nil {
fmt.Println("dotweb.InitConfig error => " + fmt.Sprint(err))
return
}
fmt.Println(jsonutil.GetJsonString(appConfig))
//引入自定义ConfigSet
err = app.Config.IncludeConfigSet("d:/gotmp/userconf.xml", config.ConfigType_XML)
if err != nil {
fmt.Println(err.Error())
return
}
app.SetConfig(appConfig)
fmt.Println("dotweb.StartServer => " + fmt.Sprint(appConfig))
err = app.Start()
fmt.Println("dotweb.StartServer error => ", err)
}
func Index(ctx dotweb.Context) error {
ctx.Response().Header().Set("Content-Type", "text/html; charset=utf-8")
return ctx.WriteString("index => ", fmt.Sprint(ctx.RouterNode().Middlewares()))
}
func GetAppSet(ctx dotweb.Context) error {
key := ctx.QueryString("key")
return ctx.WriteString(ctx.Request().Url(), " => key = ", ctx.ConfigSet().GetString(key))
}
// ConfigSet
func ConfigSet(ctx dotweb.Context) error {
vkey1 := ctx.ConfigSet().GetString("set1")
vkey2 := ctx.ConfigSet().GetString("set2")
return ctx.WriteString(ctx.Request().Path(), "key1=", vkey1, "key2=", vkey2)
}
func RegisterHandler(server *dotweb.HttpServer) {
server.Router().RegisterHandler("Index", Index)
server.Router().RegisterHandler("appset", GetAppSet)
server.GET("/configser", ConfigSet)
}