1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00

opt handleCmd

This commit is contained in:
shaoying 2020-06-18 19:38:34 +08:00
parent 906a3cc6e2
commit fadbff380a
3 changed files with 80 additions and 79 deletions

View File

@ -56,9 +56,7 @@ func Login(msg *ice.Message, w http.ResponseWriter, r *http.Request) bool {
return msg.Option(ice.MSG_USERURL) != ""
}
func Trans(web *Frame, m *ice.Message, key string, cmd *ice.Command) {
web.HandleFunc(key, func(w http.ResponseWriter, r *http.Request) {
m.TryCatch(m.Spawns(), true, func(msg *ice.Message) {
func HandleCmd(key string, cmd *ice.Command, msg *ice.Message, w http.ResponseWriter, r *http.Request) {
defer func() { msg.Cost("%s %v %v", r.URL.Path, msg.Optionv("cmds"), msg.Format("append")) }()
if u, e := url.Parse(r.Header.Get("Referer")); e == nil {
for k, v := range u.Query() {
@ -68,7 +66,7 @@ func Trans(web *Frame, m *ice.Message, key string, cmd *ice.Command) {
}
// 用户请求
msg.Option(ice.MSG_USERWEB, m.Conf(SHARE, "meta.domain"))
msg.Option(ice.MSG_USERWEB, msg.Conf(SHARE, "meta.domain"))
msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent"))
msg.Option(ice.MSG_USERURL, r.URL.Path)
@ -132,8 +130,6 @@ func Trans(web *Frame, m *ice.Message, key string, cmd *ice.Command) {
// 渲染引擎
_args, _ := msg.Optionv(ice.MSG_ARGS).([]interface{})
Render(msg, msg.Option(ice.MSG_OUTPUT), _args...)
})
})
}
func (web *Frame) ServeHTTP(w http.ResponseWriter, r *http.Request) {
m := web.m

View File

@ -17,6 +17,9 @@ import (
)
func _link(m *ice.Message, pod interface{}) string {
if m.Option(ice.MSG_USERUA) == "" {
return kit.Format(pod)
}
return fmt.Sprintf(`<a target="_blank" href="%s?pod=%s">%s</a>`,
kit.Select(m.Conf(SHARE, "meta.domain"), m.Option(ice.MSG_USERWEB)), pod, pod)
}
@ -44,7 +47,7 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) {
host := kit.Format(client["hostname"])
proto := kit.Select("ws", "wss", client["protocol"] == "https")
uri := kit.MergeURL(proto+"://"+host+"/space/", "name", name)
uri := kit.MergeURL(proto+"://"+host+"/space/", "name", name, "type", cli.NodeType)
if u, e := url.Parse(uri); m.Assert(e) {
task.Put(dev, func(task *task.Task) error {
@ -212,13 +215,11 @@ func init() {
"/space/": {Name: "/space/", Help: "空间站", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if s, e := websocket.Upgrade(m.W, m.R, nil, m.Confi(ice.WEB_SPACE, "meta.buffer.r"), m.Confi(ice.WEB_SPACE, "meta.buffer.w")); m.Assert(e) {
name := m.Option(kit.MDB_NAME, strings.Replace(kit.Select(m.Option(ice.MSG_USERADDR), m.Option(kit.MDB_NAME)), ".", "_", -1))
kind := kit.Select(ice.WEB_WORKER, m.Option(kit.MDB_TYPE))
// 添加节点
h := m.Rich(ice.WEB_SPACE, nil, kit.Dict(
kit.MDB_TYPE, ice.WEB_WORKER,
kit.MDB_NAME, m.Option(kit.MDB_NAME),
kit.MDB_TEXT, s.RemoteAddr().String(),
"socket", s,
h := m.Rich(ice.WEB_SPACE, nil, kit.Dict("socket", s,
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, s.RemoteAddr().String(),
))
m.Log_CREATE(SPACE, name)

View File

@ -120,7 +120,11 @@ func (web *Frame) Start(m *ice.Message, arg ...string) bool {
m.Travel(func(p *ice.Context, sub *ice.Context, k string, x *ice.Command) {
if s == sub && k[0] == '/' {
msg.Log("route", "%s <- %s", s.Name, k)
Trans(w, msg, k, x)
w.HandleFunc(k, func(w http.ResponseWriter, r *http.Request) {
m.TryCatch(msg.Spawns(), true, func(msg *ice.Message) {
HandleCmd(k, x, msg, w, r)
})
})
}
})
}