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

add gdb.event

This commit is contained in:
shaoying 2019-12-20 05:03:38 +08:00
parent e31594f131
commit 8e432deab6
17 changed files with 222 additions and 132 deletions

20
base.go
View File

@ -30,7 +30,7 @@ func (f *Frame) Begin(m *Message, arg ...string) Server {
return f
}
func (f *Frame) Start(m *Message, arg ...string) bool {
m.Cmd("_init").Cmd("init", arg)
m.Cmd(ICE_INIT).Cmd("init", arg)
return true
}
func (f *Frame) Close(m *Message, arg ...string) bool {
@ -48,8 +48,8 @@ func (f *Frame) Close(m *Message, arg ...string) bool {
var Index = &Context{Name: "ice", Help: "冰山模块",
Caches: map[string]*Cache{
"status": {Value: "begin"},
"stream": {Value: "shy"},
CTX_STATUS: {Value: "begin"},
CTX_STREAM: {Value: "shy"},
},
Configs: map[string]*Config{
"table": {Name: "数据缓存", Value: map[string]interface{}{
@ -76,10 +76,10 @@ var Index = &Context{Name: "ice", Help: "冰山模块",
}},
},
Commands: map[string]*Command{
"_init": {Name: "_init", Help: "hello", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
ICE_INIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
m.Travel(func(p *Context, s *Context) {
if _, ok := s.Commands["_init"]; ok && p != nil {
m.Spawns(s).Runs("_init", "_init", arg...)
if _, ok := s.Commands[ICE_INIT]; ok && p != nil {
m.Spawns(s).Runs(ICE_INIT, ICE_INIT, arg...)
}
})
}},
@ -95,13 +95,13 @@ var Index = &Context{Name: "ice", Help: "冰山模块",
"exit": {Name: "exit", Help: "hello", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
f := m.root.target.server.(*Frame)
f.code = kit.Int(kit.Select("0", arg, 0))
m.root.Cmd("_exit")
m.root.Cmd(ICE_EXIT)
}},
"_exit": {Name: "_init", Help: "hello", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
ICE_EXIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
m.root.Travel(func(p *Context, s *Context) {
if _, ok := s.Commands["_exit"]; ok && p != nil {
if _, ok := s.Commands[ICE_EXIT]; ok && p != nil {
m.TryCatch(m.Spawns(s), true, func(msg *Message) {
msg.Runs("_exit", "_exit", arg...)
msg.Runs(ICE_EXIT, ICE_EXIT, arg...)
})
}
})

View File

@ -9,29 +9,29 @@ var Index = &ice.Context{Name: "aaa", Help: "认证模块",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
"role": {Name: "role", Help: "角色", Value: map[string]interface{}{
"meta": map[string]interface{}{},
"hash": map[string]interface{}{
ice.MDB_META: map[string]interface{}{},
ice.MDB_HASH: map[string]interface{}{
"root": map[string]interface{}{},
"tech": map[string]interface{}{},
"void": map[string]interface{}{},
},
"list": map[string]interface{}{},
ice.MDB_LIST: map[string]interface{}{},
}},
"user": {Name: "user", Help: "用户", Value: map[string]interface{}{
"meta": map[string]interface{}{},
"hash": map[string]interface{}{},
"list": map[string]interface{}{},
ice.MDB_META: map[string]interface{}{},
ice.MDB_HASH: map[string]interface{}{},
ice.MDB_LIST: map[string]interface{}{},
}},
"sess": {Name: "sess", Help: "会话", Value: map[string]interface{}{
"meta": map[string]interface{}{"expire": "720h"},
"hash": map[string]interface{}{},
"list": map[string]interface{}{},
ice.MDB_META: map[string]interface{}{"expire": "720h"},
ice.MDB_HASH: map[string]interface{}{},
ice.MDB_LIST: map[string]interface{}{},
}},
},
Commands: map[string]*ice.Command{
"_init": {Name: "_init", Help: "加载", 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) {
}},
"_exit": {Name: "_exit", Help: "加载", 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) {
}},
"role": {Name: "role", Help: "角色", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
@ -52,7 +52,7 @@ var Index = &ice.Context{Name: "aaa", Help: "认证模块",
break
}
sessid := kit.Format(user["sessid"])
sessid := kit.Format(user[ice.WEB_SESS])
if sessid == "" {
sessid = m.Cmdx("aaa.sess", "login", arg[1])
}
@ -61,7 +61,7 @@ var Index = &ice.Context{Name: "aaa", Help: "认证模块",
"create_time": m.Time(),
"remote_ip": m.Option("remote_ip"),
"username": arg[1],
"sessid": sessid,
ice.WEB_SESS: sessid,
})
// 登录成功
m.Echo(sessid)

View File

@ -24,7 +24,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
}},
},
Commands: map[string]*ice.Command{
"_init": {Name: "_init", Help: "hello", 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.Cmd("ctx.config", "load", "var/conf/cli.json")
m.Conf("runtime", "host.GOARCH", runtime.GOARCH)
@ -45,7 +45,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
m.Conf("runtime", "node.name", m.Conf("runtime", "boot.pathname"))
m.Log("info", "runtime %v", kit.Formats(m.Confv("runtime")))
}},
"_exit": {Name: "_exit", Help: "hello", 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.Cmd("ctx.config", "save", "var/conf/cli.json", "cli.runtime")
}},
"runtime": {Name: "runtime", Help: "hello", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {

View File

@ -21,8 +21,8 @@ var Index = &ice.Context{Name: "ctx", Help: "元始模块",
m.Push("ups", "shy")
}
m.Push("name", s.Name)
m.Push("status", s.Cap("status"))
m.Push("stream", s.Cap("stream"))
m.Push(ice.CTX_STATUS, s.Cap(ice.CTX_STATUS))
m.Push(ice.CTX_STREAM, s.Cap(ice.CTX_STREAM))
m.Push("help", s.Help)
})
}},

View File

@ -11,36 +11,58 @@ import (
)
type Frame struct {
p chan os.Signal
s chan os.Signal
t <-chan time.Time
d chan []string
}
func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server {
return &Frame{}
}
func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
f.p = make(chan os.Signal, 10)
return f
}
func (f *Frame) Start(m *ice.Message, arg ...string) bool {
m.Cap("stream", m.Conf("timer", "meta.tick"))
tick := time.Tick(kit.Duration(m.Conf("timer", "meta.tick")))
for {
select {
case sig, ok := <-f.p:
case s, ok := <-f.s:
if !ok {
return true
}
m.Log("info", "signal %v", sig)
m.Cmd(m.Confv("signal", kit.Format(sig)))
case now, _ := <-tick:
stamp := int(now.Unix())
m.Confm("timer", "hash", func(key string, value map[string]interface{}) {
m.Log(ice.LOG_INFO, "signal %v", s)
m.Cmd(m.Confv(ice.GDB_SIGNAL, kit.Keys(ice.MDB_HASH, s)))
m.Grow(ice.GDB_SIGNAL, nil, map[string]interface{}{
"create_time": m.Time(), "signal": kit.Format(s),
"cmd": m.Confv(ice.GDB_SIGNAL, kit.Format(s)),
})
case t, ok := <-f.t:
if !ok {
return true
}
break
stamp := int(t.Unix())
m.Confm(ice.GDB_TIMER, ice.MDB_HASH, func(key string, value map[string]interface{}) {
if kit.Int(value["next"]) <= stamp {
m.Log("info", "timer %v %v", key, value["next"])
m.Cmd(value["cmd"])
m.Log(ice.LOG_INFO, "timer %v %v", key, value["next"])
value["next"] = stamp + int(kit.Duration(value["interval"]))/int(time.Second)
m.Cmd(value["cmd"])
m.Grow(ice.GDB_TIMER, nil, map[string]interface{}{
"create_time": kit.Format(t), "interval": value["interval"],
"cmd": value["cmd"], "key": key,
})
}
})
case d, ok := <-f.d:
if !ok {
return true
}
m.Log(ice.LOG_INFO, "event %v", d)
m.Confm(ice.GDB_EVENT, kit.Keys(ice.MDB_HASH, d[0], d[1], ice.MDB_HASH), func(key string, value map[string]interface{}) {
m.Log(ice.LOG_INFO, "event %v %v", key, value)
m.Cmd(value["cmd"], d[2:])
})
}
}
return true
@ -49,59 +71,83 @@ func (f *Frame) Close(m *ice.Message, arg ...string) bool {
return true
}
var Index = &ice.Context{Name: "gdb", Help: "调试模块",
var Index = &ice.Context{Name: "gdb", Help: "事件模块",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
"logpid": &ice.Config{Name: "logpid", Value: "var/run/shy.pid", Help: ""},
"signal": &ice.Config{Name: "signal", Value: map[string]interface{}{
"2": []interface{}{"exit"},
"3": []interface{}{"exit", "1"},
"15": []interface{}{"exit", "1"},
"30": []interface{}{"exit"},
"31": []interface{}{"exit", "1"},
"28": "WINCH",
}, Help: "信号"},
"timer": {Name: "定时器", Value: map[string]interface{}{
"meta": map[string]interface{}{
ice.GDB_SIGNAL: {Name: "signal", Help: "信号器", Value: map[string]interface{}{
ice.MDB_META: map[string]interface{}{
"pid": "var/run/shy.pid",
},
ice.MDB_HASH: map[string]interface{}{
"2": []interface{}{"exit"},
"3": []interface{}{"exit", "1"},
"15": []interface{}{"exit", "1"},
"30": []interface{}{"exit"},
"31": []interface{}{"exit", "1"},
"28": "WINCH",
},
ice.MDB_LIST: map[string]interface{}{},
}},
ice.GDB_TIMER: {Name: "timer", Help: "定时器", Value: map[string]interface{}{
ice.MDB_META: map[string]interface{}{
"tick": "100ms",
},
"hash": map[string]interface{}{},
"list": map[string]interface{}{},
ice.MDB_HASH: map[string]interface{}{},
ice.MDB_LIST: map[string]interface{}{},
}},
ice.GDB_EVENT: {Name: "event", Help: "触发器", Value: map[string]interface{}{
ice.MDB_META: map[string]interface{}{},
ice.MDB_HASH: map[string]interface{}{},
ice.MDB_LIST: map[string]interface{}{},
}},
},
Commands: map[string]*ice.Command{
"_init": {Name: "_init", Help: "hello", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, p, e := kit.Create(m.Conf("logpid")); m.Assert(e) {
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, p, e := kit.Create(m.Conf(ice.GDB_SIGNAL, kit.Keys(ice.MDB_META, "pid"))); m.Assert(e) {
defer f.Close()
f.WriteString(kit.Format(os.Getpid()))
m.Log("info", "pid %d %s", os.Getpid(), p)
m.Log("info", "pid %d: %s", os.Getpid(), p)
}
f := m.Target().Server().(*Frame)
m.Confm("signal", nil, func(sig string, action string) {
m.Log("signal", "add %s: %s", sig, action)
signal.Notify(f.p, syscall.Signal(kit.Int(sig)))
})
if f, ok := m.Target().Server().(*Frame); ok {
f.s = make(chan os.Signal, ice.ICE_CHAN)
m.Confm(ice.GDB_SIGNAL, ice.MDB_HASH, func(sig string, action string) {
m.Log(ice.GDB_SIGNAL, "add %s: %s", sig, action)
signal.Notify(f.s, syscall.Signal(kit.Int(sig)))
})
f.t = time.Tick(kit.Duration(m.Cap(ice.CTX_STREAM, m.Conf(ice.GDB_TIMER, kit.Keys(ice.MDB_META, "tick")))))
f.d = make(chan []string, ice.ICE_CHAN)
}
}},
"_exit": {Name: "_exit", Help: "hello", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
f := m.Target().Server().(*Frame)
close(f.p)
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, ok := m.Target().Server().(*Frame); ok {
close(f.s)
close(f.d)
}
}},
"timer": {Name: "timer", Help: "hello", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
ice.GDB_SIGNAL: {Name: "signal", Help: "信号器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Conf(ice.GDB_SIGNAL, kit.Keys(ice.MDB_META, arg[0]), arg[1:])
}},
ice.GDB_TIMER: {Name: "timer", Help: "定时器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "start":
h := kit.ShortKey(m.Confm("timer", "hash"), 6)
next := time.Now().Add(kit.Duration(arg[1])).Unix()
m.Conf("timer", "hash."+h, map[string]interface{}{
"interval": arg[1],
"next": next,
"cmd": arg[2:],
m.Rich(ice.GDB_TIMER, nil, map[string]interface{}{
"next": time.Now().Add(kit.Duration(arg[1])).Unix(),
"interval": arg[1], "cmd": arg[2:],
})
m.Echo(h)
case "stop":
m.Conf("timer", "hash."+arg[1], "")
}
}},
ice.GDB_EVENT: {Name: "event", Help: "触发器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "listen":
m.Rich(ice.GDB_EVENT, kit.Keys(ice.MDB_HASH, arg[1], arg[2]), map[string]interface{}{
"create_time": m.Time(), "cmd": arg[3:],
})
case "action":
if f, ok := m.Target().Server().(*Frame); ok {
f.d <- arg[1:]
}
}
}},
},

View File

@ -72,16 +72,16 @@ var Index = &ice.Context{Name: "log", Help: "日志模块",
}, Help: "信号"},
},
Commands: map[string]*ice.Command{
"_init": {Name: "_init", Help: "hello", 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.Confm("file", nil, func(key string, value map[string]interface{}) {
if f, p, e := kit.Create(kit.Format(value["path"])); m.Assert(e) {
m.Cap("stream", path.Base(p))
m.Cap(ice.CTX_STREAM, path.Base(p))
m.Log("info", "log %s %s", key, p)
value["file"] = f
}
})
}},
"_exit": {Name: "_exit", Help: "hello", 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) {
f := m.Target().Server().(*Frame)
ice.Log = nil
close(f.p)

View File

@ -134,7 +134,7 @@ var Index = &ice.Context{Name: "nfs", Help: "文件模块",
"dir": {Name: "dir", Help: "目录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
rg, _ := regexp.Compile(m.Option("dir_reg"))
dir(m, arg[0], arg[1], 0, false, "both", rg,
strings.Split(kit.Select("time size line path", arg, 2), " "), "2006-01-02 15:04:05")
strings.Split(kit.Select("time size line path", arg, 2), " "), ice.ICE_TIME)
}},
},
}

View File

@ -24,7 +24,7 @@ func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
func (f *Frame) Start(m *ice.Message, arg ...string) bool {
f.in = os.Stdin
f.out = os.Stdout
m.Cap("stream", "stdio")
m.Cap(ice.CTX_STREAM, "stdio")
prompt := "%d[15:04:05]%s> "
target := m.Target()
@ -60,10 +60,10 @@ var Index = &ice.Context{Name: "ssh", Help: "终端模块",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{},
Commands: map[string]*ice.Command{
"_init": {Name: "_init", Help: "hello", 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)
}},
"_exit": {Name: "_exit", Help: "hello", 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) {
f := m.Target().Server().(*Frame)
f.in.Close()
m.Done()

View File

@ -178,7 +178,7 @@ func (web *WEB) HandleCmd(m *ice.Message, key string, cmd *ice.Command) {
}
for k, v := range r.Form {
for _, v := range v {
msg.Add("option", k, v)
msg.Add(ice.MSG_OPTION, k, v)
}
}
@ -196,7 +196,7 @@ func (web *WEB) HandleCmd(m *ice.Message, key string, cmd *ice.Command) {
case map[string]interface{}:
for k, v := range d {
for _, v := range kit.Simple(v) {
msg.Add("option", k, v)
msg.Add(ice.MSG_OPTION, k, v)
}
}
}
@ -336,20 +336,20 @@ var Index = &ice.Context{Name: "web", Help: "网页模块",
"type": m.Option("node"),
"name": m.Option("name"),
}
m.Confv("space", []string{"hash", h}, meta)
m.Confv("space", []string{ice.MDB_HASH, h}, meta)
m.Log("space", "conn %v %v", h, kit.Formats(m.Confv("space")))
web := m.Target().Server().(*WEB)
m.Gos(m, func(m *ice.Message) {
web.HandleWSS(m, false, s)
m.Log("space", "close %v %v", h, kit.Formats(m.Confv("space")))
m.Confv("space", []string{"hash", h}, "")
m.Confv("space", []string{ice.MDB_HASH, h}, "")
})
}
}},
"space": &ice.Command{Name: "space", Help: "", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 {
m.Conf("space", "hash", func(key string, value map[string]interface{}) {
m.Conf("space", ice.MDB_HASH, func(key string, value map[string]interface{}) {
m.Push(key, value)
})
return

22
conf.go
View File

@ -1,34 +1,36 @@
package ice
const (
ICE_CHAN = 10
ICE_INIT = "_init"
ICE_EXIT = "_exit"
ICE_DATE = "2006-01-02"
ICE_TIME = "2006-01-02 15:04:05"
)
const (
CTX_STATUS = "status"
CTX_STREAM = "stream"
)
const (
MSG_DETAIL = "detail"
MSG_OPTION = "option"
MSG_APPEND = "append"
MSG_RESULT = "result"
)
const (
MDB_META = "meta"
MDB_LIST = "hash"
MDB_HASH = "list"
MDB_LIST = "list"
MDB_HASH = "hash"
)
const (
GDB_SIGNAL = "signal"
GDB_TIMER = "timer"
GDB_EVENT = "event"
)
const (
WEB_PORT = ":9020"
WEB_SESS = "sessid"
)
const (
LOG_CMD = "cmd"
LOG_INFO = "info"
@ -40,3 +42,9 @@ const (
LOG_BENCH = "bench"
LOG_CLOSE = "close"
)
var Alias = map[string]string{
GDB_SIGNAL: "gdb.signal",
GDB_TIMER: "gdb.timer",
GDB_EVENT: "gdb.event",
}

View File

@ -110,14 +110,14 @@ var Index = &ice.Context{Name: "chat", Help: "聊天模块",
if len(arg) == 0 {
m.Confm("group", ice.MDB_HASH, func(key string, value map[string]interface{}) {
m.Push("key", key)
m.Push("name", kit.Value(value["meta"], "name"))
m.Push("name", kit.Value(value[ice.MDB_META], "name"))
})
return
}
}},
"/action": {Name: "/action", Help: "hello", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 2 {
m.Set("option")
m.Set(ice.MSG_OPTION)
m.Confm("group", "hash."+arg[0]+".tool.hash."+arg[1]+".list", func(index int, value map[string]interface{}) {
m.Push("river", arg[0])
m.Push("storm", arg[1])
@ -143,7 +143,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天模块",
"/storm": {Name: "/storm", Help: "hello", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) < 2 {
m.Confm("group", "hash."+arg[0]+".tool.hash", func(key string, value map[string]interface{}) {
m.Push("key", key).Push("count", len(value["list"].([]interface{})))
m.Push("key", key).Push("count", len(value[ice.MDB_LIST].([]interface{})))
})
return
}

View File

@ -55,6 +55,9 @@ var Index = &ice.Context{Name: "code", Help: "编程模块",
}},
},
Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(ice.GDB_EVENT, "listen", "miss", "start", "web.code.docker", "image")
}},
"tmux": {Name: "tmux [session [window [pane cmd]]]", Help: "窗口", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
prefix := kit.Simple(m.Confv("prefix", "tmux"))
if len(arg) > 1 {
@ -211,7 +214,7 @@ var Index = &ice.Context{Name: "code", Help: "编程模块",
if arg[0] != "" && kit.IndexOf(m.Appendv("session"), arg[0]) == -1 {
m.Cmdy(prefix, "new-session", "-ds", arg[0])
}
m.Set("append").Set("result")
m.Set(ice.MSG_APPEND).Set(ice.MSG_RESULT)
// 查看窗口
if m.Cmdy(prefix, "list-windows", "-t", arg[0], "-F", "#{window_id},#{window_active},#{window_name},#{window_panes},#{window_height},#{window_width}",
@ -223,7 +226,7 @@ var Index = &ice.Context{Name: "code", Help: "编程模块",
if arg[1] != "" && kit.IndexOf(m.Appendv("window"), arg[1]) == -1 {
m.Cmdy(prefix, "new-window", "-dt", arg[0], "-n", arg[1])
}
m.Set("append").Set("result")
m.Set(ice.MSG_APPEND).Set(ice.MSG_RESULT)
// 查看面板
if len(arg) == 2 {
@ -446,7 +449,7 @@ var Index = &ice.Context{Name: "code", Help: "编程模块",
if total {
if count++; i == 1 {
if t, e := time.Parse("2006-01-02", hs[0]); e == nil {
if t, e := time.Parse(ice.ICE_DATE, hs[0]); e == nil {
total_day = time.Now().Sub(t)
m.Append("from", hs[0])
}

View File

@ -1,4 +1,4 @@
package team
package mall
import (
"github.com/shylinux/toolkits"
@ -12,16 +12,16 @@ import (
"strings"
)
var Index = &ice.Context{Name: "team", Help: "团队模块",
var Index = &ice.Context{Name: "mall", Help: "团队模块",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
"miss": {Value: map[string]interface{}{
"meta": map[string]interface{}{
ice.MDB_META: map[string]interface{}{
"path": "usr/local/work",
"cmd": []interface{}{"cli.system", "sh", "ice.sh", "start", "web.space", "connect"},
},
"list": map[string]interface{}{},
"hash": map[string]interface{}{},
ice.MDB_LIST: map[string]interface{}{},
ice.MDB_HASH: map[string]interface{}{},
}},
},
Commands: map[string]*ice.Command{
@ -76,7 +76,7 @@ var Index = &ice.Context{Name: "team", Help: "团队模块",
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
switch arg[0] {
case "create":
meta := m.Grow("web.chat.group", []string{"hash", m.Option("sess.river"), "task"}, map[string]interface{}{
meta := m.Grow("web.chat.group", []string{ice.MDB_HASH, m.Option("sess.river"), "task"}, map[string]interface{}{
"name": arg[1],
"text": kit.Select("", arg, 2),
"status": "准备",

View File

@ -1,4 +1,4 @@
package mall
package team
import (
"github.com/shylinux/toolkits"
@ -12,16 +12,16 @@ import (
"strings"
)
var Index = &ice.Context{Name: "mall", Help: "商场模块",
var Index = &ice.Context{Name: "team", Help: "团队模块",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
"miss": {Value: map[string]interface{}{
"meta": map[string]interface{}{
ice.MDB_META: map[string]interface{}{
"path": "usr/local/work",
"cmd": []interface{}{"cli.system", "sh", "ice.sh", "start", "web.space", "connect"},
},
"list": map[string]interface{}{},
"hash": map[string]interface{}{},
ice.MDB_LIST: map[string]interface{}{},
ice.MDB_HASH: map[string]interface{}{},
}},
},
Commands: map[string]*ice.Command{
@ -38,6 +38,7 @@ var Index = &ice.Context{Name: "mall", Help: "商场模块",
case "启动":
case "停止":
m.Cmd("web.space", arg[0], "exit", "1")
m.Cmd(ice.GDB_EVENT, "action", "miss", "stop", arg[0])
return
}
}
@ -55,6 +56,7 @@ var Index = &ice.Context{Name: "mall", Help: "商场模块",
if !m.Confs("web.space", "hash."+arg[0]) {
m.Option("cmd_dir", p)
m.Option("cmd_type", "daemon")
m.Cmd(ice.GDB_EVENT, "action", "miss", "start", arg[0])
m.Cmd(m.Confv("miss", "meta.cmd"))
}
}

View File

@ -150,14 +150,14 @@ func (b *Chain) show(m *ice.Message, str string) (res []string) {
// 输出节点
word := kit.Split(line)
res = append(res, "{", "meta", "{", "text")
res = append(res, "{", ice.MDB_META, "{", "text")
res = append(res, word...)
res = append(res, "}", "list", "[")
res = append(res, "}", ice.MDB_LIST, "[")
}
return
}
func (b *Chain) size(m *ice.Message, root map[string]interface{}, depth int, width map[int]int) int {
meta := root["meta"].(map[string]interface{})
meta := root[ice.MDB_META].(map[string]interface{})
// 最大宽度
text := kit.Format(meta["text"])
@ -167,8 +167,8 @@ func (b *Chain) size(m *ice.Message, root map[string]interface{}, depth int, wid
// 计算高度
height := 0
if list, ok := root["list"].([]interface{}); ok && len(list) > 0 {
kit.Fetch(root["list"], func(index int, value map[string]interface{}) {
if list, ok := root[ice.MDB_LIST].([]interface{}); ok && len(list) > 0 {
kit.Fetch(root[ice.MDB_LIST], func(index int, value map[string]interface{}) {
height += b.size(m, value, depth+1, width)
})
} else {
@ -179,7 +179,7 @@ func (b *Chain) size(m *ice.Message, root map[string]interface{}, depth int, wid
return height
}
func (b *Chain) draw(m *ice.Message, root map[string]interface{}, depth int, width map[int]int, x, y int, p *Block) Chart {
meta := root["meta"].(map[string]interface{})
meta := root[ice.MDB_META].(map[string]interface{})
b.Width, b.Height = 0, 0
// 当前节点
@ -193,11 +193,11 @@ func (b *Chain) draw(m *ice.Message, root map[string]interface{}, depth int, wid
Width: b.GetWidth(strings.Repeat(" ", width[depth])),
}
block.Data(root["meta"])
block.Data(root[ice.MDB_META])
block.Init(m, kit.Format(meta["text"])).Draw(m, x, y+(kit.Int(meta["height"])-1)*b.GetHeights()/2)
// 递归节点
kit.Fetch(root["list"], func(index int, value map[string]interface{}) {
kit.Fetch(root[ice.MDB_LIST], func(index int, value map[string]interface{}) {
b.draw(m, value, depth+1, width, x+b.GetWidths(strings.Repeat(" ", width[depth])), y, block)
y += kit.Int(kit.Value(value, "meta.height")) * b.GetHeights()
})

View File

@ -17,11 +17,11 @@ var Index = &ice.Context{Name: "wiki", Help: "文档模块",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
"note": {Name: "note", Value: map[string]interface{}{
"meta": map[string]interface{}{
ice.MDB_META: map[string]interface{}{
"path": "usr/local/wiki",
},
"list": map[string]interface{}{},
"hash": map[string]interface{}{},
ice.MDB_LIST: map[string]interface{}{},
ice.MDB_HASH: map[string]interface{}{},
}},
},
Commands: map[string]*ice.Command{

49
type.go
View File

@ -649,6 +649,11 @@ func (m *Message) Travel(cb interface{}) *Message {
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, ".") {
@ -725,16 +730,42 @@ func (m *Message) Back(sub *Message) *Message {
return m
}
func (m *Message) Rich(key string, args interface{}, data interface{}) map[string]interface{} {
cache := m.Confm(key, args)
if cache == nil {
cache = map[string]interface{}{}
}
meta, ok := cache[MDB_META].(map[string]interface{})
if !ok {
meta = map[string]interface{}{}
}
hash, ok := cache[MDB_HASH].(map[string]interface{})
if !ok {
hash = map[string]interface{}{}
}
h := kit.ShortKey(hash, 6)
hash[h] = data
cache[MDB_HASH] = hash
cache[MDB_META] = meta
if args == nil {
m.Conf(key, cache)
} else {
m.Conf(key, args, cache)
}
return meta
}
func (m *Message) Grow(key string, args interface{}, data interface{}) map[string]interface{} {
cache := m.Confm(key, args)
if cache == nil {
cache = map[string]interface{}{}
}
meta, ok := cache["meta"].(map[string]interface{})
meta, ok := cache[MDB_META].(map[string]interface{})
if !ok {
meta = map[string]interface{}{}
}
list, _ := cache["list"].([]interface{})
list, _ := cache[MDB_LIST].([]interface{})
// 添加数据
list = append(list, data)
@ -809,8 +840,8 @@ func (m *Message) Grow(key string, args interface{}, data interface{}) map[strin
}
// 更新数据
cache["meta"] = meta
cache["list"] = list
cache[MDB_LIST] = list
cache[MDB_META] = meta
if args == nil {
m.Conf(key, cache)
} else {
@ -823,11 +854,11 @@ func (m *Message) Grows(key string, args interface{}, cb interface{}) map[string
if cache == nil {
return nil
}
meta, ok := cache["meta"].(map[string]interface{})
meta, ok := cache[MDB_META].(map[string]interface{})
if !ok {
return nil
}
list, ok := cache["list"].([]interface{})
list, ok := cache[MDB_LIST].([]interface{})
if !ok {
return nil
}
@ -937,12 +968,12 @@ func (m *Message) Cmd(arg ...interface{}) *Message {
if cmd, ok := c.Commands[key]; ok {
m.TryCatch(m.Spawns(s), true, func(msg *Message) {
msg.Log(LOG_CMD, "%s.%s %v", c.Name, key, list[1:])
msg.meta[MSG_DETAIL] = list
cmd.Hand(msg, c, key, list[1:]...)
msg.Hand = true
m.Hand = true
m = msg
msg.Log(LOG_CMD, "%s.%s %v", c.Name, key, list[1:])
msg.meta[MSG_DETAIL] = list
cmd.Hand(msg, c, key, list[1:]...)
})
break
}