-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpController.go
54 lines (49 loc) · 1.62 KB
/
httpController.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
package web
import (
"net/http"
"text/template"
"github.com/henrylee2cn/pholcus/app"
"github.com/henrylee2cn/pholcus/common/session"
"github.com/henrylee2cn/pholcus/config"
"github.com/henrylee2cn/pholcus/logs"
"github.com/henrylee2cn/pholcus/runtime/status"
)
var globalSessions *session.Manager
func init() {
globalSessions, _ = session.NewManager("memory", `{"cookieName":"pholcusSession", "enableSetCookie,omitempty": true, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 157680000, "providerConfig": ""}`)
// go globalSessions.GC()
}
// 处理web页面请求
func web(rw http.ResponseWriter, req *http.Request) {
sess, _ := globalSessions.SessionStart(rw, req)
defer sess.SessionRelease(rw)
index, _ := viewsIndexHtmlBytes()
t, err := template.New("index").Parse(string(index)) //解析模板文件
// t, err := template.ParseFiles("web/views/index.html") //解析模板文件
if err != nil {
logs.Log.Error("%v", err)
}
//获取pholcus信息
data := map[string]interface{}{
"title": config.NAME,
"logo": config.ICON_PNG,
"version": config.VERSION,
"author": config.AUTHOR,
"mode": map[string]int{
"offline": status.OFFLINE,
"server": status.SERVER,
"client": status.CLIENT,
"unset": status.UNSET,
"curr": app.LogicApp.GetAppConf("mode").(int),
},
"status": map[string]int{
"stopped": status.STOPPED,
"stop": status.STOP,
"run": status.RUN,
"pause": status.PAUSE,
},
"port": app.LogicApp.GetAppConf("port").(int),
"ip": app.LogicApp.GetAppConf("master").(string),
}
t.Execute(rw, data) //执行模板的merger操作
}