forked from x/icebergs
opt wiki.title
This commit is contained in:
parent
8e432deab6
commit
6c32418390
127
base/web/web.go
127
base/web/web.go
@ -21,7 +21,7 @@ const (
|
|||||||
MSG_MAPS = 1
|
MSG_MAPS = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
type WEB struct {
|
type Frame struct {
|
||||||
*http.Client
|
*http.Client
|
||||||
*http.Server
|
*http.Server
|
||||||
*http.ServeMux
|
*http.ServeMux
|
||||||
@ -37,7 +37,7 @@ func Cookie(msg *ice.Message, sessid string) string {
|
|||||||
return sessid
|
return sessid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (web *WEB) Login(msg *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
func (web *Frame) Login(msg *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||||
if msg.Options(ice.WEB_SESS) {
|
if msg.Options(ice.WEB_SESS) {
|
||||||
sub := msg.Cmd("aaa.sess", "check", msg.Option(ice.WEB_SESS))
|
sub := msg.Cmd("aaa.sess", "check", msg.Option(ice.WEB_SESS))
|
||||||
msg.Log("info", "role: %s user: %s", msg.Option("userrole", sub.Append("userrole")),
|
msg.Log("info", "role: %s user: %s", msg.Option("userrole", sub.Append("userrole")),
|
||||||
@ -47,7 +47,7 @@ func (web *WEB) Login(msg *ice.Message, w http.ResponseWriter, r *http.Request)
|
|||||||
msg.Runs("_login", msg.Option("url"), kit.Simple(msg.Optionv("cmds"))...)
|
msg.Runs("_login", msg.Option("url"), kit.Simple(msg.Optionv("cmds"))...)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (web *WEB) HandleWSS(m *ice.Message, safe bool, c *websocket.Conn) bool {
|
func (web *Frame) HandleWSS(m *ice.Message, safe bool, c *websocket.Conn) bool {
|
||||||
for {
|
for {
|
||||||
if t, b, e := c.ReadMessage(); e != nil {
|
if t, b, e := c.ReadMessage(); e != nil {
|
||||||
m.Log("warn", "space recv %d msg %v", t, e)
|
m.Log("warn", "space recv %d msg %v", t, e)
|
||||||
@ -107,44 +107,52 @@ func (web *WEB) HandleWSS(m *ice.Message, safe bool, c *websocket.Conn) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func (web *WEB) HandleCGI(m *ice.Message, which string) *template.Template {
|
func (web *Frame) HandleCGI(m *ice.Message, alias map[string]interface{}, which string) *template.Template {
|
||||||
cgi := template.FuncMap{
|
cgi := template.FuncMap{
|
||||||
"result": func(msg *ice.Message) string {
|
"result": func(msg *ice.Message) string {
|
||||||
return msg.Result()
|
return msg.Result()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tmpl := template.New("render")
|
|
||||||
|
tmpl := template.New(ice.WEB_TMPL)
|
||||||
|
cb := func(k string, p []string, v *ice.Command) {
|
||||||
|
cgi[k] = func(arg ...interface{}) (res interface{}) {
|
||||||
|
m.TryCatch(m.Spawn(), true, func(msg *ice.Message) {
|
||||||
|
v.Hand(msg, m.Target(), k, kit.Simple(p, arg)...)
|
||||||
|
|
||||||
|
buffer := bytes.NewBuffer([]byte{})
|
||||||
|
m.Assert(tmpl.ExecuteTemplate(buffer, msg.Option(ice.WEB_TMPL), msg))
|
||||||
|
res = string(buffer.Bytes())
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for k, v := range alias {
|
||||||
|
list := kit.Simple(v)
|
||||||
|
if v, ok := m.Target().Commands[list[0]]; ok {
|
||||||
|
m.Log("info", "%v, %v", k, v.Name)
|
||||||
|
cb(k, list[1:], v)
|
||||||
|
}
|
||||||
|
}
|
||||||
for k, v := range m.Target().Commands {
|
for k, v := range m.Target().Commands {
|
||||||
m.Log("info", "%v, %v", k, v.Name)
|
m.Log("info", "%v, %v", k, v.Name)
|
||||||
if strings.HasPrefix(k, "/") || strings.HasPrefix(k, "_") {
|
if strings.HasPrefix(k, "/") || strings.HasPrefix(k, "_") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
cb(k, nil, v)
|
||||||
func(k string, v *ice.Command) {
|
|
||||||
cgi[k] = func(arg ...interface{}) (res interface{}) {
|
|
||||||
m.TryCatch(m.Spawn(), true, func(msg *ice.Message) {
|
|
||||||
msg.Option("render", "table")
|
|
||||||
v.Hand(msg, m.Target(), k, kit.Simple(arg)...)
|
|
||||||
|
|
||||||
buffer := bytes.NewBuffer([]byte{})
|
|
||||||
m.Assert(tmpl.ExecuteTemplate(buffer, msg.Option("render"), msg))
|
|
||||||
res = string(buffer.Bytes())
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}(k, v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl = tmpl.Funcs(cgi)
|
tmpl = tmpl.Funcs(cgi)
|
||||||
// tmpl = template.Must(tmpl.ParseGlob(path.Join(m.Conf("serve", "template.path"), "/*.tmpl")))
|
// tmpl = template.Must(tmpl.ParseGlob(path.Join(m.Conf(ice.WEB_SERVE, "template.path"), "/*.tmpl")))
|
||||||
// tmpl = template.Must(tmpl.ParseGlob(path.Join(m.Conf("serve", "template.path"), m.Target().Name, "/*.tmpl")))
|
// tmpl = template.Must(tmpl.ParseGlob(path.Join(m.Conf(ice.WEB_SERVE, "template.path"), m.Target().Name, "/*.tmpl")))
|
||||||
tmpl = template.Must(tmpl.ParseFiles(which))
|
tmpl = template.Must(tmpl.ParseFiles(which))
|
||||||
m.Confm("serve", "template.list", func(index int, value string) { tmpl = template.Must(tmpl.Parse(value)) })
|
m.Confm(ice.WEB_SERVE, "template.list", func(index int, value string) { tmpl = template.Must(tmpl.Parse(value)) })
|
||||||
for i, v := range tmpl.Templates() {
|
for i, v := range tmpl.Templates() {
|
||||||
m.Log("info", "%v, %v", i, v.Name())
|
m.Log("info", "%v, %v", i, v.Name())
|
||||||
}
|
}
|
||||||
return tmpl
|
return tmpl
|
||||||
}
|
}
|
||||||
func (web *WEB) HandleCmd(m *ice.Message, key string, cmd *ice.Command) {
|
func (web *Frame) HandleCmd(m *ice.Message, key string, cmd *ice.Command) {
|
||||||
web.HandleFunc(key, func(w http.ResponseWriter, r *http.Request) {
|
web.HandleFunc(key, func(w http.ResponseWriter, r *http.Request) {
|
||||||
m.TryCatch(m.Spawns(), true, func(msg *ice.Message) {
|
m.TryCatch(m.Spawns(), true, func(msg *ice.Message) {
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -210,7 +218,7 @@ func (web *WEB) HandleCmd(m *ice.Message, key string, cmd *ice.Command) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func (web *WEB) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (web *Frame) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
m := web.m
|
m := web.m
|
||||||
|
|
||||||
index := r.Header.Get("index.module") == ""
|
index := r.Header.Get("index.module") == ""
|
||||||
@ -233,16 +241,16 @@ func (web *WEB) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
web.ServeMux.ServeHTTP(w, r)
|
web.ServeMux.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (web *WEB) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server {
|
func (web *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server {
|
||||||
return &WEB{}
|
return &Frame{}
|
||||||
}
|
}
|
||||||
func (web *WEB) Begin(m *ice.Message, arg ...string) ice.Server {
|
func (web *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
|
||||||
web.send = map[string]*ice.Message{}
|
web.send = map[string]*ice.Message{}
|
||||||
return web
|
return web
|
||||||
}
|
}
|
||||||
func (web *WEB) Start(m *ice.Message, arg ...string) bool {
|
func (web *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||||
m.Travel(func(p *ice.Context, s *ice.Context) {
|
m.Travel(func(p *ice.Context, s *ice.Context) {
|
||||||
if w, ok := s.Server().(*WEB); ok {
|
if w, ok := s.Server().(*Frame); ok {
|
||||||
if w.ServeMux != nil {
|
if w.ServeMux != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -251,7 +259,7 @@ func (web *WEB) Start(m *ice.Message, arg ...string) bool {
|
|||||||
|
|
||||||
// 级联路由
|
// 级联路由
|
||||||
route := "/" + s.Name + "/"
|
route := "/" + s.Name + "/"
|
||||||
if n, ok := p.Server().(*WEB); ok && n.ServeMux != nil {
|
if n, ok := p.Server().(*Frame); ok && n.ServeMux != nil {
|
||||||
msg.Log("route", "%s <= %s", p.Name, route)
|
msg.Log("route", "%s <= %s", p.Name, route)
|
||||||
n.Handle(route, http.StripPrefix(path.Dir(route), w))
|
n.Handle(route, http.StripPrefix(path.Dir(route), w))
|
||||||
}
|
}
|
||||||
@ -272,41 +280,31 @@ func (web *WEB) Start(m *ice.Message, arg ...string) bool {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
port := kit.Select(m.Conf("spide", "self.port"), arg, 0)
|
port := m.Cap(ice.CTX_STREAM, kit.Select(m.Conf(ice.WEB_SPIDE, "self.port"), arg, 0))
|
||||||
m.Cap(ice.CTX_STREAM, port)
|
m.Log("serve", "listen %s %v", port, m.Conf("cli.runtime", "node"))
|
||||||
web.m = m
|
web.m, web.Server = m, &http.Server{Addr: port, Handler: web}
|
||||||
web.Server = &http.Server{Addr: port, Handler: web}
|
|
||||||
m.Log("serve", "node %v", m.Conf("cli.runtime", "node"))
|
|
||||||
m.Log("serve", "listen %s", port)
|
|
||||||
m.Log("serve", "listen %s", web.Server.ListenAndServe())
|
m.Log("serve", "listen %s", web.Server.ListenAndServe())
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (web *WEB) Close(m *ice.Message, arg ...string) bool {
|
func (web *Frame) Close(m *ice.Message, arg ...string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
var Index = &ice.Context{Name: "web", Help: "网页模块",
|
var Index = &ice.Context{Name: "web", Help: "网页模块",
|
||||||
Caches: map[string]*ice.Cache{},
|
Caches: map[string]*ice.Cache{},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
"spide": {Name: "客户端", Value: map[string]interface{}{
|
ice.WEB_SPIDE: {Name: "客户端", Value: map[string]interface{}{
|
||||||
"self": map[string]interface{}{"port": ice.WEB_PORT},
|
"self": map[string]interface{}{"port": ice.WEB_PORT},
|
||||||
}},
|
}},
|
||||||
"serve": {Name: "服务端", Value: map[string]interface{}{
|
ice.WEB_SERVE: {Name: "服务端", Value: map[string]interface{}{
|
||||||
"static": map[string]interface{}{"/": "usr/volcanos/",
|
"static": map[string]interface{}{"/": "usr/volcanos/",
|
||||||
"/static/volcanos/": "usr/volcanos/",
|
"/static/volcanos/": "usr/volcanos/",
|
||||||
},
|
},
|
||||||
"template": map[string]interface{}{
|
"template": map[string]interface{}{"path": "usr/template", "list": []interface{}{
|
||||||
"path": "usr/template",
|
`{{define "raw"}}{{.|result}}{{end}}`,
|
||||||
"list": []interface{}{
|
}},
|
||||||
`{{define "raw"}}{{.|result}}{{end}}`,
|
|
||||||
`{{define "title"}}{{.|result}}{{end}}`,
|
|
||||||
`{{define "chapter"}}{{.|result}}{{end}}`,
|
|
||||||
`{{define "section"}}{{.|result}}{{end}}`,
|
|
||||||
`{{define "block"}}<div>{{.|result}}<div>{{end}}`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}},
|
}},
|
||||||
"space": {Name: "空间端", Value: map[string]interface{}{
|
ice.WEB_SPACE: {Name: "空间端", Value: map[string]interface{}{
|
||||||
ice.MDB_META: map[string]interface{}{"buffer": 4096, "redial": 3000},
|
ice.MDB_META: map[string]interface{}{"buffer": 4096, "redial": 3000},
|
||||||
ice.MDB_HASH: map[string]interface{}{},
|
ice.MDB_HASH: map[string]interface{}{},
|
||||||
ice.MDB_LIST: map[string]interface{}{},
|
ice.MDB_LIST: map[string]interface{}{},
|
||||||
@ -314,17 +312,16 @@ var Index = &ice.Context{Name: "web", Help: "网页模块",
|
|||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Echo("hello %s world", c.Name)
|
|
||||||
}},
|
}},
|
||||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Done()
|
m.Done()
|
||||||
}},
|
}},
|
||||||
"serve": {Name: "hi", Help: "hello", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.WEB_SERVE: {Name: "serve", Help: "服务器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Conf("cli.runtime", "node.type", "server")
|
|
||||||
m.Conf("cli.runtime", "node.name", m.Conf("cli.runtime", "boot.hostname"))
|
m.Conf("cli.runtime", "node.name", m.Conf("cli.runtime", "boot.hostname"))
|
||||||
|
m.Conf("cli.runtime", "node.type", "server")
|
||||||
m.Target().Start(m, arg...)
|
m.Target().Start(m, arg...)
|
||||||
}},
|
}},
|
||||||
"/space": &ice.Command{Name: "/space", Help: "", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"/space": &ice.Command{Name: "/space", Help: "工作间", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
r := m.Optionv("request").(*http.Request)
|
r := m.Optionv("request").(*http.Request)
|
||||||
w := m.Optionv("response").(http.ResponseWriter)
|
w := m.Optionv("response").(http.ResponseWriter)
|
||||||
if s, e := websocket.Upgrade(w, r, nil, m.Confi("web.space", "meta.buffer"), m.Confi("web.space", "meta.buffer")); m.Assert(e) {
|
if s, e := websocket.Upgrade(w, r, nil, m.Confi("web.space", "meta.buffer"), m.Confi("web.space", "meta.buffer")); m.Assert(e) {
|
||||||
@ -336,26 +333,26 @@ var Index = &ice.Context{Name: "web", Help: "网页模块",
|
|||||||
"type": m.Option("node"),
|
"type": m.Option("node"),
|
||||||
"name": m.Option("name"),
|
"name": m.Option("name"),
|
||||||
}
|
}
|
||||||
m.Confv("space", []string{ice.MDB_HASH, h}, meta)
|
m.Confv(ice.WEB_SPACE, []string{ice.MDB_HASH, h}, meta)
|
||||||
m.Log("space", "conn %v %v", h, kit.Formats(m.Confv("space")))
|
m.Log("space", "conn %v %v", h, kit.Formats(m.Confv(ice.WEB_SPACE)))
|
||||||
|
|
||||||
web := m.Target().Server().(*WEB)
|
web := m.Target().Server().(*Frame)
|
||||||
m.Gos(m, func(m *ice.Message) {
|
m.Gos(m, func(m *ice.Message) {
|
||||||
web.HandleWSS(m, false, s)
|
web.HandleWSS(m, false, s)
|
||||||
m.Log("space", "close %v %v", h, kit.Formats(m.Confv("space")))
|
m.Log("space", "close %v %v", h, kit.Formats(m.Confv(ice.WEB_SPACE)))
|
||||||
m.Confv("space", []string{ice.MDB_HASH, h}, "")
|
m.Confv(ice.WEB_SPACE, []string{ice.MDB_HASH, h}, "")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
"space": &ice.Command{Name: "space", Help: "", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.WEB_SPACE: &ice.Command{Name: "space", Help: "工作间", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
m.Conf("space", ice.MDB_HASH, func(key string, value map[string]interface{}) {
|
m.Conf(ice.WEB_SPACE, ice.MDB_HASH, func(key string, value map[string]interface{}) {
|
||||||
m.Push(key, value)
|
m.Push(key, value)
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
web := m.Target().Server().(*WEB)
|
web := m.Target().Server().(*Frame)
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
case "connect":
|
case "connect":
|
||||||
node, name := m.Conf("cli.runtime", "node.type"), m.Conf("cli.runtime", "boot.hostname")
|
node, name := m.Conf("cli.runtime", "node.type"), m.Conf("cli.runtime", "boot.hostname")
|
||||||
@ -395,7 +392,7 @@ var Index = &ice.Context{Name: "web", Help: "网页模块",
|
|||||||
}
|
}
|
||||||
|
|
||||||
target := strings.Split(arg[0], ".")
|
target := strings.Split(arg[0], ".")
|
||||||
if socket, ok := m.Confv("space", "hash."+target[0]+".socket").(*websocket.Conn); !ok {
|
if socket, ok := m.Confv(ice.WEB_SPACE, "hash."+target[0]+".socket").(*websocket.Conn); !ok {
|
||||||
m.Echo("error").Echo("not found")
|
m.Echo("error").Echo("not found")
|
||||||
} else {
|
} else {
|
||||||
id := kit.Format(c.ID())
|
id := kit.Format(c.ID())
|
||||||
@ -403,7 +400,7 @@ var Index = &ice.Context{Name: "web", Help: "网页模块",
|
|||||||
m.Optionv("_target", target[1:])
|
m.Optionv("_target", target[1:])
|
||||||
m.Set(ice.MSG_DETAIL, arg[1:]...)
|
m.Set(ice.MSG_DETAIL, arg[1:]...)
|
||||||
|
|
||||||
web := m.Target().Server().(*WEB)
|
web := m.Target().Server().(*Frame)
|
||||||
web.send[id] = m
|
web.send[id] = m
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@ -419,4 +416,4 @@ var Index = &ice.Context{Name: "web", Help: "网页模块",
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { ice.Index.Register(Index, &WEB{}) }
|
func init() { ice.Index.Register(Index, &Frame{}) }
|
||||||
|
17
conf.go
17
conf.go
@ -22,15 +22,20 @@ const (
|
|||||||
MDB_LIST = "list"
|
MDB_LIST = "list"
|
||||||
MDB_HASH = "hash"
|
MDB_HASH = "hash"
|
||||||
)
|
)
|
||||||
|
const (
|
||||||
|
WEB_PORT = ":9020"
|
||||||
|
WEB_SESS = "sessid"
|
||||||
|
WEB_TMPL = "render"
|
||||||
|
|
||||||
|
WEB_SPIDE = "spide"
|
||||||
|
WEB_SERVE = "serve"
|
||||||
|
WEB_SPACE = "space"
|
||||||
|
)
|
||||||
const (
|
const (
|
||||||
GDB_SIGNAL = "signal"
|
GDB_SIGNAL = "signal"
|
||||||
GDB_TIMER = "timer"
|
GDB_TIMER = "timer"
|
||||||
GDB_EVENT = "event"
|
GDB_EVENT = "event"
|
||||||
)
|
)
|
||||||
const (
|
|
||||||
WEB_PORT = ":9020"
|
|
||||||
WEB_SESS = "sessid"
|
|
||||||
)
|
|
||||||
const (
|
const (
|
||||||
LOG_CMD = "cmd"
|
LOG_CMD = "cmd"
|
||||||
LOG_INFO = "info"
|
LOG_INFO = "info"
|
||||||
@ -47,4 +52,8 @@ var Alias = map[string]string{
|
|||||||
GDB_SIGNAL: "gdb.signal",
|
GDB_SIGNAL: "gdb.signal",
|
||||||
GDB_TIMER: "gdb.timer",
|
GDB_TIMER: "gdb.timer",
|
||||||
GDB_EVENT: "gdb.event",
|
GDB_EVENT: "gdb.event",
|
||||||
|
|
||||||
|
WEB_SPIDE: "web.spide",
|
||||||
|
WEB_SPACE: "web.space",
|
||||||
|
"note": "web.wiki.note",
|
||||||
}
|
}
|
||||||
|
@ -191,4 +191,4 @@ var Index = &ice.Context{Name: "chat", Help: "聊天模块",
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { web.Index.Register(Index, &web.WEB{}) }
|
func init() { web.Index.Register(Index, &web.Frame{}) }
|
||||||
|
@ -488,4 +488,4 @@ var Index = &ice.Context{Name: "code", Help: "编程模块",
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { web.Index.Register(Index, &web.WEB{}) }
|
func init() { web.Index.Register(Index, &web.Frame{}) }
|
||||||
|
@ -137,4 +137,4 @@ var Index = &ice.Context{Name: "mall", Help: "团队模块",
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { web.Index.Register(Index, &web.WEB{}) }
|
func init() { web.Index.Register(Index, &web.Frame{}) }
|
||||||
|
@ -69,4 +69,4 @@ var Index = &ice.Context{Name: "team", Help: "团队模块",
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { web.Index.Register(Index, &web.WEB{}) }
|
func init() { web.Index.Register(Index, &web.Frame{}) }
|
||||||
|
@ -51,10 +51,10 @@ func (b *Block) Draw(m *ice.Message, x, y int) Chart {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
func (b *Block) Data(root interface{}) {
|
func (b *Block) Data(root interface{}) {
|
||||||
kit.Table(kit.Value(root, "data"), 0, 100, func(key string, value string) {
|
kit.Fetch(kit.Value(root, "data"), func(key string, value string) {
|
||||||
b.TextData += key + "='" + value + "' "
|
b.TextData += key + "='" + value + "' "
|
||||||
})
|
})
|
||||||
kit.Table(kit.Value(root, "rect"), 0, 100, func(key string, value string) {
|
kit.Fetch(kit.Value(root, "rect"), func(key string, value string) {
|
||||||
b.RectData += key + "='" + value + "' "
|
b.RectData += key + "='" + value + "' "
|
||||||
})
|
})
|
||||||
b.FontColor = kit.Select(b.FontColor, kit.Value(root, "fg"))
|
b.FontColor = kit.Select(b.FontColor, kit.Value(root, "fg"))
|
||||||
|
@ -2,35 +2,67 @@ package wiki
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gomarkdown/markdown"
|
"github.com/gomarkdown/markdown"
|
||||||
"github.com/shylinux/toolkits"
|
|
||||||
|
|
||||||
"github.com/shylinux/icebergs"
|
"github.com/shylinux/icebergs"
|
||||||
_ "github.com/shylinux/icebergs/base"
|
_ "github.com/shylinux/icebergs/base"
|
||||||
"github.com/shylinux/icebergs/base/web"
|
"github.com/shylinux/icebergs/base/web"
|
||||||
|
"github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var prefix = `<svg vertion="1.1" xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="{{.Option "width"}}" height="{{.Option "height"}}" style="{{.Option "style"}}"
|
||||||
|
data-name="{{.Option "name"}}"
|
||||||
|
>`
|
||||||
|
var title = `<span>{{.Option "prefix"}}{{.Option "content"}}</span>`
|
||||||
|
|
||||||
var Index = &ice.Context{Name: "wiki", Help: "文档模块",
|
var Index = &ice.Context{Name: "wiki", Help: "文档模块",
|
||||||
Caches: map[string]*ice.Cache{},
|
Caches: map[string]*ice.Cache{},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
"note": {Name: "note", Value: map[string]interface{}{
|
"note": {Name: "note", Help: "笔记", Value: map[string]interface{}{
|
||||||
ice.MDB_META: map[string]interface{}{
|
ice.MDB_META: map[string]interface{}{
|
||||||
|
"temp": "var/tmp/file",
|
||||||
"path": "usr/local/wiki",
|
"path": "usr/local/wiki",
|
||||||
|
"head": "time size line path",
|
||||||
|
"alias": map[string]interface{}{
|
||||||
|
"block": []interface{}{"chart", "block"},
|
||||||
|
"chain": []interface{}{"chart", "chain"},
|
||||||
|
"table": []interface{}{"chart", "table"},
|
||||||
|
|
||||||
|
"chapter": []interface{}{"title", "chapter"},
|
||||||
|
"section": []interface{}{"title", "section"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ice.MDB_LIST: map[string]interface{}{},
|
||||||
|
ice.MDB_HASH: map[string]interface{}{},
|
||||||
|
}},
|
||||||
|
"chart": {Name: "chart", Help: "绘图", Value: map[string]interface{}{
|
||||||
|
ice.MDB_META: map[string]interface{}{
|
||||||
|
"prefix": prefix, "suffix": `</svg>`,
|
||||||
|
},
|
||||||
|
ice.MDB_LIST: map[string]interface{}{},
|
||||||
|
ice.MDB_HASH: map[string]interface{}{},
|
||||||
|
}},
|
||||||
|
"title": {Name: "title", Help: "标题", Value: map[string]interface{}{
|
||||||
|
ice.MDB_META: map[string]interface{}{
|
||||||
|
"title": title,
|
||||||
},
|
},
|
||||||
ice.MDB_LIST: map[string]interface{}{},
|
ice.MDB_LIST: map[string]interface{}{},
|
||||||
ice.MDB_HASH: map[string]interface{}{},
|
ice.MDB_HASH: map[string]interface{}{},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
"chart": {Name: "chart", Help: "绘图", List: []interface{}{
|
"chart": {Name: "chart block|chain|table name text [fg bg fs ls p m]", Help: "绘图", Meta: map[string]interface{}{
|
||||||
map[string]interface{}{"type": "select", "value": "chain", "values": "chain table"},
|
"display": "inner",
|
||||||
|
}, List: []interface{}{
|
||||||
|
map[string]interface{}{"type": "select", "value": "chain", "values": "block chain table"},
|
||||||
map[string]interface{}{"type": "text", "value": ""},
|
map[string]interface{}{"type": "text", "value": ""},
|
||||||
map[string]interface{}{"type": "button", "value": "执行"},
|
map[string]interface{}{"type": "button", "value": "生成"},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Option("render", "raw")
|
// 创建类型
|
||||||
var chart Chart
|
var chart Chart
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
case "block":
|
case "block":
|
||||||
@ -41,64 +73,79 @@ var Index = &ice.Context{Name: "wiki", Help: "文档模块",
|
|||||||
chart = &Table{}
|
chart = &Table{}
|
||||||
}
|
}
|
||||||
arg[1] = strings.TrimSpace(arg[1])
|
arg[1] = strings.TrimSpace(arg[1])
|
||||||
|
arg[2] = strings.TrimSpace(arg[2])
|
||||||
|
|
||||||
chart.Init(m, arg[1:]...)
|
// 构造数据
|
||||||
m.Echo(`<svg vertion="1.1" xmlns="http://www.w3.org/2000/svg" width="%d", height="%d" style="%s">`,
|
m.Option(ice.WEB_TMPL, "raw")
|
||||||
chart.GetWidth(), chart.GetHeight(), m.Option("style"))
|
m.Option("name", arg[1])
|
||||||
m.Echo("\n")
|
m.Option("text", arg[2])
|
||||||
|
chart.Init(m, arg[2:]...)
|
||||||
|
m.Option("width", chart.GetWidth())
|
||||||
|
m.Option("height", chart.GetHeight())
|
||||||
|
|
||||||
|
// 生成网页
|
||||||
|
m.Render(m.Conf("chart", ice.Meta("prefix")))
|
||||||
chart.Draw(m, 0, 0)
|
chart.Draw(m, 0, 0)
|
||||||
m.Echo(`</svg>`)
|
m.Render(m.Conf("chart", ice.Meta("suffix")))
|
||||||
m.Echo("\n")
|
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
|
||||||
"_tree": {Name: "_tree", Help: "目录", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
"_text": {Name: "_text file", Help: "文章", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||||
m.Cmdy("nfs.dir", m.Conf("note", "meta.path"), kit.Select("", arg, 0), "time size line path")
|
m.Option(ice.WEB_TMPL, "raw")
|
||||||
}},
|
|
||||||
"_text": {Name: "_text", Help: "文章", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
|
||||||
tmpl := m.Target().Server().(*web.WEB).HandleCGI(m, path.Join(m.Conf("note", "meta.path"), arg[0]))
|
|
||||||
m.Optionv("title", map[string]int{})
|
m.Optionv("title", map[string]int{})
|
||||||
|
|
||||||
|
// 生成文章
|
||||||
buffer := bytes.NewBuffer([]byte{})
|
buffer := bytes.NewBuffer([]byte{})
|
||||||
|
f := m.Target().Server().(*web.Frame)
|
||||||
|
tmpl := f.HandleCGI(m, m.Confm("note", ice.Meta("alias")), path.Join(m.Conf("note", ice.Meta("path")), arg[0]))
|
||||||
m.Assert(tmpl.ExecuteTemplate(buffer, m.Option("filename", path.Base(arg[0])), m))
|
m.Assert(tmpl.ExecuteTemplate(buffer, m.Option("filename", path.Base(arg[0])), m))
|
||||||
|
|
||||||
if f, p, e := kit.Create(path.Join("var/tmp/file", arg[0])); e == nil {
|
// 缓存文章
|
||||||
|
if f, p, e := kit.Create(path.Join(m.Conf("note", ice.Meta("temp")), arg[0])); e == nil {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
if n, e := f.Write(buffer.Bytes()); e == nil {
|
if n, e := f.Write(buffer.Bytes()); e == nil {
|
||||||
m.Log("info", "save %d %v", n, p)
|
m.Log("info", "save %d %v", n, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data := markdown.ToHTML(buffer.Bytes(), nil, nil)
|
// 生成网页
|
||||||
m.Echo(string(data))
|
m.Echo(string(markdown.ToHTML(buffer.Bytes(), nil, nil)))
|
||||||
}},
|
}},
|
||||||
"note": {Name: "note file|favor|commit", Help: "笔记", Meta: map[string]interface{}{
|
"_tree": {Name: "_tree path", Help: "文库", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||||
"display": "inner",
|
m.Cmdy("nfs.dir", m.Conf("note", ice.Meta("path")),
|
||||||
"remote": "true",
|
kit.Select("", arg, 0), m.Conf("note", ice.Meta("head")))
|
||||||
|
}},
|
||||||
|
"note": {Name: "note file", Help: "笔记", Meta: map[string]interface{}{
|
||||||
|
"remote": "true", "display": "inner",
|
||||||
}, List: []interface{}{
|
}, List: []interface{}{
|
||||||
map[string]interface{}{"type": "text", "value": "miss.md", "name": "path"},
|
map[string]interface{}{"type": "text", "value": "miss.md", "name": "path"},
|
||||||
map[string]interface{}{"type": "button", "value": "执行", "action": "auto"},
|
map[string]interface{}{"type": "button", "value": "执行", "action": "auto"},
|
||||||
map[string]interface{}{"type": "button", "value": "返回", "cb": "Last"},
|
map[string]interface{}{"type": "button", "value": "返回", "cb": "Last"},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||||
if len(arg) == 0 {
|
m.Cmdy(kit.Select("_tree", "_text", len(arg) > 0 && strings.HasSuffix(arg[0], ".md")), arg)
|
||||||
m.Cmdy("_tree")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch arg[0] {
|
|
||||||
case "favor", "commit":
|
|
||||||
m.Cmdy("story", arg[0], arg[1:])
|
|
||||||
default:
|
|
||||||
m.Cmdy(kit.Select("_tree", "_text", strings.HasSuffix(arg[0], ".md")), arg[0])
|
|
||||||
}
|
|
||||||
}},
|
}},
|
||||||
|
|
||||||
"title": {Name: "title text", Help: "一级标题", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"title": {Name: "title text", Help: "标题", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
title, _ := m.Optionv("title").(map[string]int)
|
||||||
|
switch arg[0] {
|
||||||
|
case "section":
|
||||||
|
arg = arg[1:]
|
||||||
|
title["section"]++
|
||||||
|
m.Option("prefix", fmt.Sprintf("%d.%d ", title["chapter"], title["section"]))
|
||||||
|
case "chapter":
|
||||||
|
arg = arg[1:]
|
||||||
|
title["chapter"]++
|
||||||
|
title["section"] = 0
|
||||||
|
m.Option("prefix", fmt.Sprintf("%d ", title["chapter"]))
|
||||||
|
default:
|
||||||
|
m.Option("prefix", "")
|
||||||
|
}
|
||||||
|
|
||||||
ns := strings.Split(m.Conf("runtime", "node.name"), "-")
|
ns := strings.Split(m.Conf("runtime", "node.name"), "-")
|
||||||
m.Option("render", cmd)
|
m.Option("content", kit.Select(ns[len(ns)-1], arg, 0))
|
||||||
m.Echo(kit.Select(ns[len(ns)-1], arg, 0))
|
m.Render(m.Conf("title", ice.Meta("title")))
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { web.Index.Register(Index, &web.WEB{}) }
|
func init() { web.Index.Register(Index, &web.Frame{}) }
|
||||||
|
@ -1,31 +1,50 @@
|
|||||||
# {{title "hello world"}}
|
# {{title "hello world"}}
|
||||||
|
|
||||||
init.register
|
{{table "项目" `
|
||||||
ice.Begin
|
volcano iceberg
|
||||||
ice.Start
|
context toolkit
|
||||||
ice.Close
|
preload appframe
|
||||||
|
`}}
|
||||||
|
|
||||||
{{chart "table" `
|
## {{chapter "hello world"}}
|
||||||
|
|
||||||
|
{{table "框架" `
|
||||||
ctx cli aaa web
|
ctx cli aaa web
|
||||||
lex yac gdb log
|
lex yac gdb log
|
||||||
tcp nfs ssh mdb
|
tcp nfs ssh mdb
|
||||||
`}}
|
`}}
|
||||||
|
|
||||||
{{chart "chain" `
|
### {{section "hello world"}}
|
||||||
|
|
||||||
|
{{chain "孵化" `
|
||||||
context
|
context
|
||||||
volcanos
|
volcanos
|
||||||
proto.js
|
proto.js
|
||||||
frame.js
|
frame.js bg blue
|
||||||
|
Page
|
||||||
|
Pane
|
||||||
|
Plugin
|
||||||
|
Inputs
|
||||||
|
Output
|
||||||
order.js
|
order.js
|
||||||
style.css
|
|
||||||
index.html
|
|
||||||
icebergs bg blue
|
icebergs bg blue
|
||||||
web.go
|
type.go
|
||||||
aaa.go
|
base.go bg red
|
||||||
cli.go
|
code
|
||||||
ctx.go
|
wiki
|
||||||
|
chat
|
||||||
|
team
|
||||||
|
mall
|
||||||
|
conf.go
|
||||||
toolkits
|
toolkits
|
||||||
type.go
|
type.go
|
||||||
core.go
|
core.go bg blue
|
||||||
|
Split
|
||||||
|
Parse
|
||||||
|
Value
|
||||||
|
Fetch
|
||||||
|
Favor
|
||||||
misc.go
|
misc.go
|
||||||
`}}
|
`}}
|
||||||
|
|
||||||
|
### {{section "hello world"}}
|
||||||
|
170
type.go
170
type.go
@ -505,11 +505,18 @@ func (m *Message) Table(cbs ...interface{}) *Message {
|
|||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Option(key string, arg ...interface{}) string {
|
func (m *Message) Render(str string) *Message {
|
||||||
return kit.Select("", kit.Simple(m.Optionv(key, arg...)), 0)
|
if res, err := kit.Render(str, m); m.Assert(err) {
|
||||||
|
m.Echo(string(res))
|
||||||
|
}
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Options(key string, arg ...interface{}) bool {
|
|
||||||
return kit.Select("", kit.Simple(m.Optionv(key, arg...)), 0) != ""
|
func (m *Message) Detail(arg ...interface{}) string {
|
||||||
|
return kit.Select("", m.meta[MSG_DETAIL], 0)
|
||||||
|
}
|
||||||
|
func (m *Message) Detailv(arg ...interface{}) []string {
|
||||||
|
return m.meta[MSG_DETAIL]
|
||||||
}
|
}
|
||||||
func (m *Message) Optionv(key string, arg ...interface{}) interface{} {
|
func (m *Message) Optionv(key string, arg ...interface{}) interface{} {
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
@ -537,6 +544,12 @@ func (m *Message) Optionv(key string, arg ...interface{}) interface{} {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (m *Message) Options(key string, arg ...interface{}) bool {
|
||||||
|
return kit.Select("", kit.Simple(m.Optionv(key, arg...)), 0) != ""
|
||||||
|
}
|
||||||
|
func (m *Message) Option(key string, arg ...interface{}) string {
|
||||||
|
return kit.Select("", kit.Simple(m.Optionv(key, arg...)), 0)
|
||||||
|
}
|
||||||
func (m *Message) Append(key string, arg ...interface{}) string {
|
func (m *Message) Append(key string, arg ...interface{}) string {
|
||||||
return kit.Select("", m.meta[key], 0)
|
return kit.Select("", m.meta[key], 0)
|
||||||
}
|
}
|
||||||
@ -549,12 +562,6 @@ func (m *Message) Resultv(arg ...interface{}) []string {
|
|||||||
func (m *Message) Result(arg ...interface{}) string {
|
func (m *Message) Result(arg ...interface{}) string {
|
||||||
return strings.Join(m.Resultv(), "")
|
return strings.Join(m.Resultv(), "")
|
||||||
}
|
}
|
||||||
func (m *Message) Detailv(arg ...interface{}) []string {
|
|
||||||
return m.meta[MSG_DETAIL]
|
|
||||||
}
|
|
||||||
func (m *Message) Detail(arg ...interface{}) string {
|
|
||||||
return kit.Select("", m.meta[MSG_DETAIL], 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Message) Log(level string, str string, arg ...interface{}) *Message {
|
func (m *Message) Log(level string, str string, arg ...interface{}) *Message {
|
||||||
if Log != nil {
|
if Log != nil {
|
||||||
@ -609,76 +616,6 @@ func (m *Message) TryCatch(msg *Message, safe bool, hand ...func(msg *Message))
|
|||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Travel(cb interface{}) *Message {
|
|
||||||
list := []*Context{m.target}
|
|
||||||
for i := 0; i < len(list); i++ {
|
|
||||||
switch cb := cb.(type) {
|
|
||||||
case func(*Context, *Context):
|
|
||||||
cb(list[i].context, list[i])
|
|
||||||
case func(*Context, *Context, string, *Command):
|
|
||||||
ls := []string{}
|
|
||||||
for k := range list[i].Commands {
|
|
||||||
ls = append(ls, k)
|
|
||||||
}
|
|
||||||
sort.Strings(ls)
|
|
||||||
for _, k := range ls {
|
|
||||||
cb(list[i].context, list[i], k, list[i].Commands[k])
|
|
||||||
}
|
|
||||||
case func(*Context, *Context, string, *Config):
|
|
||||||
ls := []string{}
|
|
||||||
for k := range list[i].Configs {
|
|
||||||
ls = append(ls, k)
|
|
||||||
}
|
|
||||||
sort.Strings(ls)
|
|
||||||
for _, k := range ls {
|
|
||||||
cb(list[i].context, list[i], k, list[i].Configs[k])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ls := []string{}
|
|
||||||
for k := range list[i].contexts {
|
|
||||||
ls = append(ls, k)
|
|
||||||
}
|
|
||||||
sort.Strings(ls)
|
|
||||||
for _, k := range ls {
|
|
||||||
list = append(list, list[i].contexts[k])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
func (m *Message) Search(key interface{}, cb func(p *Context, s *Context, key string)) *Message {
|
|
||||||
switch key := key.(type) {
|
|
||||||
case string:
|
|
||||||
if k, ok := Alias[key]; ok {
|
|
||||||
key = k
|
|
||||||
}
|
|
||||||
fmt.Printf("%v fuck %v\n", m.Time(), key)
|
|
||||||
|
|
||||||
if strings.Contains(key, ":") {
|
|
||||||
|
|
||||||
} else if strings.Contains(key, ".") {
|
|
||||||
list := strings.Split(key, ".")
|
|
||||||
|
|
||||||
p := m.target.root
|
|
||||||
for _, v := range list[:len(list)-1] {
|
|
||||||
if s, ok := p.contexts[v]; ok {
|
|
||||||
p = s
|
|
||||||
} else {
|
|
||||||
p = nil
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if p == nil {
|
|
||||||
m.Log(LOG_WARN, "not found %s", key)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
cb(p.context, p, list[len(list)-1])
|
|
||||||
} else {
|
|
||||||
cb(m.target.context, m.target, key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
func (m *Message) Gos(msg *Message, cb func(*Message)) *Message {
|
func (m *Message) Gos(msg *Message, cb func(*Message)) *Message {
|
||||||
go func() { msg.TryCatch(msg, true, func(msg *Message) { cb(msg) }) }()
|
go func() { msg.TryCatch(msg, true, func(msg *Message) { cb(msg) }) }()
|
||||||
return m
|
return m
|
||||||
@ -730,6 +667,79 @@ func (m *Message) Back(sub *Message) *Message {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Message) Travel(cb interface{}) *Message {
|
||||||
|
list := []*Context{m.target}
|
||||||
|
for i := 0; i < len(list); i++ {
|
||||||
|
switch cb := cb.(type) {
|
||||||
|
case func(*Context, *Context):
|
||||||
|
cb(list[i].context, list[i])
|
||||||
|
case func(*Context, *Context, string, *Command):
|
||||||
|
ls := []string{}
|
||||||
|
for k := range list[i].Commands {
|
||||||
|
ls = append(ls, k)
|
||||||
|
}
|
||||||
|
sort.Strings(ls)
|
||||||
|
for _, k := range ls {
|
||||||
|
cb(list[i].context, list[i], k, list[i].Commands[k])
|
||||||
|
}
|
||||||
|
case func(*Context, *Context, string, *Config):
|
||||||
|
ls := []string{}
|
||||||
|
for k := range list[i].Configs {
|
||||||
|
ls = append(ls, k)
|
||||||
|
}
|
||||||
|
sort.Strings(ls)
|
||||||
|
for _, k := range ls {
|
||||||
|
cb(list[i].context, list[i], k, list[i].Configs[k])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ls := []string{}
|
||||||
|
for k := range list[i].contexts {
|
||||||
|
ls = append(ls, k)
|
||||||
|
}
|
||||||
|
sort.Strings(ls)
|
||||||
|
for _, k := range ls {
|
||||||
|
list = append(list, list[i].contexts[k])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
func (m *Message) Search(key interface{}, cb func(p *Context, s *Context, key string)) *Message {
|
||||||
|
switch key := key.(type) {
|
||||||
|
case string:
|
||||||
|
if k, ok := Alias[key]; ok {
|
||||||
|
key = k
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(key, ":") {
|
||||||
|
|
||||||
|
} else if strings.Contains(key, ".") {
|
||||||
|
list := strings.Split(key, ".")
|
||||||
|
|
||||||
|
p := m.target.root
|
||||||
|
for _, v := range list[:len(list)-1] {
|
||||||
|
if s, ok := p.contexts[v]; ok {
|
||||||
|
p = s
|
||||||
|
} else {
|
||||||
|
p = nil
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if p == nil {
|
||||||
|
m.Log(LOG_WARN, "not found %s", key)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
cb(p.context, p, list[len(list)-1])
|
||||||
|
} else {
|
||||||
|
cb(m.target.context, m.target, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func Meta(arg ...interface{}) string {
|
||||||
|
return MDB_META + "." + kit.Keys(arg...)
|
||||||
|
}
|
||||||
func (m *Message) Rich(key string, args interface{}, data interface{}) map[string]interface{} {
|
func (m *Message) Rich(key string, args interface{}, data interface{}) map[string]interface{} {
|
||||||
cache := m.Confm(key, args)
|
cache := m.Confm(key, args)
|
||||||
if cache == nil {
|
if cache == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user