diff --git a/base/aaa/aaa.go b/base/aaa/aaa.go
index 4c2897be..d7e6c418 100644
--- a/base/aaa/aaa.go
+++ b/base/aaa/aaa.go
@@ -22,12 +22,12 @@ const (
)
var Index = &ice.Context{Name: "aaa", Help: "认证模块", Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Rich(ROLE, nil, kit.Dict(kit.MDB_NAME, TECH, Black, kit.Dict(), White, kit.Dict()))
m.Rich(ROLE, nil, kit.Dict(kit.MDB_NAME, VOID, White, kit.Dict(), Black, kit.Dict()))
m.Load()
}},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save(ROLE, USER, SESS)
}},
}}
diff --git a/base/aaa/user.go b/base/aaa/user.go
index 850ee56a..625ded2f 100644
--- a/base/aaa/user.go
+++ b/base/aaa/user.go
@@ -3,6 +3,7 @@ package aaa
import (
"github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/gdb"
"github.com/shylinux/toolkits"
"strings"
@@ -31,7 +32,7 @@ func _user_create(m *ice.Message, name, word string) {
USERNICK, name, USERNODE, cli.NodeName,
))
m.Log_CREATE(USERNAME, name)
- m.Event(ice.USER_CREATE, name)
+ m.Event(gdb.USER_CREATE, name)
}
func UserRoot(m *ice.Message) {
diff --git a/base/cli/cli.go b/base/cli/cli.go
index 8032735a..13fa5732 100644
--- a/base/cli/cli.go
+++ b/base/cli/cli.go
@@ -2,6 +2,7 @@ package cli
import (
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/ctx"
kit "github.com/shylinux/toolkits"
"os"
@@ -25,8 +26,8 @@ var PathName = ""
var NodeName = ""
func NodeType(m *ice.Message, kind, name string) {
- m.Conf(ice.CLI_RUNTIME, "node.type", kind)
- m.Conf(ice.CLI_RUNTIME, "node.name", name)
+ m.Conf(RUNTIME, "node.type", kind)
+ m.Conf(RUNTIME, "node.name", name)
NodeName = name
}
@@ -35,7 +36,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
RUNTIME: {Name: "runtime", Help: "运行环境", Value: kit.Dict()},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
// 启动配置
@@ -75,7 +76,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
// 节点信息
m.Conf(RUNTIME, "node.time", m.Time())
- m.Conf(RUNTIME, "node.type", ice.WEB_WORKER)
+ m.Conf(RUNTIME, "node.type", "worker")
m.Conf(RUNTIME, "node.name", m.Conf(RUNTIME, "boot.pathname"))
m.Info("runtime %v", kit.Formats(m.Confv(RUNTIME)))
@@ -84,7 +85,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
PathName = m.Conf(RUNTIME, "boot.pathname")
NodeName = m.Conf(RUNTIME, "node.nodename")
}},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save(RUNTIME, SYSTEM)
}},
@@ -95,7 +96,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
m.Conf(RUNTIME, "boot.hostname", arg[1])
m.Echo(m.Conf(RUNTIME, "boot.hostname"))
default:
- m.Cmdy(ice.CTX_CONFIG, RUNTIME, arg)
+ m.Cmdy(ctx.CONFIG, RUNTIME, arg)
}
}},
},
diff --git a/base/cli/daemon.go b/base/cli/daemon.go
index 95c37cdb..44d43a5b 100644
--- a/base/cli/daemon.go
+++ b/base/cli/daemon.go
@@ -33,7 +33,7 @@ func _daemon_show(m *ice.Message, cmd *exec.Cmd, out, err string) {
}
h := m.Rich(DAEMON, nil, kit.Dict(
- kit.MDB_TYPE, ice.TYPE_SHELL, kit.MDB_NAME, cmd.Process.Pid, kit.MDB_TEXT, strings.Join(cmd.Args, " "),
+ kit.MDB_TYPE, "shell", kit.MDB_NAME, cmd.Process.Pid, kit.MDB_TEXT, strings.Join(cmd.Args, " "),
kit.MDB_EXTRA, kit.Dict(
kit.MDB_STATUS, StatusStart,
CMD_STDOUT, out,
diff --git a/base/cli/system.go b/base/cli/system.go
index 63363b6d..78e7d66f 100644
--- a/base/cli/system.go
+++ b/base/cli/system.go
@@ -60,7 +60,7 @@ func init() {
if cmd.Dir = m.Option(CMD_DIR); len(cmd.Dir) > 0 {
m.Log_EXPORT(kit.MDB_META, SYSTEM, CMD_DIR, cmd.Dir)
if _, e := os.Stat(cmd.Dir); e != nil && os.IsNotExist(e) {
- os.MkdirAll(cmd.Dir, ice.DIR_MOD)
+ os.MkdirAll(cmd.Dir, ice.MOD_DIR)
}
}
diff --git a/base/ctx/conf.go b/base/ctx/conf.go
index 57e9911b..e720a835 100644
--- a/base/ctx/conf.go
+++ b/base/ctx/conf.go
@@ -25,7 +25,7 @@ func _config_list(m *ice.Message, all bool) {
func _config_save(m *ice.Message, name string, arg ...string) {
msg := m.Spawn(m.Source())
// 保存配置
- name = path.Join(msg.Conf(ice.CTX_CONFIG, "meta.path"), name)
+ name = path.Join(msg.Conf(CONFIG, "meta.path"), name)
if f, p, e := kit.Create(name); m.Assert(e) {
data := map[string]interface{}{}
for _, k := range arg {
@@ -42,7 +42,7 @@ func _config_save(m *ice.Message, name string, arg ...string) {
func _config_load(m *ice.Message, name string, arg ...string) {
msg := m.Spawn(m.Source())
// 加载配置
- name = path.Join(msg.Conf(ice.CTX_CONFIG, "meta.path"), name)
+ name = path.Join(msg.Conf(CONFIG, "meta.path"), name)
if f, e := os.Open(name); e == nil {
data := map[string]interface{}{}
json.NewDecoder(f).Decode(&data)
@@ -80,13 +80,19 @@ func _config_grow(m *ice.Message, name string, key string, arg ...string) {
m.Grow(name, key, kit.Dict(arg))
}
+const (
+ CONTEXT = "context"
+ COMMAND = "command"
+ CONFIG = "config"
+)
+
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
CONFIG: {Name: "config", Help: "配置", Value: kit.Data("path", "var/conf")},
},
Commands: map[string]*ice.Command{
- ice.CTX_CONFIG: {Name: "config [all] [chain [key [arg...]]]", Help: "配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ CONFIG: {Name: "config [all] [chain [key [arg...]]]", Help: "配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if all, arg := _parse_arg_all(m, arg...); len(arg) == 0 {
_config_list(m, all)
return
diff --git a/base/ctx/ctx.go b/base/ctx/ctx.go
index d1c41a53..06f9b0c7 100644
--- a/base/ctx/ctx.go
+++ b/base/ctx/ctx.go
@@ -5,12 +5,6 @@ import (
"github.com/shylinux/toolkits"
)
-const (
- CONTEXT = "context"
- COMMAND = "command"
- CONFIG = "config"
-)
-
func _parse_arg_all(m *ice.Message, arg ...string) (bool, []string) {
if len(arg) > 0 && arg[0] == "all" {
return true, arg[1:]
diff --git a/base/gdb/gdb.go b/base/gdb/gdb.go
index bf4fbe0b..eb2be19b 100644
--- a/base/gdb/gdb.go
+++ b/base/gdb/gdb.go
@@ -2,6 +2,8 @@ package gdb
import (
"github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/toolkits"
"os"
@@ -29,21 +31,23 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
if !ok {
return true
}
- // m.Log(ice.LOG_SIGNAL, "%v: %v", s, m.Confv(ice.GDB_SIGNAL, kit.Keys(kit.MDB_HASH, s)))
- m.Cmd(m.Confv(ice.GDB_SIGNAL, kit.Keys(kit.MDB_HASH, s)), kit.Keys(s))
+ // 信号事件
+ m.Logs(EVENT, SIGNAL, s)
+ m.Cmd(m.Confv(SIGNAL, kit.Keys(kit.MDB_HASH, s)), kit.Keys(s))
case t, ok := <-f.t:
if !ok {
return true
}
- break
+
+ // 定时事件
stamp := int(t.Unix())
- m.Confm(ice.GDB_TIMER, kit.MDB_HASH, func(key string, value map[string]interface{}) {
+ m.Confm(TIMER, kit.MDB_HASH, func(key string, value map[string]interface{}) {
if kit.Int(value["next"]) <= stamp {
- m.Log(ice.LOG_INFO, "timer %v %v", key, value["next"])
+ m.Logs(EVENT, TIMER, key, kit.MDB_TIME, 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{}{
+ m.Grow(TIMER, nil, map[string]interface{}{
"create_time": kit.Format(t), "interval": value["interval"],
"cmd": value["cmd"], "key": key,
})
@@ -54,8 +58,9 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
if !ok {
return true
}
- m.Log(ice.LOG_EVENTS, "%s: %v", d[0], d[1:])
- m.Grows(ice.GDB_EVENT, d[0], "", "", func(index int, value map[string]interface{}) {
+ // 异步事件
+ m.Logs(EVENT, d[0], d[1:])
+ m.Grows(EVENT, d[0], "", "", func(index int, value map[string]interface{}) {
m.Cmd(value["cmd"], d[1:]).Cost("event %v", d)
})
}
@@ -66,46 +71,71 @@ func (f *Frame) Close(m *ice.Message, arg ...string) bool {
return true
}
+const (
+ SIGNAL = "signal"
+ TIMER = "timer"
+ EVENT = "event"
+)
+
+const (
+ LISTEN = "listen"
+ ACTION = "action"
+)
+const (
+ SYSTEM_INIT = "system.init"
+
+ SERVE_START = "serve.start"
+ SERVE_CLOSE = "serve.close"
+ SPACE_START = "space.start"
+ SPACE_CLOSE = "space.close"
+ DREAM_START = "dream.start"
+ DREAM_CLOSE = "dream.close"
+
+ USER_CREATE = "user.create"
+ CHAT_CREATE = "chat.create"
+ MISS_CREATE = "miss.create"
+ MIND_CREATE = "mind.create"
+)
+
var Index = &ice.Context{Name: "gdb", Help: "事件模块",
- Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
- ice.GDB_SIGNAL: {Name: "signal", Help: "信号器", Value: kit.Dict(
+ SIGNAL: {Name: "signal", Help: "信号器", Value: kit.Dict(
kit.MDB_META, kit.Dict("pid", "var/run/ice.pid"),
kit.MDB_LIST, kit.List(),
kit.MDB_HASH, kit.Dict(
"2", []interface{}{"exit", "0"},
"3", []interface{}{"exit", "1"},
"15", []interface{}{"exit", "1"},
- "20", []interface{}{},
+ // "20", []interface{}{"void"},
"30", []interface{}{"exit"},
"31", []interface{}{"exit", "1"},
- "28", "WINCH",
+ // "28", []interface{}{"void"},
),
)},
- ice.GDB_TIMER: {Name: "timer", Help: "定时器", Value: kit.Data("tick", "100ms")},
- ice.GDB_EVENT: {Name: "event", Help: "触发器", Value: kit.Data()},
+ TIMER: {Name: "timer", Help: "定时器", Value: kit.Data("tick", "100ms")},
+ EVENT: {Name: "event", Help: "触发器", Value: kit.Data()},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if os.Getenv("ctx_mod") != "" {
- m.Cmd("nfs.save", kit.Select(m.Conf(ice.GDB_SIGNAL, "meta.pid"),
- m.Conf(ice.CLI_RUNTIME, "conf.ctx_pid")), m.Conf(ice.CLI_RUNTIME, "host.pid"))
+ m.Cmd(nfs.SAVE, kit.Select(m.Conf(SIGNAL, "meta.pid"),
+ m.Conf(cli.RUNTIME, "conf.ctx_pid")), m.Conf(cli.RUNTIME, "host.pid"))
}
// 进程标识
if f, ok := m.Target().Server().(*Frame); ok {
// 注册信号
- f.s = make(chan os.Signal, ice.ICE_CHAN)
- m.Richs(ice.GDB_SIGNAL, nil, "*", func(key string, value string) {
- m.Log(ice.LOG_LISTEN, "%s: %s", key, value)
+ f.s = make(chan os.Signal, ice.MOD_CHAN)
+ m.Richs(SIGNAL, nil, "*", func(key string, value string) {
+ m.Logs(LISTEN, key, "cmd", value)
signal.Notify(f.s, syscall.Signal(kit.Int(key)))
})
// 启动心跳
- f.t = time.Tick(kit.Duration(m.Cap(ice.CTX_STREAM, m.Conf(ice.GDB_TIMER, "meta.tick"))))
+ f.t = time.Tick(kit.Duration(m.Cap(ice.CTX_STREAM, m.Conf(TIMER, "meta.tick"))))
// 分发事件
- f.d = make(chan []string, ice.ICE_CHAN)
+ f.d = make(chan []string, ice.MOD_CHAN)
}
}},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, ok := m.Target().Server().(*Frame); ok {
// 停止心跳
close(f.s)
@@ -114,36 +144,35 @@ var Index = &ice.Context{Name: "gdb", Help: "事件模块",
}
}},
- ice.GDB_SIGNAL: {Name: "signal", Help: "信号器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- switch arg[0] {
- case "listen":
- // 监听信号
- m.Rich(ice.GDB_SIGNAL, 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 "repeat":
- // 周期命令
- m.Rich(ice.GDB_TIMER, nil, kit.Dict(
- "next", time.Now().Add(kit.Duration(arg[1])).Unix(),
+ SIGNAL: {Name: "signal", Help: "信号器", Action: map[string]*ice.Action{
+ LISTEN: {Name: "listen signal cmd...", Help: "监听事件", Hand: func(m *ice.Message, arg ...string) {
+ m.Rich(SIGNAL, arg[0], arg[1:])
+ }},
+ }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
+
+ TIMER: {Name: "timer", Help: "定时器", Action: map[string]*ice.Action{
+ LISTEN: {Name: "listen delay interval cmd...", Help: "监听事件", Hand: func(m *ice.Message, arg ...string) {
+ m.Rich(TIMER, nil, kit.Dict(
+ "next", time.Now().Add(kit.Duration(arg[0])).Unix(),
"interval", arg[1], "cmd", arg[2:],
))
- }
- }},
- ice.GDB_EVENT: {Name: "event", Help: "触发器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- switch arg[0] {
- case "listen":
- // 监听事件
- m.Grow(ice.GDB_EVENT, arg[1], kit.Dict("cmd", arg[2:]))
- m.Log(ice.LOG_LISTEN, "%s: %v", arg[1], arg[2:])
- case "action":
- // 触发事件
+ }},
+ }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
+
+ EVENT: {Name: "event", Help: "触发器", Action: map[string]*ice.Action{
+ LISTEN: {Name: "listen event cmd...", Help: "监听事件", Hand: func(m *ice.Message, arg ...string) {
+ m.Grow(EVENT, arg[0], kit.Dict("cmd", arg[1:]))
+ m.Logs(LISTEN, arg[0], "cmd", arg[1:])
+ }},
+ ACTION: {Name: "action event arg...", Help: "触发事件", Hand: func(m *ice.Message, arg ...string) {
if f, ok := m.Target().Server().(*Frame); ok {
- f.d <- arg[1:]
+ m.Logs(ACTION, arg[0], "arg", arg[1:])
+ f.d <- arg
}
- }
- }},
+ }},
+ }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
+
+ "void": {Name: "void", Help: "空命令", Action: map[string]*ice.Action{}},
},
}
diff --git a/base/log/log.go b/base/log/log.go
index 5fa4a5c4..34b7bee3 100644
--- a/base/log/log.go
+++ b/base/log/log.go
@@ -63,8 +63,12 @@ func (f *Frame) Close(m *ice.Message, arg ...string) bool {
return true
}
+const (
+ ERROR = "error"
+ TRACE = "trace"
+)
+
var Index = &ice.Context{Name: "log", Help: "日志模块",
- Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
"file": &ice.Config{Name: "file", Help: "日志文件", Value: kit.Dict(
"watch", kit.Dict("path", "var/log/watch.log"),
@@ -114,7 +118,7 @@ var Index = &ice.Context{Name: "log", Help: "日志模块",
)},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if os.Getenv("ctx_mod") != "" {
m.Confm("file", nil, func(key string, value map[string]interface{}) {
// 日志文件
@@ -126,7 +130,7 @@ var Index = &ice.Context{Name: "log", Help: "日志模块",
})
}
}},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, ok := m.Target().Server().(*Frame); ok {
// 关闭日志
ice.Log = nil
diff --git a/base/mdb/mdb.go b/base/mdb/mdb.go
index 263cd9c5..0edccf22 100644
--- a/base/mdb/mdb.go
+++ b/base/mdb/mdb.go
@@ -195,8 +195,8 @@ const (
var Index = &ice.Context{Name: "mdb", Help: "数据模块",
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {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) {}},
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
IMPORT: {Name: "import conf key type file", Help: "导入数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[2] {
diff --git a/base/nfs/nfs.go b/base/nfs/nfs.go
index ae4cb8fa..aed51bfc 100644
--- a/base/nfs/nfs.go
+++ b/base/nfs/nfs.go
@@ -3,7 +3,6 @@ package nfs
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli"
- "github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
"bufio"
@@ -54,7 +53,7 @@ func _file_list(m *ice.Message, root string, name string, level int, deep bool,
for _, field := range fields {
switch field {
case "time":
- m.Push("time", f.ModTime().Format(ice.ICE_TIME))
+ m.Push("time", f.ModTime().Format(ice.MOD_TIME))
case "type":
if m.Assert(e) && f.IsDir() {
m.Push("type", "dir")
@@ -197,7 +196,7 @@ func _file_trash(m *ice.Message, name string, from ...string) {
os.MkdirAll(path.Dir(p), 0777)
os.Rename(name, p)
- m.Cmd(web.FAVOR, "trash", "bin", name, p)
+ m.Cmd("web.favor", "trash", "bin", name, p)
}
}
}
@@ -241,4 +240,4 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
},
}
-func init() { ice.Index.Register(Index, nil) }
+func init() { ice.Index.Register(Index, nil, DIR, CAT, SAVE, COPY, LINK, TRASH) }
diff --git a/base/nfs/search.go b/base/nfs/search.go
index f69e0aef..4b60d474 100644
--- a/base/nfs/search.go
+++ b/base/nfs/search.go
@@ -39,11 +39,16 @@ func travel(m *ice.Message, root string, name string, cb func(name string)) {
}
}
+const (
+ SEARCH = "search"
+ COMMEND = "commend"
+)
+
func init() {
Index.Register(&ice.Context{Name: "search", Help: "搜索",
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Cmd(ice.APP_SEARCH, "add", "dir", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Cmd(SEARCH, "add", "dir", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "set":
m.Cmdy("nfs.dir", arg[5])
@@ -58,14 +63,14 @@ func init() {
m.Push("engine", "dir")
m.Push("favor", "file")
m.Push("id", kit.FmtSize(s.Size()))
- m.Push("time", s.ModTime().Format(ice.ICE_TIME))
+ m.Push("time", s.ModTime().Format(ice.MOD_TIME))
m.Push("type", strings.TrimPrefix(path.Ext(name), "."))
m.Push("name", path.Base(name))
m.Push("text", name)
}
})
}}))
- m.Cmd(ice.APP_COMMEND, "add", "dir", "base", m.AddCmd(&ice.Command{Name: "commend word", Help: "推荐引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Cmd(COMMEND, "add", "dir", "base", m.AddCmd(&ice.Command{Name: "commend word", Help: "推荐引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "set":
m.Cmdy("nfs.dir", arg[5])
@@ -74,8 +79,8 @@ func init() {
travel(m, "./", "", func(name string) {
score := 0
- m.Richs(ice.APP_COMMEND, "meta.user", m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
- m.Grows(ice.APP_COMMEND, kit.Keys("meta.user", kit.MDB_HASH, key, "like"), "", "", func(index int, value map[string]interface{}) {
+ m.Richs(COMMEND, "meta.user", m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
+ m.Grows(COMMEND, kit.Keys("meta.user", kit.MDB_HASH, key, "like"), "", "", func(index int, value map[string]interface{}) {
switch kit.Value(value, "extra.engine") {
case "dir":
if value["type"] == strings.TrimPrefix(path.Ext(name), ".") {
diff --git a/base/shy.go b/base/shy.go
index f620ab45..fb8c7435 100644
--- a/base/shy.go
+++ b/base/shy.go
@@ -1,18 +1,3 @@
package shy
-import (
- _ "github.com/shylinux/icebergs/base/aaa"
- _ "github.com/shylinux/icebergs/base/cli"
- _ "github.com/shylinux/icebergs/base/ctx"
- _ "github.com/shylinux/icebergs/base/web"
-
- _ "github.com/shylinux/icebergs/base/gdb"
- _ "github.com/shylinux/icebergs/base/lex"
- _ "github.com/shylinux/icebergs/base/log"
- _ "github.com/shylinux/icebergs/base/yac"
-
- _ "github.com/shylinux/icebergs/base/mdb"
- _ "github.com/shylinux/icebergs/base/nfs"
- _ "github.com/shylinux/icebergs/base/ssh"
- _ "github.com/shylinux/icebergs/base/tcp"
-)
+import ()
diff --git a/base/ssh/ssh.go b/base/ssh/ssh.go
index 76aa8b01..19894769 100644
--- a/base/ssh/ssh.go
+++ b/base/ssh/ssh.go
@@ -54,7 +54,7 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
// 转换结果
res := msg.Result()
if res == "" {
- res = msg.Table().Result()
+ res = msg.Table(nil).Result()
}
args = append(args, "length:", len(res))
@@ -321,8 +321,8 @@ var Index = &ice.Context{Name: "ssh", Help: "终端模块",
REMOTE: {Name: "remote", Help: "远程连接", Value: kit.Data()},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if _, ok := m.Target().Server().(*Frame); ok {
m.Done()
}
diff --git a/base/tcp/tcp.go b/base/tcp/tcp.go
index 98d41467..4464d1df 100644
--- a/base/tcp/tcp.go
+++ b/base/tcp/tcp.go
@@ -2,6 +2,7 @@ package tcp
import (
"github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/aaa"
"github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/toolkits"
@@ -89,8 +90,8 @@ var Index = &ice.Context{Name: "tcp", Help: "通信模块",
)},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(GETPORT) }},
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(GETPORT) }},
"ifconfig": {Name: "ifconfig [name]", Help: "网络配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_ip_list(m, "")
@@ -107,7 +108,7 @@ var Index = &ice.Context{Name: "tcp", Help: "通信模块",
}
}},
"netstat": {Name: "netstat [name]", Help: "网络配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Cmdy(ice.CLI_SYSTEM, "netstat", "-lanp")
+ m.Cmdy(cli.SYSTEM, "netstat", "-lanp")
}},
"check": {Name: "check addr", Help: "server", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@@ -146,8 +147,8 @@ var Index = &ice.Context{Name: "tcp", Help: "通信模块",
switch msg.Cmdx("check", c.RemoteAddr().String()) {
case "local":
// 本机用户
- msg.Option(ice.MSG_USERNAME, msg.Conf(ice.CLI_RUNTIME, "boot.username"))
- msg.Option(ice.MSG_USERROLE, msg.Cmdx(ice.AAA_ROLE, "check", msg.Option(ice.MSG_USERNAME)))
+ msg.Option(ice.MSG_USERNAME, msg.Conf(cli.RUNTIME, "boot.username"))
+ msg.Option(ice.MSG_USERROLE, msg.Cmdx(aaa.ROLE, "check", msg.Option(ice.MSG_USERNAME)))
msg.Logs(ice.LOG_AUTH, "name", msg.Option(ice.MSG_USERNAME), "role", msg.Option(ice.MSG_USERROLE))
}
@@ -159,7 +160,7 @@ var Index = &ice.Context{Name: "tcp", Help: "通信模块",
if len(text) == 0 {
if len(cmds) > 0 {
- msg.Cmd(ice.AAA_ROLE, "right")
+ msg.Cmd(aaa.ROLE, "right")
// 执行命令
res := msg.Cmd(cmds)
diff --git a/base/web/cache.go b/base/web/cache.go
index 2b429b23..03c2dcce 100644
--- a/base/web/cache.go
+++ b/base/web/cache.go
@@ -90,7 +90,7 @@ func _cache_watch(m *ice.Message, key, file string) {
os.Link(kit.Format(value["file"]), file)
}
}) == nil {
- m.Cmdy(ice.WEB_SPIDE, "dev", "cache", "/cache/"+key)
+ m.Cmdy(SPIDE, "dev", "cache", "/cache/"+key)
os.MkdirAll(path.Dir(file), 0777)
os.Remove(file)
os.Link(m.Append("file"), file)
diff --git a/base/web/dream.go b/base/web/dream.go
index 080a4ca7..b23ed442 100644
--- a/base/web/dream.go
+++ b/base/web/dream.go
@@ -2,7 +2,8 @@ package web
import (
ice "github.com/shylinux/icebergs"
- cli "github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/gdb"
kit "github.com/shylinux/toolkits"
"io/ioutil"
@@ -34,7 +35,7 @@ func _dream_show(m *ice.Message, name string) {
p := path.Join(m.Conf(DREAM, "meta.path"), name)
os.MkdirAll(p, 0777)
- if b, e := ioutil.ReadFile(path.Join(p, m.Conf(ice.GDB_SIGNAL, "meta.pid"))); e == nil {
+ if b, e := ioutil.ReadFile(path.Join(p, m.Conf(gdb.SIGNAL, "meta.pid"))); e == nil {
if s, e := os.Stat("/proc/" + string(b)); e == nil && s.IsDir() {
m.Info("already exists %v", string(b))
return
@@ -60,13 +61,13 @@ const DREAM = "dream"
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
- ice.WEB_DREAM: {Name: "dream", Help: "梦想家", Value: kit.Data("path", "usr/local/work",
- // "cmd", []interface{}{ice.CLI_SYSTEM, "ice.sh", "start", ice.WEB_SPACE, "connect"},
- "cmd", []interface{}{ice.CLI_SYSTEM, "ice.bin", ice.WEB_SPACE, "connect"},
+ DREAM: {Name: "dream", Help: "梦想家", Value: kit.Data("path", "usr/local/work",
+ // "cmd", []interface{}{cli.SYSTEM, "ice.sh", "start", ice.WEB_SPACE, "connect"},
+ "cmd", []interface{}{cli.SYSTEM, "ice.bin", SPACE, "connect"},
)},
},
Commands: map[string]*ice.Command{
- ice.WEB_DREAM: {Name: "dream [name] auto", Help: "梦想家", Meta: kit.Dict("detail", []interface{}{"启动", "停止"}), Action: map[string]*ice.Action{
+ DREAM: {Name: "dream [name] auto", Help: "梦想家", Meta: kit.Dict("detail", []interface{}{"启动", "停止"}), Action: map[string]*ice.Action{
"start": {Name: "start", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
_dream_show(m, m.Option(kit.MDB_NAME))
}},
diff --git a/base/web/favor.go b/base/web/favor.go
index 319ad53f..7d9f1978 100644
--- a/base/web/favor.go
+++ b/base/web/favor.go
@@ -31,7 +31,7 @@ func _favor_list(m *ice.Message, zone, id string, fields ...string) {
m.Push("detail", value)
m.Optionv("value", value)
m.Push(kit.MDB_KEY, kit.MDB_RENDER)
- m.Push(kit.MDB_VALUE, m.Cmdx(m.Conf(ice.WEB_FAVOR, kit.Keys(kit.MDB_META, kit.MDB_RENDER, value[kit.MDB_TYPE]))))
+ m.Push(kit.MDB_VALUE, m.Cmdx(m.Conf(FAVOR, kit.Keys(kit.MDB_META, kit.MDB_RENDER, value[kit.MDB_TYPE]))))
})
})
}
@@ -61,14 +61,14 @@ func _favor_sync(m *ice.Message, zone, route, favor string, arg ...string) {
count := kit.Int(kit.Value(val, kit.Keys(kit.MDB_COUNT)))
pull := kit.Int(kit.Value(val, kit.Keys(remote, kit.MDB_PULL)))
- m.Cmd(ice.WEB_SPIDE, route, "msg", "/favor/pull", FAVOR, favor, "begin", pull+1).Table(func(index int, value map[string]string, head []string) {
+ m.Cmd(SPIDE, route, "msg", "/favor/pull", FAVOR, favor, "begin", pull+1).Table(func(index int, value map[string]string, head []string) {
_favor_insert(m, favor, value[kit.MDB_TYPE], value[kit.MDB_NAME], value[kit.MDB_TEXT], value[kit.MDB_EXTRA])
pull = kit.Int(value[kit.MDB_ID])
})
m.Option("cache.limit", count-kit.Int(kit.Value(val, kit.Keys(remote, kit.MDB_PUSH))))
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
- m.Cmd(ice.WEB_SPIDE, route, "msg", "/favor/push", FAVOR, favor,
+ m.Cmd(SPIDE, route, "msg", "/favor/push", FAVOR, favor,
kit.MDB_TYPE, value[kit.MDB_TYPE], kit.MDB_NAME, value[kit.MDB_NAME], kit.MDB_TEXT, value[kit.MDB_TEXT],
kit.MDB_EXTRA, kit.Format(value[kit.MDB_EXTRA]),
)
@@ -98,7 +98,7 @@ func _favor_proxy(m *ice.Message, zone, id string, arg ...string) {
// 分发数据
m.Richs(FAVOR, nil, zone, func(key string, val map[string]interface{}) {
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
- m.Cmdy(ice.WEB_PROXY, p, ice.WEB_FAVOR, zone, kit.MDB_TYPE, value[kit.MDB_TYPE],
+ m.Cmdy(PROXY, p, FAVOR, zone, kit.MDB_TYPE, value[kit.MDB_TYPE],
kit.MDB_NAME, value[kit.MDB_NAME], kit.MDB_TEXT, value[kit.MDB_TEXT],
kit.Format(value[kit.MDB_EXTRA]))
})
@@ -108,7 +108,7 @@ func _favor_proxy(m *ice.Message, zone, id string, arg ...string) {
func _favor_share(m *ice.Message, zone, id string, arg ...string) {
m.Richs(FAVOR, nil, zone, func(key string, val map[string]interface{}) {
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
- m.Cmdy(ice.WEB_SHARE, value[kit.MDB_TYPE], value[kit.MDB_NAME], value[kit.MDB_TYPE], kit.Format(value[kit.MDB_EXTRA]))
+ m.Cmdy(SHARE, value[kit.MDB_TYPE], value[kit.MDB_NAME], value[kit.MDB_TYPE], kit.Format(value[kit.MDB_EXTRA]))
})
})
}
@@ -116,7 +116,7 @@ func _favor_commit(m *ice.Message, zone, id string, arg ...string) {
m.Echo("list: ")
m.Richs(FAVOR, nil, zone, func(key string, val map[string]interface{}) {
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
- m.Cmdy(ice.WEB_STORY, "add", value[kit.MDB_TYPE], value[kit.MDB_NAME], value[kit.MDB_TEXT])
+ m.Cmdy(STORY, "add", value[kit.MDB_TYPE], value[kit.MDB_NAME], value[kit.MDB_TEXT])
})
})
}
@@ -247,6 +247,23 @@ const (
)
const FAVOR = "favor"
+const ( // TYPE
+ TYPE_SPIDE = "spide"
+ TYPE_SPACE = "space"
+ TYPE_STORY = "story"
+
+ TYPE_RIVER = "river"
+ TYPE_STORM = "storm"
+ TYPE_ACTION = "action"
+ TYPE_ACTIVE = "active"
+
+ TYPE_DRIVE = "drive"
+ TYPE_SHELL = "shell"
+ TYPE_VIMRC = "vimrc"
+ TYPE_TABLE = "table"
+ TYPE_INNER = "inner"
+ TYPE_MEDIA = "media"
+)
func init() {
Index.Merge(&ice.Context{
diff --git a/base/web/group.go b/base/web/group.go
index b0601d38..31ae0078 100644
--- a/base/web/group.go
+++ b/base/web/group.go
@@ -5,20 +5,22 @@ import (
kit "github.com/shylinux/toolkits"
)
+const GROUP = "group"
+
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
- ice.WEB_GROUP: {Name: "group", Help: "分组", Value: kit.Data(kit.MDB_SHORT, "group")},
+ GROUP: {Name: "group", Help: "分组", Value: kit.Data(kit.MDB_SHORT, "group")},
},
Commands: map[string]*ice.Command{
- ice.WEB_GROUP: {Name: "group group=auto name=auto auto", Help: "分组", Meta: kit.Dict(
+ GROUP: {Name: "group group=auto name=auto auto", Help: "分组", Meta: kit.Dict(
"exports", []string{"grp", "group"}, "detail", []string{"标签", "添加", "退还"},
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 1 && arg[0] == "action" {
switch arg[1] {
case "label", "标签":
if m.Option(ice.EXPORT_LABEL) != "" && m.Option(cmd) != "" {
- m.Cmdy(ice.WEB_LABEL, m.Option(ice.EXPORT_LABEL), "add", m.Option(cmd), m.Option(kit.MDB_NAME))
+ m.Cmdy(LABEL, m.Option(ice.EXPORT_LABEL), "add", m.Option(cmd), m.Option(kit.MDB_NAME))
m.Option(ice.FIELD_RELOAD, "true")
}
case "add", "添加":
@@ -147,7 +149,7 @@ func init() {
default:
m.Richs(cmd, kit.Keys(kit.MDB_HASH, key), arg[1], func(key string, value map[string]interface{}) {
// 执行命令
- m.Cmdy(ice.WEB_PROXY, value[kit.MDB_NAME], arg[2:])
+ m.Cmdy(PROXY, value[kit.MDB_NAME], arg[2:])
})
}
})
diff --git a/base/web/label.go b/base/web/label.go
index 70eb28fb..ada9a60a 100644
--- a/base/web/label.go
+++ b/base/web/label.go
@@ -85,7 +85,7 @@ func _label_select(m *ice.Message, cmd string, arg ...string) {
}
}
func _label_create(m *ice.Message, cmd string, key string, arg ...string) {
- if pod := m.Cmdx(ice.WEB_GROUP, arg[2], "get", arg[3:]); pod != "" {
+ if pod := m.Cmdx(GROUP, arg[2], "get", arg[3:]); pod != "" {
if m.Richs(cmd, kit.Keys(kit.MDB_HASH, key), pod, func(key string, value map[string]interface{}) {
if value[kit.MDB_STATUS] == "void" {
value[kit.MDB_STATUS] = "free"
@@ -105,7 +105,7 @@ func _label_remove(m *ice.Message, cmd string, key string, arg ...string) {
if value[kit.MDB_STATUS] == "free" {
value[kit.MDB_STATUS] = "void"
m.Logs(ice.LOG_MODIFY, cmd, arg[0], kit.MDB_NAME, arg[3], kit.MDB_STATUS, "void")
- m.Cmdx(ice.WEB_GROUP, value[kit.MDB_GROUP], "put", arg[3])
+ m.Cmdx(GROUP, value[kit.MDB_GROUP], "put", arg[3])
m.Echo(arg[3])
}
})
@@ -116,7 +116,7 @@ func _label_remote(m *ice.Message, cmd string, key string, arg ...string) {
m.Richs(cmd, kit.Keys(kit.MDB_HASH, key), arg[1], func(key string, value map[string]interface{}) {
wg.Add(1)
m.Option(ice.MSG_USERPOD, value[kit.MDB_NAME])
- m.Cmd(ice.WEB_SPACE, value[kit.MDB_NAME], arg[2:]).Call(false, func(res *ice.Message) *ice.Message {
+ m.Cmd(SPACE, value[kit.MDB_NAME], arg[2:]).Call(false, func(res *ice.Message) *ice.Message {
if wg.Done(); res != nil && m != nil {
m.Copy(res)
}
@@ -126,13 +126,15 @@ func _label_remote(m *ice.Message, cmd string, key string, arg ...string) {
wg.Wait()
}
+const LABEL = "label"
+
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
- ice.WEB_LABEL: {Name: "label", Help: "标签", Value: kit.Data(kit.MDB_SHORT, "label")},
+ LABEL: {Name: "label", Help: "标签", Value: kit.Data(kit.MDB_SHORT, "label")},
},
Commands: map[string]*ice.Command{
- ice.WEB_LABEL: {Name: "label label=auto name=auto auto", Help: "标签", Meta: kit.Dict(
+ LABEL: {Name: "label label=auto name=auto auto", Help: "标签", Meta: kit.Dict(
"exports", []string{"lab", "label"}, "detail", []string{"归还"},
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 1 && arg[0] == "action" {
@@ -172,7 +174,7 @@ func init() {
_label_remove(m, cmd, key, arg...)
default: // 远程命令
if arg[0] == "route" {
- m.Cmd(ice.WEB_ROUTE).Table(func(index int, value map[string]string, field []string) {
+ m.Cmd(ROUTE).Table(func(index int, value map[string]string, field []string) {
m.Rich(cmd, kit.Keys(kit.MDB_HASH, key), kit.Dict(
kit.MDB_NAME, value["name"], kit.MDB_GROUP, arg[0], kit.MDB_STATUS, "free",
))
diff --git a/base/web/proxy.go b/base/web/proxy.go
index 28ea2323..8261ab26 100644
--- a/base/web/proxy.go
+++ b/base/web/proxy.go
@@ -5,31 +5,33 @@ import (
kit "github.com/shylinux/toolkits"
)
+const PROXY = "proxy"
+
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
- ice.WEB_PROXY: {Name: "proxy", Help: "代理", Value: kit.Data(kit.MDB_SHORT, "proxy")},
+ PROXY: {Name: "proxy", Help: "代理", Value: kit.Data(kit.MDB_SHORT, "proxy")},
},
Commands: map[string]*ice.Command{
- ice.WEB_PROXY: {Name: "proxy name cmd auto", Help: "代理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ PROXY: {Name: "proxy name cmd auto", Help: "代理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "add":
- m.Rich(ice.WEB_SPACE, nil, kit.Dict(
- kit.MDB_TYPE, ice.WEB_BETTER, kit.MDB_NAME, arg[1], kit.MDB_TEXT, arg[2],
+ m.Rich(SPACE, nil, kit.Dict(
+ kit.MDB_TYPE, BETTER, kit.MDB_NAME, arg[1], kit.MDB_TEXT, arg[2],
))
- m.Conf(ice.WEB_PROXY, kit.Keys("meta.better", arg[1]), arg[2])
+ m.Conf(PROXY, kit.Keys("meta.better", arg[1]), arg[2])
m.Logs(ice.LOG_INSERT, "proxy", arg[1], "cb", arg[2])
return
}
- m.Richs(ice.WEB_SPACE, nil, arg[0], func(key string, value map[string]interface{}) {
- if value[kit.MDB_TYPE] == ice.WEB_BETTER {
- arg[0] = m.Cmdx(m.Conf(ice.WEB_PROXY, kit.Keys("meta.better", arg[0])))
+ m.Richs(SPACE, nil, arg[0], func(key string, value map[string]interface{}) {
+ if value[kit.MDB_TYPE] == BETTER {
+ arg[0] = m.Cmdx(m.Conf(PROXY, kit.Keys("meta.better", arg[0])))
m.Logs(ice.LOG_SELECT, "proxy", value["name"], "space", arg[0])
}
})
- m.Cmdy(ice.WEB_ROUTE, arg[0], arg[1:])
+ m.Cmdy(ROUTE, arg[0], arg[1:])
}},
}}, nil)
}
diff --git a/base/web/route.go b/base/web/route.go
index 753b9eb0..894f5e77 100644
--- a/base/web/route.go
+++ b/base/web/route.go
@@ -2,6 +2,8 @@ package web
import (
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/aaa"
+ "github.com/shylinux/icebergs/base/cli"
kit "github.com/shylinux/toolkits"
"strings"
@@ -18,18 +20,20 @@ func _route_split(arg ...string) (string, string) {
return target, rest
}
+const ROUTE = "route"
+
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
- ice.WEB_ROUTE: {Name: "route", Help: "路由", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
+ ROUTE: {Name: "route", Help: "路由", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
},
Commands: map[string]*ice.Command{
- ice.WEB_ROUTE: {Name: "route name cmd auto", Help: "路由", Meta: kit.Dict("detail", []string{"分组"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ROUTE: {Name: "route name cmd auto", Help: "路由", Meta: kit.Dict("detail", []string{"分组"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 1 && arg[0] == "action" {
switch arg[1] {
case "group", "分组":
if m.Option("grp") != "" && m.Option("name") != "" {
- m.Cmdy(ice.WEB_GROUP, m.Option("grp"), "add", m.Option("name"))
+ m.Cmdy(GROUP, m.Option("grp"), "add", m.Option("name"))
}
}
return
@@ -40,32 +44,32 @@ func init() {
}
target, rest := _route_split(arg...)
- m.Richs(ice.WEB_SPACE, nil, target, func(key string, val map[string]interface{}) {
+ m.Richs(SPACE, nil, target, func(key string, val map[string]interface{}) {
if len(arg) > 1 {
m.Call(false, func(res *ice.Message) *ice.Message { return res })
- ls := []interface{}{ice.WEB_SPACE, val[kit.MDB_NAME]}
+ ls := []interface{}{SPACE, val[kit.MDB_NAME]}
// 发送命令
if rest != "" {
- ls = append(ls, ice.WEB_SPACE, rest)
+ ls = append(ls, SPACE, rest)
}
m.Cmdy(ls, arg[1:])
return
}
switch val[kit.MDB_TYPE] {
- case ice.WEB_SERVER:
- if val[kit.MDB_NAME] == m.Conf(ice.CLI_RUNTIME, "node.name") {
+ case SERVER:
+ if val[kit.MDB_NAME] == m.Conf(cli.RUNTIME, "node.name") {
// 避免循环
return
}
// 远程查询
- m.Cmd(ice.WEB_SPACE, val[kit.MDB_NAME], ice.WEB_ROUTE).Table(func(index int, value map[string]string, head []string) {
+ m.Cmd(SPACE, val[kit.MDB_NAME], ROUTE).Table(func(index int, value map[string]string, head []string) {
m.Push(kit.MDB_TYPE, value[kit.MDB_TYPE])
m.Push(kit.MDB_NAME, kit.Keys(val[kit.MDB_NAME], value[kit.MDB_NAME]))
})
fallthrough
- case ice.WEB_WORKER:
+ case WORKER:
// 本机查询
m.Push(kit.MDB_TYPE, val[kit.MDB_TYPE])
m.Push(kit.MDB_NAME, val[kit.MDB_NAME])
@@ -85,13 +89,13 @@ func init() {
m.Info("username: %v", m.Option(ice.MSG_USERNAME))
break
}
- if m.Option(ice.MSG_SESSID) != "" && m.Cmdx(ice.AAA_SESS, "check", m.Option(ice.MSG_SESSID)) != "" {
+ if m.Option(ice.MSG_SESSID) != "" && m.Cmdx(aaa.SESS, "check", m.Option(ice.MSG_SESSID)) != "" {
m.Info("sessid: %v", m.Option(ice.MSG_SESSID))
break
}
- sessid := m.Cmdx(ice.AAA_SESS, "create", "")
- share := m.Cmdx(ice.WEB_SHARE, "login", m.Option(ice.MSG_USERIP), sessid)
+ sessid := m.Cmdx(aaa.SESS, "create", "")
+ share := m.Cmdx(SHARE, "login", m.Option(ice.MSG_USERIP), sessid)
Render(m, "cookie", sessid)
m.Render(share)
}
diff --git a/base/web/serve.go b/base/web/serve.go
index d58074c4..a7c50c7d 100644
--- a/base/web/serve.go
+++ b/base/web/serve.go
@@ -4,6 +4,7 @@ import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/aaa"
"github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/gdb"
"github.com/shylinux/icebergs/base/tcp"
kit "github.com/shylinux/toolkits"
@@ -33,9 +34,9 @@ func _serve_login(msg *ice.Message, w http.ResponseWriter, r *http.Request) bool
}
}
- if s, ok := msg.Target().Commands[ice.WEB_LOGIN]; ok {
+ if _, ok := msg.Target().Commands[LOGIN]; ok {
// 权限检查
- msg.Target().Run(msg, s, ice.WEB_LOGIN, kit.Simple(msg.Optionv("cmds"))...)
+ msg.Target().Cmd(msg, LOGIN, LOGIN, kit.Simple(msg.Optionv("cmds"))...)
} else if ls := strings.Split(msg.Option(ice.MSG_USERURL), "/"); msg.Conf(SERVE, kit.Keys("meta.black", ls[1])) == "true" {
return false // black
@@ -124,7 +125,7 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
// 执行命令
if cmds := kit.Simple(msg.Optionv("cmds")); _serve_login(msg, w, r) {
msg.Option("_option", msg.Optionv(ice.MSG_OPTION))
- msg.Target().Run(msg, cmd, msg.Option(ice.MSG_USERURL), cmds...)
+ msg.Target().Cmd(msg, key, msg.Option(ice.MSG_USERURL), cmds...)
}
// 渲染引擎
@@ -177,7 +178,7 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
}
m.W = w
Render(m, "refresh", m.Conf(SERVE, "meta.volcanos.refresh"))
- m.Event(ice.SYSTEM_INIT)
+ m.Event(gdb.SYSTEM_INIT)
m.W = nil
} else if r.URL.Path == "/share" && r.Method == "GET" {
http.ServeFile(w, r, m.Conf(SERVE, "meta.page.share"))
@@ -189,10 +190,12 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
const SERVE = "serve"
+const LOGIN = "_login"
+
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
- ice.WEB_SERVE: {Name: "serve", Help: "服务器", Value: kit.Data(
+ SERVE: {Name: "serve", Help: "服务器", Value: kit.Data(
"init", "false", "logheaders", "false",
"black", kit.Dict(),
"white", kit.Dict(
@@ -224,9 +227,9 @@ func init() {
)},
},
Commands: map[string]*ice.Command{
- ice.WEB_SERVE: {Name: "serve [random] [ups...]", Help: "服务器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- if cli.NodeType(m, ice.WEB_SERVER, cli.HostName); len(arg) > 0 && arg[0] == "random" {
- cli.NodeType(m, ice.WEB_SERVER, cli.PathName)
+ SERVE: {Name: "serve [random] [ups...]", Help: "服务器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ if cli.NodeType(m, SERVER, cli.HostName); len(arg) > 0 && arg[0] == "random" {
+ cli.NodeType(m, SERVER, cli.PathName)
// 随机端口
m.Cmd(SPIDE, kit.MDB_CREATE, "self", "http://random")
arg = arg[1:]
@@ -234,12 +237,12 @@ func init() {
// 启动服务
m.Target().Start(m, "self")
- defer m.Cmd(ice.WEB_SPACE, "connect", "self")
+ defer m.Cmd(SPACE, "connect", "self")
m.Sleep("1s")
// 连接服务
for _, k := range arg {
- m.Cmd(ice.WEB_SPACE, "connect", k)
+ m.Cmd(SPACE, "connect", k)
}
}},
}}, nil)
diff --git a/base/web/share.go b/base/web/share.go
index 7b744b55..da6215c3 100644
--- a/base/web/share.go
+++ b/base/web/share.go
@@ -2,6 +2,9 @@ package web
import (
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/aaa"
+ "github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/ctx"
kit "github.com/shylinux/toolkits"
"fmt"
@@ -23,11 +26,11 @@ func _share_list(m *ice.Message, key string, fields ...string) {
m.Push("detail", value)
m.Push(kit.MDB_KEY, kit.MDB_LINK)
- m.Push(kit.MDB_VALUE, fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.link"), m.Conf(ice.WEB_SHARE, "meta.domain"), key, key))
+ m.Push(kit.MDB_VALUE, fmt.Sprintf(m.Conf(SHARE, "meta.template.link"), m.Conf(SHARE, "meta.domain"), key, key))
m.Push(kit.MDB_KEY, kit.MDB_SHARE)
- m.Push(kit.MDB_VALUE, fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.share"), m.Conf(ice.WEB_SHARE, "meta.domain"), key))
+ m.Push(kit.MDB_VALUE, fmt.Sprintf(m.Conf(SHARE, "meta.template.share"), m.Conf(SHARE, "meta.domain"), key))
m.Push(kit.MDB_KEY, kit.MDB_VALUE)
- m.Push(kit.MDB_VALUE, fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.value"), m.Conf(ice.WEB_SHARE, "meta.domain"), key))
+ m.Push(kit.MDB_VALUE, fmt.Sprintf(m.Conf(SHARE, "meta.template.value"), m.Conf(SHARE, "meta.domain"), key))
})
}
func _share_show(m *ice.Message, key string, value map[string]interface{}, arg ...string) bool {
@@ -37,7 +40,7 @@ func _share_show(m *ice.Message, key string, value map[string]interface{}, arg .
kit.MDB_TYPE, SHARE, kit.MDB_NAME, value[kit.MDB_TYPE], kit.MDB_TEXT, key,
)))
case kit.MDB_SHARE, "共享码":
- m.Render(ice.RENDER_QRCODE, kit.Format("%s/share/%s/?share=%s", m.Conf(ice.WEB_SHARE, "meta.domain"), key, key))
+ m.Render(ice.RENDER_QRCODE, kit.Format("%s/share/%s/?share=%s", m.Conf(SHARE, "meta.domain"), key, key))
case kit.MDB_VALUE, "数据值":
m.Render(ice.RENDER_QRCODE, kit.Format(value), kit.Select("256", arg, 1))
case kit.MDB_TEXT:
@@ -45,7 +48,7 @@ func _share_show(m *ice.Message, key string, value map[string]interface{}, arg .
case "detail", "详情":
m.Render(kit.Formats(value))
case "download", "下载":
- if strings.HasPrefix(kit.Format(value["text"]), m.Conf(ice.WEB_CACHE, "meta.path")) {
+ if strings.HasPrefix(kit.Format(value["text"]), m.Conf(CACHE, "meta.path")) {
m.Render(ice.RENDER_DOWNLOAD, value["text"], value["type"], value["name"])
} else {
m.Render("%s", value["text"])
@@ -56,9 +59,9 @@ func _share_show(m *ice.Message, key string, value map[string]interface{}, arg .
return true
}
func _share_repos(m *ice.Message, repos string, arg ...string) {
- prefix := m.Conf(ice.WEB_SERVE, "meta.volcanos.require")
+ prefix := m.Conf(SERVE, "meta.volcanos.require")
if _, e := os.Stat(path.Join(prefix, repos)); e != nil {
- m.Cmd(ice.CLI_SYSTEM, "git", "clone", "https://"+repos, path.Join(prefix, repos))
+ m.Cmd(cli.SYSTEM, "git", "clone", "https://"+repos, path.Join(prefix, repos))
}
m.Render(ice.RENDER_DOWNLOAD, path.Join(prefix, repos, path.Join(arg...)))
}
@@ -66,7 +69,7 @@ func _share_local(m *ice.Message, arg ...string) {
p := path.Join(arg...)
if m.Option("pod") != "" {
// 远程文件
- m.Cmdy(ice.WEB_SPACE, m.Option("pod"), "nfs.cat", p)
+ m.Cmdy(SPACE, m.Option("pod"), "nfs.cat", p)
m.Render(ice.RENDER_RESULT)
return
}
@@ -80,7 +83,7 @@ func _share_local(m *ice.Message, arg ...string) {
m.Render(ice.RENDER_DOWNLOAD, p)
}
func _share_remote(m *ice.Message, pod string, arg ...string) {
- m.Cmdy(ice.WEB_SPACE, pod, "web./publish/", arg)
+ m.Cmdy(SPACE, pod, "web./publish/", arg)
m.Render(ice.RENDER_RESULT)
}
func _share_create(m *ice.Message, kind, name, text string, arg ...string) string {
@@ -89,7 +92,7 @@ func _share_create(m *ice.Message, kind, name, text string, arg ...string) strin
}
h := m.Rich(SHARE, nil, kit.Dict(
- kit.MDB_TIME, m.Time(m.Conf(ice.WEB_SHARE, "meta.expire")),
+ kit.MDB_TIME, m.Time(m.Conf(SHARE, "meta.expire")),
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
kit.MDB_EXTRA, kit.Dict(arg),
))
@@ -105,9 +108,9 @@ func _share_create(m *ice.Message, kind, name, text string, arg ...string) strin
}
func _share_story(m *ice.Message, value map[string]interface{}, arg ...string) map[string]interface{} {
- msg := m.Cmd(ice.WEB_STORY, ice.STORY_INDEX, value["text"])
+ msg := m.Cmd(STORY, INDEX, value["text"])
if msg.Append("text") == "" && kit.Value(value, "extra.pod") != "" {
- msg = m.Cmd(ice.WEB_SPACE, kit.Value(value, "extra.pod"), ice.WEB_STORY, ice.STORY_INDEX, value["text"])
+ msg = m.Cmd(SPACE, kit.Value(value, "extra.pod"), STORY, INDEX, value["text"])
}
value = kit.Dict("type", msg.Append("scene"), "name", msg.Append("story"), "text", msg.Append("text"), "file", msg.Append("file"))
m.Log(ice.LOG_EXPORT, "%s: %v", arg, kit.Format(value))
@@ -140,7 +143,7 @@ func _share_action(m *ice.Message, value map[string]interface{}, arg ...string)
cmds := kit.Simple(m.Space(meta["pod"]), kit.Keys(meta["ctx"], meta["cmd"]), arg[3:])
m.Cmdy(cmds).Option("cmds", cmds)
m.Option("title", value["name"])
- if strings.HasPrefix(kit.Format(value["text"]), m.Conf(ice.WEB_CACHE, "meta.path")) {
+ if strings.HasPrefix(kit.Format(value["text"]), m.Conf(CACHE, "meta.path")) {
m.Render(ice.RENDER_DOWNLOAD, value["text"], value["type"], value["name"])
} else {
m.Render("%s", value["text"])
@@ -158,7 +161,7 @@ func _share_action_redirect(m *ice.Message, value map[string]interface{}, share
return true
}
func _share_action_page(m *ice.Message, value map[string]interface{}) bool {
- Render(m, ice.RENDER_DOWNLOAD, m.Conf(ice.WEB_SERVE, "meta.page.share"))
+ Render(m, ice.RENDER_DOWNLOAD, m.Conf(SERVE, "meta.page.share"))
return true
}
func _share_action_list(m *ice.Message, value map[string]interface{}, river, storm string) bool {
@@ -174,7 +177,7 @@ func _share_action_list(m *ice.Message, value map[string]interface{}, river, sto
m.Push("args", value["args"])
m.Push("value", value["value"])
- msg := m.Cmd(m.Space(value["pod"]), ice.CTX_COMMAND, value["ctx"], value["cmd"])
+ msg := m.Cmd(m.Space(value["pod"]), ctx.COMMAND, value["ctx"], value["cmd"])
m.Push("name", value["cmd"])
m.Push("help", kit.Select(msg.Append("help"), kit.Format(value["help"])))
m.Push("inputs", msg.Append("list"))
@@ -184,19 +187,19 @@ func _share_action_list(m *ice.Message, value map[string]interface{}, river, sto
}
func _share_auth(m *ice.Message, share string, role string) {
- m.Richs(ice.WEB_SHARE, nil, share, func(key string, value map[string]interface{}) {
+ m.Richs(SHARE, nil, share, func(key string, value map[string]interface{}) {
switch value["type"] {
case "active":
- m.Cmdy(ice.WEB_SPACE, value["name"], "sessid", m.Cmdx(ice.AAA_SESS, "create", role))
+ m.Cmdy(SPACE, value["name"], "sessid", m.Cmdx(aaa.SESS, "create", role))
case "user":
- m.Cmdy(ice.AAA_ROLE, role, value["name"])
+ m.Cmdy(aaa.ROLE, role, value["name"])
default:
- m.Cmdy(ice.AAA_SESS, "auth", value["text"], role)
+ m.Cmdy(aaa.SESS, "auth", value["text"], role)
}
})
}
func _share_check(m *ice.Message, share string) {
- m.Richs(ice.WEB_SHARE, nil, share, func(key string, value map[string]interface{}) {
+ m.Richs(SHARE, nil, share, func(key string, value map[string]interface{}) {
m.Render(ice.RENDER_QRCODE, kit.Format(kit.Dict(
kit.MDB_TYPE, "share", kit.MDB_NAME, value["type"], kit.MDB_TEXT, key,
)))
@@ -205,7 +208,7 @@ func _share_check(m *ice.Message, share string) {
func _trash(m *ice.Message, arg ...string) {
switch arg[0] {
case "invite":
- arg = []string{arg[0], m.Cmdx(ice.WEB_SHARE, "invite", kit.Select("tech", arg, 1), kit.Select("miss", arg, 2))}
+ arg = []string{arg[0], m.Cmdx(SHARE, "invite", kit.Select("tech", arg, 1), kit.Select("miss", arg, 2))}
fallthrough
case "check":
_share_check(m, arg[1])
@@ -232,6 +235,7 @@ func init() {
Configs: map[string]*ice.Config{
SHARE: {Name: "share", Help: "共享链", Value: kit.Data(
"template", share_template, "expire", "72h",
+ "limit", 10,
)},
},
Commands: map[string]*ice.Command{
@@ -250,15 +254,15 @@ func init() {
_share_local(m, arg...)
}},
"/share/": {Name: "/share/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Richs(ice.WEB_SHARE, nil, kit.Select(m.Option(kit.MDB_SHARE), arg, 0), func(key string, value map[string]interface{}) {
+ m.Richs(SHARE, nil, kit.Select(m.Option(kit.MDB_SHARE), arg, 0), func(key string, value map[string]interface{}) {
m.Log_EXPORT(kit.MDB_META, SHARE, "arg", arg, "value", kit.Format(value))
- if m.Warn(m.Option(ice.MSG_USERROLE) != ice.ROLE_ROOT && kit.Time(kit.Format(value[kit.MDB_TIME])) < kit.Time(m.Time()), "expired") {
+ if m.Warn(m.Option(ice.MSG_USERROLE) != aaa.ROOT && kit.Time(kit.Format(value[kit.MDB_TIME])) < kit.Time(m.Time()), "expired") {
m.Echo("expired")
return
}
switch value[kit.MDB_TYPE] {
- case ice.TYPE_STORY:
+ case TYPE_STORY:
value = _share_story(m, value, arg...)
}
@@ -267,15 +271,15 @@ func init() {
}
switch value[kit.MDB_TYPE] {
- case ice.TYPE_RIVER:
+ case TYPE_RIVER:
// 共享群组
m.Render("redirect", "/", "share", key, "river", kit.Format(value["text"]))
- case ice.TYPE_STORM:
+ case TYPE_STORM:
// 共享应用
m.Render("redirect", "/", "share", key, "storm", kit.Format(value["text"]), "river", kit.Format(kit.Value(value, "extra.river")))
- case ice.TYPE_ACTION:
+ case TYPE_ACTION:
_share_action(m, value, arg...)
default:
@@ -299,7 +303,7 @@ func init() {
return
}
- p := path.Join(kit.Simple(m.Conf(ice.WEB_SERVE, "meta.publish"), arg)...)
+ p := path.Join(kit.Simple(m.Conf(SERVE, "meta.publish"), arg)...)
if m.W == nil {
m.Cmdy("nfs.cat", p)
return
diff --git a/base/web/space.go b/base/web/space.go
index f7d342c0..9d5a22f9 100644
--- a/base/web/space.go
+++ b/base/web/space.go
@@ -5,6 +5,7 @@ import (
ice "github.com/shylinux/icebergs"
aaa "github.com/shylinux/icebergs/base/aaa"
"github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/gdb"
kit "github.com/shylinux/toolkits"
"github.com/shylinux/toolkits/task"
@@ -57,7 +58,7 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) {
// 连接成功
m.Rich(SPACE, nil, kit.Dict("socket", s,
- kit.MDB_TYPE, ice.WEB_MASTER, kit.MDB_NAME, dev, kit.MDB_TEXT, host,
+ kit.MDB_TYPE, MASTER, kit.MDB_NAME, dev, kit.MDB_TEXT, host,
))
m.Log_CREATE("space", dev, "retry", i, "uri", uri)
@@ -151,7 +152,7 @@ func _space_handle(m *ice.Message, safe bool, send map[string]*ice.Message, c *w
})
continue
}
- } else if msg.Richs(ice.WEB_SPACE, nil, target[0], func(key string, value map[string]interface{}) {
+ } else if msg.Richs(SPACE, nil, target[0], func(key string, value map[string]interface{}) {
// 查询节点
if s, ok := value["socket"].(*websocket.Conn); ok {
socket, source, target = s, source, target[1:]
@@ -184,16 +185,23 @@ func _space_handle(m *ice.Message, safe bool, send map[string]*ice.Message, c *w
const SPACE = "space"
+const (
+ MASTER = "master"
+ SERVER = "server"
+ WORKER = "worker"
+ BETTER = "better"
+)
+
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
- ice.WEB_SPACE: {Name: "space", Help: "空间站", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME,
+ SPACE: {Name: "space", Help: "空间站", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME,
"redial", kit.Dict("a", 3000, "b", 1000, "c", 1000, "r", 4096, "w", 4096),
"timeout", kit.Dict("c", "180s"),
)},
},
Commands: map[string]*ice.Command{
- ice.WEB_SPACE: {Name: "space [name [cmd...]] auto", Help: "空间站", Action: map[string]*ice.Action{
+ SPACE: {Name: "space [name [cmd...]] auto", Help: "空间站", Action: map[string]*ice.Action{
"connect": {Name: "connect [dev [name]]", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
_space_dial(m, kit.Select("dev", arg, 0), kit.Select(cli.NodeName, arg, 2))
}},
@@ -213,22 +221,22 @@ 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) {
+ if s, e := websocket.Upgrade(m.W, m.R, nil, m.Confi(SPACE, "meta.buffer.r"), m.Confi(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))
+ kind := kit.Select(WORKER, m.Option(kit.MDB_TYPE))
// 添加节点
- h := m.Rich(ice.WEB_SPACE, nil, kit.Dict("socket", s,
+ h := m.Rich(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)
task.Put(name, func(task *task.Task) error {
// 监听消息
- m.Event(ice.SPACE_START, ice.WEB_WORKER, name)
+ m.Event(gdb.SPACE_START, WORKER, name)
_space_handle(m, false, m.Target().Server().(*Frame).send, s, name)
m.Log(ice.LOG_CLOSE, "%s: %s", name, kit.Format(m.Confv(SPACE, kit.Keys(kit.MDB_HASH, h))))
- m.Event(ice.SPACE_CLOSE, ice.WEB_WORKER, name)
+ m.Event(gdb.SPACE_CLOSE, WORKER, name)
m.Confv(SPACE, kit.Keys(kit.MDB_HASH, h), "")
return nil
})
diff --git a/base/web/spide.go b/base/web/spide.go
index b685a275..2c6513f5 100644
--- a/base/web/spide.go
+++ b/base/web/spide.go
@@ -46,7 +46,7 @@ func _spide_login(m *ice.Message, name string) {
}
if msg.Result() != "" {
kit.Value(value, "client.login", msg.Result())
- kit.Value(value, "client.share", m.Cmdx(SHARE, ice.TYPE_SPIDE, name,
+ kit.Value(value, "client.share", m.Cmdx(SHARE, TYPE_SPIDE, name,
kit.Format("%s?sessid=%s", kit.Value(value, "client.url"), kit.Value(value, "cookie.sessid"))))
}
m.Render(ice.RENDER_QRCODE, kit.Dict(
@@ -69,7 +69,7 @@ func _spide_create(m *ice.Message, name, address string, arg ...string) {
dir, file := path.Split(uri.EscapedPath())
m.Rich(SPIDE, nil, kit.Dict(
"cookie", kit.Dict(), "header", kit.Dict(), "client", kit.Dict(
- "share", ShareCreate(m.Spawn(), ice.TYPE_SPIDE, name, address),
+ "share", ShareCreate(m.Spawn(), TYPE_SPIDE, name, address),
"name", name, "url", address, "method", "POST",
"protocol", uri.Scheme, "hostname", uri.Host,
"path", dir, "file", file, "query", uri.RawQuery,
diff --git a/base/web/story.go b/base/web/story.go
index fc221cfb..69390918 100644
--- a/base/web/story.go
+++ b/base/web/story.go
@@ -12,11 +12,11 @@ import (
func _story_share(m *ice.Message, story string, list string, arg ...string) {
if m.Echo("share: "); list == "" {
- msg := m.Cmd(STORY, ice.STORY_INDEX, story)
- m.Cmdy(ice.WEB_SHARE, "story", story, msg.Append("list"))
+ msg := m.Cmd(STORY, INDEX, story)
+ m.Cmdy(SHARE, "story", story, msg.Append("list"))
} else {
- msg := m.Cmd(STORY, ice.STORY_INDEX, list)
- m.Cmdy(ice.WEB_SHARE, msg.Append("scene"), msg.Append("story"), msg.Append("text"))
+ msg := m.Cmd(STORY, INDEX, list)
+ m.Cmdy(SHARE, msg.Append("scene"), msg.Append("story"), msg.Append("text"))
}
}
func _story_list(m *ice.Message, arg ...string) {
@@ -31,7 +31,7 @@ func _story_list(m *ice.Message, arg ...string) {
m.Cmdy(STORY, "history", arg)
return
}
- m.Cmd(STORY, ice.STORY_INDEX, arg[1]).Table(func(index int, value map[string]string, head []string) {
+ m.Cmd(STORY, INDEX, arg[1]).Table(func(index int, value map[string]string, head []string) {
for k, v := range value {
m.Push("key", k)
m.Push("value", v)
@@ -51,15 +51,15 @@ func _story_pull(m *ice.Message, arg ...string) {
pull := end
var first map[string]interface{}
for begin != "" && begin != end {
- if m.Cmd(ice.WEB_SPIDE, arg[2], "msg", "/story/pull", "begin", begin, "end", end).Table(func(index int, value map[string]string, head []string) {
- if m.Richs(ice.WEB_CACHE, nil, value["data"], nil) == nil {
+ if m.Cmd(SPIDE, arg[2], "msg", "/story/pull", "begin", begin, "end", end).Table(func(index int, value map[string]string, head []string) {
+ if m.Richs(CACHE, nil, value["data"], nil) == nil {
m.Log(ice.LOG_IMPORT, "%v: %v", value["data"], value["save"])
if node := kit.UnMarshal(value["save"]); kit.Format(kit.Value(node, "file")) != "" {
// 下载文件
- m.Cmd(ice.WEB_SPIDE, arg[2], "cache", "GET", "/story/download/"+value["data"])
+ m.Cmd(SPIDE, arg[2], "cache", "GET", "/story/download/"+value["data"])
} else {
// 导入缓存
- m.Conf(ice.WEB_CACHE, kit.Keys("hash", value["data"]), node)
+ m.Conf(CACHE, kit.Keys("hash", value["data"]), node)
}
}
@@ -160,17 +160,17 @@ func _story_push(m *ice.Message, arg ...string) {
for _, v := range kit.Revert(nodes) {
m.Richs(STORY, nil, v, func(list string, node map[string]interface{}) {
- m.Richs(ice.WEB_CACHE, nil, node["data"], func(data string, save map[string]interface{}) {
+ m.Richs(CACHE, nil, node["data"], func(data string, save map[string]interface{}) {
if kit.Format(save["file"]) != "" {
// 推送缓存
- m.Cmd(ice.WEB_SPIDE, arg[2], "/story/upload",
+ m.Cmd(SPIDE, arg[2], "/story/upload",
"part", "upload", "@"+kit.Format(save["file"]),
)
}
// 推送节点
m.Log(ice.LOG_EXPORT, "%s: %s", v, kit.Format(node))
- m.Cmd(ice.WEB_SPIDE, arg[2], "/story/push",
+ m.Cmd(SPIDE, arg[2], "/story/push",
"story", arg[3], "list", v, "node", kit.Format(node),
"data", node["data"], "save", kit.Format(save),
)
@@ -197,7 +197,7 @@ func _story_commit(m *ice.Message, arg ...string) {
// 节点信息
menu := map[string]string{}
for i := 3; i < len(arg); i++ {
- menu[arg[i]] = m.Cmdx(STORY, ice.STORY_INDEX, arg[i])
+ menu[arg[i]] = m.Cmdx(STORY, INDEX, arg[i])
}
// 添加节点
@@ -221,12 +221,12 @@ func _story_commit(m *ice.Message, arg ...string) {
}
func _story_add(m *ice.Message, arg ...string) {
- if len(arg) < 4 || arg[3] == "" || m.Richs(ice.WEB_CACHE, nil, arg[3], func(key string, value map[string]interface{}) {
+ if len(arg) < 4 || arg[3] == "" || m.Richs(CACHE, nil, arg[3], func(key string, value map[string]interface{}) {
// 复用缓存
arg[3] = key
}) == nil {
// 添加缓存
- m.Cmdy(ice.WEB_CACHE, arg)
+ m.Cmdy(CACHE, arg)
arg = []string{arg[0], m.Append("type"), m.Append("name"), m.Append("data")}
}
@@ -267,12 +267,12 @@ func _story_add(m *ice.Message, arg ...string) {
// for _, k := range []string{"you", "pod"} {
// if p := m.Option(k); p != "" {
// m.Option(k, "")
- // m.Cmd(ice.WEB_PROXY, p, STORY, ice.STORY_PULL, arg[2], "dev", arg[2])
+ // m.Cmd(PROXY, p, STORY, PULL, arg[2], "dev", arg[2])
// return
// }
// }
- // m.Cmd(ice.WEB_PROXY, m.Conf(ice.WEB_FAVOR, "meta.proxy"),
- // STORY, ice.STORY_PULL, arg[2], "dev", arg[2])
+ // m.Cmd(PROXY, m.Conf(FAVOR, "meta.proxy"),
+ // STORY, PULL, arg[2], "dev", arg[2])
}
func _story_trash(m *ice.Message, arg ...string) {
bak := kit.Select(kit.Keys(arg[1], "bak"), arg, 2)
@@ -281,7 +281,7 @@ func _story_trash(m *ice.Message, arg ...string) {
}
func _story_catch(m *ice.Message, arg ...string) {
if last := m.Richs(STORY, "head", arg[2], nil); last != nil {
- if t, e := time.ParseInLocation(ice.ICE_TIME, kit.Format(last["time"]), time.Local); e == nil {
+ if t, e := time.ParseInLocation(ice.MOD_TIME, kit.Format(last["time"]), time.Local); e == nil {
// 文件对比
if s, e := os.Stat(arg[2]); e == nil && s.ModTime().Before(t) {
m.Push(arg[2], last, []string{"time", "count", "key"})
@@ -296,9 +296,9 @@ func _story_catch(m *ice.Message, arg ...string) {
func _story_watch(m *ice.Message, index string, arg ...string) {
// 备份文件
name := kit.Select(index, arg, 0)
- m.Cmd(STORY, ice.STORY_TRASH, name)
+ m.Cmd(STORY, TRASH, name)
- if msg := m.Cmd(STORY, ice.STORY_INDEX, index); msg.Append("file") != "" {
+ if msg := m.Cmd(STORY, INDEX, index); msg.Append("file") != "" {
p := path.Dir(name)
os.MkdirAll(p, 0777)
@@ -328,7 +328,7 @@ func _story_index(m *ice.Message, name string, withdata bool) {
name = kit.Format(value["data"])
})
- m.Richs(ice.WEB_CACHE, nil, name, func(key string, value map[string]interface{}) {
+ m.Richs(CACHE, nil, name, func(key string, value map[string]interface{}) {
// 查询数据
m.Push("data", key)
m.Push(key, value, []string{"text", "time", "size", "type", "name", "file"})
@@ -343,13 +343,13 @@ func _story_index(m *ice.Message, name string, withdata bool) {
}
func _story_history(m *ice.Message, name string) {
// 历史记录
- list := m.Cmd(STORY, ice.STORY_INDEX, name).Append("list")
+ list := m.Cmd(STORY, INDEX, name).Append("list")
for i := 0; i < kit.Int(kit.Select("30", m.Option("cache.limit"))) && list != ""; i++ {
m.Richs(STORY, nil, list, func(key string, value map[string]interface{}) {
// 直连节点
m.Push(key, value, []string{"time", "key", "count", "scene", "story"})
- m.Richs(ice.WEB_CACHE, nil, value["data"], func(key string, value map[string]interface{}) {
+ m.Richs(CACHE, nil, value["data"], func(key string, value map[string]interface{}) {
m.Push("drama", value["text"])
m.Push("data", key)
})
@@ -358,7 +358,7 @@ func _story_history(m *ice.Message, name string) {
m.Richs(STORY, nil, val, func(key string, value map[string]interface{}) {
// 复合节点
m.Push(key, value, []string{"time", "key", "count", "scene", "story"})
- m.Richs(ice.WEB_CACHE, nil, value["data"], func(key string, value map[string]interface{}) {
+ m.Richs(CACHE, nil, value["data"], func(key string, value map[string]interface{}) {
m.Push("drama", value["text"])
m.Push("data", key)
})
@@ -385,7 +385,18 @@ func StoryAdd(m *ice.Message, mime string, name string, text string, arg ...stri
const STORY = "story"
const (
+ TRASH = "trash"
CATCH = "catch"
+ INDEX = "index"
+
+ LIST = "list"
+ SHOW = "show"
+
+ PULL = "pull"
+ PUSH = "push"
+
+ UPLOAD = "upload"
+ DOWNLOAD = "download"
)
func init() {
@@ -423,25 +434,25 @@ func init() {
}
switch arg[0] {
- case ice.STORY_PULL: // story [spide [story]]
+ case PULL: // story [spide [story]]
_story_pull(m, arg...)
- case ice.STORY_PUSH:
+ case PUSH:
_story_push(m, arg...)
case "commit":
_story_commit(m, arg...)
- case ice.STORY_TRASH:
+ case TRASH:
_story_trash(m, arg...)
- case ice.STORY_WATCH:
+ case SHOW:
_story_watch(m, arg[1], arg[2:]...)
- case ice.STORY_CATCH:
+ case CATCH:
_story_catch(m, arg...)
- case "add", ice.STORY_UPLOAD, ice.STORY_DOWNLOAD:
+ case "add":
_story_add(m, arg...)
- case ice.STORY_INDEX:
+ case INDEX:
_story_index(m, arg[1], true)
- case ice.STORY_HISTORY:
+ case LIST:
_story_history(m, arg[1])
default:
_story_list(m, arg...)
@@ -450,15 +461,15 @@ func init() {
"/story/": {Name: "/story/", Help: "故事会", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
- case ice.STORY_PULL:
- list := m.Cmd(STORY, ice.STORY_INDEX, m.Option("begin")).Append("list")
+ case PULL:
+ list := m.Cmd(STORY, INDEX, m.Option("begin")).Append("list")
for i := 0; i < 10 && list != "" && list != m.Option("end"); i++ {
if m.Richs(STORY, nil, list, func(key string, value map[string]interface{}) {
// 节点信息
m.Push("list", key)
m.Push("node", kit.Format(value))
m.Push("data", value["data"])
- m.Push("save", kit.Format(m.Richs(ice.WEB_CACHE, nil, value["data"], nil)))
+ m.Push("save", kit.Format(m.Richs(CACHE, nil, value["data"], nil)))
list = kit.Format(value["prev"])
}) == nil {
break
@@ -466,11 +477,11 @@ func init() {
}
m.Log(ice.LOG_EXPORT, "%s %s", m.Option("begin"), m.Format("append"))
- case ice.STORY_PUSH:
- if m.Richs(ice.WEB_CACHE, nil, m.Option("data"), nil) == nil {
+ case PUSH:
+ if m.Richs(CACHE, nil, m.Option("data"), nil) == nil {
// 导入缓存
m.Log(ice.LOG_IMPORT, "%v: %v", m.Option("data"), m.Option("save"))
- m.Conf(ice.WEB_CACHE, kit.Keys("hash", m.Option("data")), kit.UnMarshal(m.Option("save")))
+ m.Conf(CACHE, kit.Keys("hash", m.Option("data")), kit.UnMarshal(m.Option("save")))
}
node := kit.UnMarshal(m.Option("node")).(map[string]interface{})
@@ -496,13 +507,13 @@ func init() {
// 推送失败
}
- case ice.STORY_UPLOAD:
+ case UPLOAD:
// 上传数据
- m.Cmdy(ice.WEB_CACHE, "upload")
+ m.Cmdy(CACHE, "upload")
- case ice.STORY_DOWNLOAD:
+ case DOWNLOAD:
// 下载数据
- m.Cmdy(STORY, ice.STORY_INDEX, arg[1])
+ m.Cmdy(STORY, INDEX, arg[1])
m.Render(kit.Select(ice.RENDER_DOWNLOAD, ice.RENDER_RESULT, m.Append("file") == ""), m.Append("text"))
}
}},
diff --git a/base/web/web.go b/base/web/web.go
index 5d54106b..0180ec29 100644
--- a/base/web/web.go
+++ b/base/web/web.go
@@ -2,6 +2,10 @@ package web
import (
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/aaa"
+ "github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/gdb"
+ "github.com/shylinux/icebergs/base/nfs"
kit "github.com/shylinux/toolkits"
"github.com/skip2/go-qrcode"
@@ -34,6 +38,7 @@ func Format(key string, arg ...interface{}) string {
}
return ""
}
+
func Render(msg *ice.Message, cmd string, args ...interface{}) {
if cmd != "" {
defer func() { msg.Log(ice.LOG_EXPORT, "%s: %v", cmd, args) }()
@@ -55,7 +60,7 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
msg.W.Write([]byte(kit.Select("", arg, 1)))
case "cookie":
- expire := time.Now().Add(kit.Duration(msg.Conf(ice.AAA_SESS, "meta.expire")))
+ expire := time.Now().Add(kit.Duration(msg.Conf(aaa.SESS, "meta.expire")))
http.SetCookie(msg.W, &http.Cookie{Value: arg[0], Name: kit.Select(ice.MSG_SESSID, arg, 1), Path: "/", Expires: expire})
case ice.RENDER_DOWNLOAD:
@@ -136,18 +141,18 @@ func (web *Frame) Start(m *ice.Message, arg ...string) bool {
})
// TODO simple
- m.Richs(ice.WEB_SPIDE, nil, arg[0], func(key string, value map[string]interface{}) {
+ m.Richs(SPIDE, nil, arg[0], func(key string, value map[string]interface{}) {
client := value["client"].(map[string]interface{})
// 服务地址
port := m.Cap(ice.CTX_STREAM, client["hostname"])
- m.Log("serve", "listen %s %s %v", arg[0], port, m.Conf(ice.CLI_RUNTIME, "node"))
+ m.Log("serve", "listen %s %s %v", arg[0], port, m.Conf(cli.RUNTIME, "node"))
// 启动服务
web.m, web.Server = m, &http.Server{Addr: port, Handler: web}
- m.Event(ice.SERVE_START, arg[0])
+ m.Event(gdb.SERVE_START, arg[0])
m.Warn(true, "listen %s", web.Server.ListenAndServe())
- m.Event(ice.SERVE_CLOSE, arg[0])
+ m.Event(gdb.SERVE_CLOSE, arg[0])
})
return true
}
@@ -159,19 +164,19 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
- m.Cmd(SPIDE, kit.MDB_CREATE, "self", kit.Select("http://:9020", m.Conf(ice.CLI_RUNTIME, "conf.ctx_self")))
- m.Cmd(SPIDE, kit.MDB_CREATE, "dev", kit.Select("http://:9020", m.Conf(ice.CLI_RUNTIME, "conf.ctx_dev")))
- m.Cmd(SPIDE, kit.MDB_CREATE, "shy", kit.Select("https://shylinux.com:443", m.Conf(ice.CLI_RUNTIME, "conf.ctx_shy")))
+ m.Cmd(SPIDE, kit.MDB_CREATE, "self", kit.Select("http://:9020", m.Conf(cli.RUNTIME, "conf.ctx_self")))
+ m.Cmd(SPIDE, kit.MDB_CREATE, "dev", kit.Select("http://:9020", m.Conf(cli.RUNTIME, "conf.ctx_dev")))
+ m.Cmd(SPIDE, kit.MDB_CREATE, "shy", kit.Select("https://shylinux.com:443", m.Conf(cli.RUNTIME, "conf.ctx_shy")))
- m.Cmd(ice.APP_SEARCH, "add", "favor", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Cmd(nfs.SEARCH, "add", "favor", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "set":
- m.Richs(ice.WEB_FAVOR, nil, arg[1], func(key string, value map[string]interface{}) {
- m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "id", arg[2], func(index int, value map[string]interface{}) {
- if cmd := m.Conf(ice.WEB_FAVOR, kit.Keys("meta.render", value["type"])); cmd != "" {
+ m.Richs(FAVOR, nil, arg[1], func(key string, value map[string]interface{}) {
+ m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), "id", arg[2], func(index int, value map[string]interface{}) {
+ if cmd := m.Conf(FAVOR, kit.Keys("meta.render", value["type"])); cmd != "" {
m.Optionv("value", value)
m.Cmdy(cmd, arg[1:])
} else {
@@ -184,11 +189,11 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
m.Option("cache.limit", -2)
wg := &sync.WaitGroup{}
- m.Richs(ice.WEB_FAVOR, nil, "*", func(key string, val map[string]interface{}) {
+ m.Richs(FAVOR, nil, "*", func(key string, val map[string]interface{}) {
favor := kit.Format(kit.Value(val, "meta.name"))
wg.Add(1)
m.Gos(m, func(m *ice.Message) {
- m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
+ m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
if favor == arg[0] || value["type"] == arg[0] ||
strings.Contains(kit.Format(value["name"]), arg[0]) || strings.Contains(kit.Format(value["text"]), arg[0]) {
m.Push("pod", m.Option(ice.MSG_USERPOD))
@@ -203,14 +208,14 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
wg.Wait()
}}))
- m.Cmd(ice.APP_SEARCH, "add", "story", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Cmd(nfs.SEARCH, "add", "story", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "set":
- m.Cmdy(ice.WEB_STORY, "index", arg[2])
+ m.Cmdy(STORY, "index", arg[2])
return
}
- m.Richs(ice.WEB_STORY, "head", "*", func(key string, val map[string]interface{}) {
+ m.Richs(STORY, "head", "*", func(key string, val map[string]interface{}) {
if val["story"] == arg[0] {
m.Push("pod", m.Option(ice.MSG_USERPOD))
m.Push("engine", "story")
@@ -225,15 +230,15 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
})
}}))
- m.Cmd(ice.APP_SEARCH, "add", "share", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Cmd(nfs.SEARCH, "add", "share", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "set":
- m.Cmdy(ice.WEB_SHARE, arg[2])
+ m.Cmdy(SHARE, arg[2])
return
}
m.Option("cache.limit", -2)
- m.Grows(ice.WEB_SHARE, nil, "", "", func(index int, value map[string]interface{}) {
+ m.Grows(SHARE, nil, "", "", func(index int, value map[string]interface{}) {
if value["share"] == arg[0] || value["type"] == arg[0] ||
strings.Contains(kit.Format(value["name"]), arg[0]) || strings.Contains(kit.Format(value["text"]), arg[0]) {
m.Push("pod", m.Option(ice.MSG_USERPOD))
@@ -249,16 +254,16 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
})
}}))
- m.Conf(ice.WEB_FAVOR, "meta.render.bench", m.AddCmd(&ice.Command{Name: "render type name text arg...", Help: "渲染引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Conf(FAVOR, "meta.render.bench", m.AddCmd(&ice.Command{Name: "render type name text arg...", Help: "渲染引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmdy("web.code.bench", "action", "show", arg)
}}))
}},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Save(ice.WEB_SPIDE, ice.WEB_SERVE, ice.WEB_GROUP, ice.WEB_LABEL,
- ice.WEB_FAVOR, ice.WEB_CACHE, ice.WEB_STORY, ice.WEB_SHARE)
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Save(SPIDE, SERVE, GROUP, LABEL,
+ FAVOR, CACHE, STORY, SHARE)
m.Done()
- m.Richs(ice.WEB_SPACE, nil, "*", func(key string, value map[string]interface{}) {
+ m.Richs(SPACE, nil, "*", func(key string, value map[string]interface{}) {
if kit.Format(value["type"]) == "master" {
m.Done()
}
diff --git a/conf.go b/conf.go
index 18a5fb48..ca7baf71 100644
--- a/conf.go
+++ b/conf.go
@@ -1,21 +1,14 @@
package ice
-const (
- DIR_MOD = 0750
- FILE_MOD = 0640
-)
+const ( //MOD
+ MOD_DIR = 0750
+ MOD_FILE = 0640
-const ( // ICE
- ICE_CHAN = 10
- ICE_INIT = "_init"
- ICE_EXIT = "_exit"
- ICE_DATE = "2006-01-02"
- ICE_TIME = "2006-01-02 15:04:05"
+ MOD_CHAN = 16
+ MOD_BUF = 1024
- ICE_BEGIN = "begin"
- ICE_START = "start"
- ICE_SERVE = "serve"
- ICE_CLOSE = "close"
+ MOD_DATE = "2006-01-02"
+ MOD_TIME = "2006-01-02 15:04:05"
)
const ( // MSG
MSG_DETAIL = "detail"
@@ -23,6 +16,7 @@ const ( // MSG
MSG_APPEND = "append"
MSG_RESULT = "result"
+ MSG_ALIAS = "_alias"
MSG_SOURCE = "_source"
MSG_TARGET = "_target"
MSG_HANDLE = "_handle"
@@ -30,10 +24,6 @@ const ( // MSG
MSG_OUTPUT = "_output"
MSG_ARGS = "_args"
- MSG_STDOUT = "_stdout"
- MSG_PROMPT = "_prompt"
- MSG_ALIAS = "_alias"
-
MSG_SESSID = "sessid"
MSG_USERIP = "user.ip"
MSG_USERUA = "user.ua"
@@ -43,64 +33,25 @@ const ( // MSG
MSG_USERNICK = "user.nick"
MSG_USERNAME = "user.name"
MSG_USERROLE = "user.role"
- MSG_USERADDR = "user.addr"
MSG_USERDATA = "user.data"
+ MSG_USERADDR = "user.addr"
- MSG_RIVER = "sess.river"
- MSG_STORM = "sess.storm"
-
- FIELD_RELOAD = "field.reload"
- FIELD_DETAIL = "field.detail"
-
- EXPORT_LABEL = "lab"
- EXPORT_GROUP = "grp"
+ MSG_RIVER = "sess.river"
+ MSG_STORM = "sess.storm"
+ MSG_ACTIVE = "sess.active"
)
-
const ( // CTX
- CTX_STATUS = "status"
- CTX_STREAM = "stream"
- CTX_FOLLOW = "follow"
- CTX_CONFIG = "config"
- CTX_COMMAND = "command"
- CTX_CONTEXT = "context"
-)
-const ( // CLI
- CLI_RUNTIME = "runtime"
- CLI_SYSTEM = "system"
- CLI_DAEMON = "daemon"
-)
-const ( // AAA
- AAA_ROLE = "role"
- AAA_USER = "user"
- AAA_SESS = "sess"
-)
-const ( // WEB
- WEB_PORT = ":9020"
- WEB_SESS = "sessid"
- WEB_TMPL = "render"
+ CTX_STREAM = "stream"
+ CTX_STATUS = "status"
+ CTX_FOLLOW = "follow"
- WEB_LOGIN = "_login"
+ CTX_INIT = "_init"
+ CTX_EXIT = "_exit"
- WEB_SPIDE = "spide"
- WEB_SERVE = "serve"
- WEB_SPACE = "space"
- WEB_DREAM = "dream"
-
- WEB_FAVOR = "favor"
- WEB_CACHE = "cache"
- WEB_STORY = "story"
- WEB_SHARE = "share"
-
- WEB_ROUTE = "route"
- WEB_PROXY = "proxy"
- WEB_GROUP = "group"
- WEB_LABEL = "label"
-
- WEB_MASTER = "master"
- WEB_MYSELF = "myself"
- WEB_BETTER = "better"
- WEB_SERVER = "server"
- WEB_WORKER = "worker"
+ CTX_BEGIN = "begin"
+ CTX_START = "start"
+ CTX_SERVE = "serve"
+ CTX_CLOSE = "close"
)
const ( // LOG
// 数据
@@ -115,12 +66,13 @@ const ( // LOG
// 事件
LOG_ENABLE = "enable"
+ LOG_STATUS = "status"
LOG_LISTEN = "listen"
LOG_ACCEPT = "accept"
LOG_FINISH = "finish"
LOG_SIGNAL = "signal"
- LOG_EVENTS = "events"
LOG_TIMERS = "timers"
+ LOG_EVENTS = "events"
// 状态
LOG_BEGIN = "begin"
@@ -139,163 +91,18 @@ const ( // LOG
LOG_TRACE = "trace"
LOG_DEBUG = "debug"
)
-const ( // SSH
- SSH_SOURCE = "source"
-)
-const ( // GDB
- GDB_SIGNAL = "signal"
- GDB_TIMER = "timer"
- GDB_EVENT = "event"
-
- SYSTEM_INIT = "system.init"
-
- SERVE_START = "serve.start"
- SERVE_CLOSE = "serve.close"
- SPACE_START = "space.start"
- SPACE_CLOSE = "space.close"
- DREAM_START = "dream.start"
- DREAM_CLOSE = "dream.close"
-
- USER_CREATE = "user.create"
- CHAT_CREATE = "chat.create"
- MISS_CREATE = "miss.create"
- MIND_CREATE = "mind.create"
-)
-const ( // MDB
- MDB_REDIS = "redis"
- MDB_MYSQL = "mysql"
- MDB_CREATE = "create"
- MDB_IMPORT = "import"
- MDB_EXPORT = "export"
- MDB_REMOVE = "remove"
-
- MDB_INESRT = "insert"
- MDB_UPDATE = "update"
- MDB_SELECT = "select"
- MDB_DELETE = "delete"
-)
-
-const ( // APP
- APP_MIND = "mind"
- APP_MISS = "miss"
- APP_SEARCH = "search"
- APP_COMMEND = "commend"
-)
-const ( // ROLE
- ROLE_ROOT = "root"
- ROLE_TECH = "tech"
- ROLE_VOID = "void"
-)
-const ( // TYPE
- TYPE_SPIDE = "spide"
- TYPE_SPACE = "space"
- TYPE_STORY = "story"
-
- TYPE_RIVER = "river"
- TYPE_STORM = "storm"
- TYPE_ACTION = "action"
- TYPE_ACTIVE = "active"
-
- TYPE_DRIVE = "drive"
- TYPE_SHELL = "shell"
- TYPE_VIMRC = "vimrc"
- TYPE_TABLE = "table"
- TYPE_INNER = "inner"
- TYPE_MEDIA = "media"
-)
-const ( // CODE
- CODE_INSTALL = "_install"
- CODE_PREPARE = "_prepare"
- CODE_PROJECT = "_project"
-)
-const ( // CHAT
- CHAT_RIVER = "river"
- CHAT_STORM = "storm"
-)
-const ( // FAVOR
- FAVOR_CHAT = "chat.init"
- FAVOR_TMUX = "tmux.init"
- FAVOR_START = "favor.start"
-)
-const ( // STORY
- STORY_CATCH = "catch"
- STORY_INDEX = "index"
- STORY_TRASH = "trash"
- STORY_WATCH = "watch"
-
- STORY_STATUS = "status"
- STORY_COMMIT = "commit"
- STORY_BRANCH = "branch"
- STORY_HISTORY = "history"
-
- STORY_PULL = "pull"
- STORY_PUSH = "push"
- STORY_UPLOAD = "upload"
- STORY_DOWNLOAD = "download"
-)
const ( // RENDER
RENDER_VOID = "_void"
RENDER_OUTPUT = "_output"
- RENDER_TEMPLATE = "_template"
- RENDER_DOWNLOAD = "_download"
RENDER_RESULT = "_result"
RENDER_QRCODE = "_qrcode"
+ RENDER_TEMPLATE = "_template"
+ RENDER_DOWNLOAD = "_download"
)
-var Alias = map[string]string{
- CTX_CONTEXT: "ctx.context",
- CTX_COMMAND: "ctx.command",
- CTX_CONFIG: "ctx.config",
-
- CLI_RUNTIME: "cli.runtime",
- CLI_SYSTEM: "cli.system",
- CLI_DAEMON: "cli.daemon",
- SSH_SOURCE: "ssh.source",
-
- AAA_ROLE: "aaa.role",
- AAA_USER: "aaa.user",
- AAA_SESS: "aaa.sess",
-
- WEB_SPIDE: "web.spide",
- WEB_SERVE: "web.serve",
- WEB_SPACE: "web.space",
- WEB_DREAM: "web.dream",
-
- WEB_FAVOR: "web.favor",
- WEB_CACHE: "web.cache",
- WEB_STORY: "web.story",
- WEB_SHARE: "web.share",
-
- WEB_ROUTE: "web.route",
- WEB_PROXY: "web.proxy",
- WEB_GROUP: "web.group",
- WEB_LABEL: "web.label",
-
- GDB_SIGNAL: "gdb.signal",
- GDB_TIMER: "gdb.timer",
- GDB_EVENT: "gdb.event",
-
- MDB_REDIS: "mdb.redis",
- MDB_MYSQL: "mdb.mysql",
- MDB_CREATE: "mdb.create",
- MDB_IMPORT: "mdb.import",
- MDB_EXPORT: "mdb.export",
- MDB_REMOVE: "mdb.remove",
-
- MDB_INESRT: "mdb.insert",
- MDB_UPDATE: "mdb.update",
- MDB_SELECT: "mdb.select",
- MDB_DELETE: "mdb.delete",
-
- CHAT_RIVER: "web.chat.river",
-
- APP_MISS: "web.team.miss",
- APP_MIND: "web.wiki.mind",
- APP_SEARCH: "web.chat.search",
- APP_COMMEND: "web.chat.commend",
-
- "compile": "web.code.compile",
- "publish": "web.code.publish",
- "upgrade": "web.code.upgrade",
- "pprof": "web.code.pprof",
-}
+const ( // TODO
+ EXPORT_LABEL = "lab"
+ EXPORT_GROUP = "grp"
+ FIELD_RELOAD = "field.reload"
+ FIELD_DETAIL = "field.detail"
+)
diff --git a/core/chat/action.go b/core/chat/action.go
index 41fa3372..26f2d405 100644
--- a/core/chat/action.go
+++ b/core/chat/action.go
@@ -2,6 +2,8 @@ package chat
import (
"github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/ctx"
+ "github.com/shylinux/icebergs/base/web"
"github.com/shylinux/toolkits"
"strconv"
@@ -9,7 +11,7 @@ import (
func _action_share_create(m *ice.Message, arg ...string) {
if m.Option("_index") != "" {
- m.Cmdy(ice.WEB_SHARE, ice.TYPE_ACTION, m.Option("_name"), m.Option("_text"),
+ m.Cmdy(web.SHARE, web.TYPE_ACTION, m.Option("_name"), m.Option("_text"),
"tool.0.pod", kit.Select(m.Option("_pod"), m.Option("_node")),
"tool.0.ctx", m.Option("_group"),
"tool.0.cmd", m.Option("_index"),
@@ -29,7 +31,7 @@ func _action_share_create(m *ice.Message, arg ...string) {
}
}
func _action_share_list(m *ice.Message, river, storm string) {
- m.Richs(ice.WEB_SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
+ m.Richs(web.SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
kit.Fetch(kit.Value(value, "extra.tool"), func(index int, value map[string]interface{}) {
m.Push("river", river)
m.Push("storm", storm)
@@ -40,7 +42,7 @@ func _action_share_list(m *ice.Message, river, storm string) {
m.Push("index", value["cmd"])
m.Push("args", value["args"])
- msg := m.Cmd(m.Space(value["pod"]), ice.CTX_COMMAND, kit.Keys(value["ctx"], value["cmd"]))
+ msg := m.Cmd(m.Space(value["pod"]), ctx.COMMAND, kit.Keys(value["ctx"], value["cmd"]))
m.Push("name", value["cmd"])
m.Push("help", kit.Select(msg.Append("help"), kit.Format(value["help"])))
m.Push("inputs", msg.Append("list"))
@@ -50,7 +52,7 @@ func _action_share_list(m *ice.Message, river, storm string) {
}
func _action_share_show(m *ice.Message, river, storm, index string, arg ...string) {
if i, e := strconv.Atoi(index); e == nil {
- m.Richs(ice.WEB_SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
+ m.Richs(web.SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
kit.Fetch(kit.Value(value, kit.Keys("extra.tool", i-1)), func(value map[string]interface{}) {
cmds := kit.Simple(kit.Keys(value["ctx"], value["cmd"]), arg)
m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds)
@@ -69,7 +71,7 @@ func _action_order_list(m *ice.Message, river, storm string, arg ...string) {
m.Push("index", v)
m.Push("args", "[]")
- msg := m.Cmd(m.Space(m.Option("pod")), ice.CTX_COMMAND, v)
+ msg := m.Cmd(m.Space(m.Option("pod")), ctx.COMMAND, v)
m.Push("name", msg.Append("name"))
m.Push("help", msg.Append("help"))
m.Push("feature", msg.Append("meta"))
@@ -80,7 +82,7 @@ func _action_order_list(m *ice.Message, river, storm string, arg ...string) {
func _action_action(m *ice.Message, action string, arg ...string) bool {
switch action {
case "upload":
- msg := m.Cmd(ice.WEB_STORY, "upload")
+ msg := m.Cmd(web.STORY, "upload")
m.Option("name", msg.Append("name"))
m.Option("data", msg.Append("data"))
}
@@ -88,14 +90,14 @@ func _action_action(m *ice.Message, action string, arg ...string) bool {
}
func _action_proxy(m *ice.Message) (proxy []string) {
if m.Option("pod") != "" {
- proxy = append(proxy, ice.WEB_PROXY, m.Option("pod"))
+ proxy = append(proxy, web.PROXY, m.Option("pod"))
m.Option("pod", "")
}
return proxy
}
func _action_list(m *ice.Message, river, storm string) {
prefix := kit.Keys(kit.MDB_HASH, river, "tool", kit.MDB_HASH, storm)
- m.Grows(ice.CHAT_RIVER, prefix, "", "", func(index int, value map[string]interface{}) {
+ m.Grows(RIVER, prefix, "", "", func(index int, value map[string]interface{}) {
if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok {
m.Push("river", river)
m.Push("storm", storm)
@@ -106,7 +108,7 @@ func _action_list(m *ice.Message, river, storm string) {
m.Push("index", meta["cmd"])
m.Push("args", kit.Select("[]", kit.Format(meta["args"])))
- msg := m.Cmd(m.Space(meta["pod"]), ice.CTX_COMMAND, kit.Keys(meta["ctx"], meta["cmd"]))
+ msg := m.Cmd(m.Space(meta["pod"]), ctx.COMMAND, kit.Keys(meta["ctx"], meta["cmd"]))
m.Push("name", meta["cmd"])
m.Push("help", kit.Select(msg.Append("help"), kit.Format(meta["help"])))
m.Push("feature", msg.Append("meta"))
@@ -119,7 +121,7 @@ func _action_show(m *ice.Message, river, storm, index string, arg ...string) {
cmds := []string{}
if i, e := strconv.Atoi(index); e == nil {
- m.Grows(ice.CHAT_RIVER, prefix, kit.MDB_ID, kit.Format(i+1), func(index int, value map[string]interface{}) {
+ m.Grows(RIVER, prefix, kit.MDB_ID, kit.Format(i+1), func(index int, value map[string]interface{}) {
if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok {
cmds = kit.Simple(m.Space(meta["pod"]), kit.Keys(meta["ctx"], meta["cmd"]), arg[3:])
}
@@ -149,7 +151,7 @@ func init() {
if p := m.Option("pod"); p != "" {
m.Option("pod", "")
// 代理列表
- m.Cmdy(ice.WEB_SPACE, p, "web.chat./action", arg)
+ m.Cmdy(web.SPACE, p, "web.chat./action", arg)
}
// 命令列表
_action_list(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM))
diff --git a/core/chat/chat.go b/core/chat/chat.go
index e429eaf2..06054957 100644
--- a/core/chat/chat.go
+++ b/core/chat/chat.go
@@ -3,6 +3,8 @@ package chat
import (
"github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/aaa"
+ "github.com/shylinux/icebergs/base/ctx"
+ "github.com/shylinux/icebergs/base/gdb"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/toolkits"
@@ -90,20 +92,20 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
)},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
- m.Watch(ice.SYSTEM_INIT, m.Prefix("init"))
- m.Watch(ice.USER_CREATE, m.Prefix("auto"))
+ m.Watch(gdb.SYSTEM_INIT, m.Prefix("init"))
+ m.Watch(gdb.USER_CREATE, m.Prefix("auto"))
}},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save(RIVER)
}},
"init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- if len(m.Confm(ice.CHAT_RIVER, kit.MDB_HASH)) == 0 {
+ if len(m.Confm(RIVER, kit.MDB_HASH)) == 0 {
// 默认群组
- kit.Fetch(m.Confv(ice.CHAT_RIVER, "meta.template"), func(key string, val map[string]interface{}) {
- if favor := kit.Keys(c.Cap(ice.CTX_FOLLOW), key); m.Richs(ice.WEB_FAVOR, nil, favor, nil) == nil {
+ kit.Fetch(m.Confv(RIVER, "meta.template"), func(key string, val map[string]interface{}) {
+ if favor := kit.Keys(c.Cap(ice.CTX_FOLLOW), key); m.Richs(web.FAVOR, nil, favor, nil) == nil {
kit.Fetch(val, func(index int, value interface{}) {
v := kit.Simple(value)
web.FavorInsert(m, favor, v[0], v[1], v[2])
@@ -112,11 +114,11 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
})
// 黑名单
- kit.Fetch(m.Confv(ice.CHAT_RIVER, "meta.black.tech"), func(index int, value interface{}) {
+ kit.Fetch(m.Confv(RIVER, "meta.black.tech"), func(index int, value interface{}) {
m.Cmd(aaa.ROLE, aaa.Black, aaa.TECH, value)
})
// 白名单
- kit.Fetch(m.Confv(ice.CHAT_RIVER, "meta.white.void"), func(index int, value interface{}) {
+ kit.Fetch(m.Confv(RIVER, "meta.white.void"), func(index int, value interface{}) {
m.Cmd(aaa.ROLE, aaa.White, aaa.VOID, value)
})
}
@@ -144,7 +146,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
})
}},
- ice.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ web.LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(ice.MSG_RIVER, "")
m.Option(ice.MSG_STORM, "")
@@ -159,11 +161,11 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
default:
// 群组检查
- m.Richs(ice.CHAT_RIVER, nil, arg[0], func(key string, value map[string]interface{}) {
- m.Richs(ice.CHAT_RIVER, kit.Keys(kit.MDB_HASH, arg[0], "user"), m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
+ m.Richs(RIVER, nil, arg[0], func(key string, value map[string]interface{}) {
+ m.Richs(RIVER, kit.Keys(kit.MDB_HASH, arg[0], "user"), m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
if m.Option(ice.MSG_RIVER, arg[0]); len(arg) > 1 {
// 应用检查
- m.Richs(ice.CHAT_RIVER, kit.Keys(kit.MDB_HASH, arg[0], "tool"), arg[1], func(key string, value map[string]interface{}) {
+ m.Richs(RIVER, kit.Keys(kit.MDB_HASH, arg[0], "tool"), arg[1], func(key string, value map[string]interface{}) {
m.Option(ice.MSG_STORM, arg[1])
})
}
@@ -202,7 +204,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
"/login": {Name: "/login", Help: "登录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "check":
- m.Richs(ice.AAA_USER, nil, m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
+ m.Richs(aaa.USER, nil, m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
m.Push("nickname", value["nickname"])
})
m.Render(m.Option(ice.MSG_USERNAME))
@@ -234,14 +236,14 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
default:
return
}
- m.Cmdy(ice.WEB_SHARE, arg[1], arg[2], arg[3], arg[4:])
+ m.Cmdy(web.SHARE, arg[1], arg[2], arg[3], arg[4:])
}
}},
"/ocean": {Name: "/ocean", Help: "大海洋", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 {
// 用户列表
- m.Richs(ice.AAA_USER, nil, "*", func(key string, value map[string]interface{}) {
+ m.Richs(aaa.USER, nil, "*", func(key string, value map[string]interface{}) {
m.Push(key, value, []string{"username", "usernode"})
})
return
@@ -250,7 +252,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
switch arg[0] {
case "spawn":
// 创建群组
- river := m.Rich(ice.CHAT_RIVER, nil, kit.Dict(
+ river := m.Rich(RIVER, nil, kit.Dict(
kit.MDB_META, kit.Dict(kit.MDB_NAME, arg[1]),
"user", kit.Data(kit.MDB_SHORT, "username"),
"tool", kit.Data(),
@@ -270,15 +272,15 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
if len(arg) < 2 {
if list := []string{}; m.Option("pod") != "" {
// 远程空间
- m.Cmdy(ice.WEB_SPACE, m.Option("pod"), "web.chat./steam").Table(func(index int, value map[string]string, head []string) {
+ m.Cmdy(web.SPACE, m.Option("pod"), "web.chat./steam").Table(func(index int, value map[string]string, head []string) {
list = append(list, kit.Keys(m.Option("pod"), value["name"]))
})
m.Append("name", list)
} else {
// 本地空间
- m.Richs(ice.WEB_SPACE, nil, "*", func(key string, value map[string]interface{}) {
+ m.Richs(web.SPACE, nil, "*", func(key string, value map[string]interface{}) {
switch value[kit.MDB_TYPE] {
- case ice.WEB_SERVER, ice.WEB_WORKER:
+ case web.SERVER, web.WORKER:
m.Push(key, value, []string{"type", "name", "user"})
}
})
@@ -294,7 +296,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
switch arg[1] {
case "spawn":
// 创建应用
- storm := m.Rich(ice.CHAT_RIVER, kit.Keys(kit.MDB_HASH, arg[0], "tool"), kit.Dict(
+ storm := m.Rich(RIVER, kit.Keys(kit.MDB_HASH, arg[0], "tool"), kit.Dict(
kit.MDB_META, kit.Dict(kit.MDB_NAME, arg[2]),
))
m.Log(ice.LOG_CREATE, "storm: %s name: %v", storm, arg[2])
@@ -308,7 +310,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
default:
// 命令列表
- m.Cmdy(ice.WEB_SPACE, arg[2], ice.CTX_COMMAND)
+ m.Cmdy(web.SPACE, arg[2], ctx.COMMAND)
}
}},
@@ -317,7 +319,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
"commend": {Name: "commend label pod engine work auto", Help: "推荐引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) < 2 {
- m.Cmdy(ice.WEB_LABEL, arg)
+ m.Cmdy(web.LABEL, arg)
return
}
@@ -346,7 +348,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
wg.Wait()
case "set":
if arg[1] != "" {
- m.Cmdy(ice.WEB_SPACE, arg[1], "web.chat.commend", "set", "", arg[2:])
+ m.Cmdy(web.SPACE, arg[1], "web.chat.commend", "set", "", arg[2:])
break
}
@@ -390,7 +392,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
})
break
}
- m.Cmdy(ice.WEB_LABEL, arg[0], arg[1], "web.chat.commend", "get", arg[2:])
+ m.Cmdy(web.LABEL, arg[0], arg[1], "web.chat.commend", "get", arg[2:])
// m.Cmdy("web.chat.commend", "get", arg[2:])
}
}},
diff --git a/core/chat/footer.go b/core/chat/footer.go
index a7ec5ef1..97c6165b 100644
--- a/core/chat/footer.go
+++ b/core/chat/footer.go
@@ -2,13 +2,14 @@ package chat
import (
"github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/web"
"github.com/shylinux/toolkits"
)
func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
"/footer": {Name: "/footer", Help: "状态栏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- kit.Fetch(m.Confv(ice.WEB_SERVE, "meta.legal"), func(index int, value string) {
+ kit.Fetch(m.Confv(web.SERVE, "meta.legal"), func(index int, value string) {
m.Echo(value)
})
}},
diff --git a/core/chat/header.go b/core/chat/header.go
index ef673a89..735518f7 100644
--- a/core/chat/header.go
+++ b/core/chat/header.go
@@ -2,6 +2,7 @@ package chat
import (
"github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/web"
"github.com/shylinux/toolkits"
)
@@ -18,7 +19,7 @@ func init() {
m.Render(m.Option(ice.MSG_USERNAME))
}
default:
- m.Echo(m.Conf(ice.WEB_SERVE, "meta.title"))
+ m.Echo(m.Conf(web.SERVE, "meta.title"))
}
}},
}}, nil)
diff --git a/core/chat/river.go b/core/chat/river.go
index 4876921d..1e5773ca 100644
--- a/core/chat/river.go
+++ b/core/chat/river.go
@@ -2,6 +2,7 @@ package chat
import (
"github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/toolkits"
)
@@ -28,7 +29,7 @@ func _river_list(m *ice.Message) {
})
}
func _river_user(m *ice.Message, river string, user ...string) {
- m.Rich(RIVER, kit.Keys(kit.MDB_HASH, river, "user"), kit.Data("username", m.Conf(ice.CLI_RUNTIME, "boot.username")))
+ m.Rich(RIVER, kit.Keys(kit.MDB_HASH, river, "user"), kit.Data("username", m.Conf(cli.RUNTIME, "boot.username")))
for _, v := range user {
user := m.Rich(RIVER, kit.Keys(kit.MDB_HASH, river, "user"), kit.Data("username", v))
m.Log_INSERT(RIVER, river, "hash", user, "user", v)
@@ -52,17 +53,17 @@ func init() {
Action: map[string]*ice.Action{
"user": {Name: "user user...", Help: "添加用户", Hand: func(m *ice.Message, arg ...string) {
if _river_right(m, "user") {
- _river_user(m, m.Option(ice.CHAT_RIVER), arg...)
+ _river_user(m, m.Option(RIVER), arg...)
}
}},
"rename": {Name: "rename name", Help: "重命名", Hand: func(m *ice.Message, arg ...string) {
if _river_right(m, "rename") {
- _river_rename(m, m.Option(ice.CHAT_RIVER), arg[0])
+ _river_rename(m, m.Option(RIVER), arg[0])
}
}},
"remove": {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
if _river_right(m, "remove") {
- _river_remove(m, m.Option(ice.CHAT_RIVER))
+ _river_remove(m, m.Option(RIVER))
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
diff --git a/core/chat/search.go b/core/chat/search.go
index 16a4b1e6..2937ae85 100644
--- a/core/chat/search.go
+++ b/core/chat/search.go
@@ -2,6 +2,7 @@ package chat
import (
"github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/web"
"github.com/shylinux/toolkits"
"sync"
)
@@ -14,7 +15,7 @@ func init() {
Commands: map[string]*ice.Command{
"search": {Name: "search label pod engine word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) < 2 {
- m.Cmdy(ice.WEB_LABEL, arg)
+ m.Cmdy(web.LABEL, arg)
return
}
@@ -42,7 +43,7 @@ func init() {
wg.Wait()
case "set":
if arg[1] != "" {
- m.Cmdy(ice.WEB_SPACE, arg[1], "web.chat.search", "set", "", arg[2:])
+ m.Cmdy(web.SPACE, arg[1], "web.chat.search", "set", "", arg[2:])
break
}
@@ -67,7 +68,7 @@ func init() {
break
}
m.Option("pod", "")
- m.Cmdy(ice.WEB_LABEL, arg[0], arg[1], "web.chat.search", "get", arg[2:])
+ m.Cmdy(web.LABEL, arg[0], arg[1], "web.chat.search", "get", arg[2:])
m.Sort("time", "time_r")
}
}},
diff --git a/core/chat/storm.go b/core/chat/storm.go
index 8bf49f0c..d8e74f4a 100644
--- a/core/chat/storm.go
+++ b/core/chat/storm.go
@@ -2,11 +2,12 @@ package chat
import (
"github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/web"
"github.com/shylinux/toolkits"
)
func _storm_list(m *ice.Message, river string) {
- m.Richs(ice.CHAT_RIVER, kit.Keys(kit.MDB_HASH, river, "tool"), "*", func(key string, value map[string]interface{}) {
+ m.Richs(RIVER, kit.Keys(kit.MDB_HASH, river, "tool"), "*", func(key string, value map[string]interface{}) {
m.Push(key, value["meta"], []string{kit.MDB_KEY, kit.MDB_NAME})
})
m.Sort(kit.MDB_NAME)
@@ -14,27 +15,27 @@ func _storm_list(m *ice.Message, river string) {
func _storm_tool(m *ice.Message, river, storm string, arg ...string) {
prefix := kit.Keys(kit.MDB_HASH, river, "tool", kit.MDB_HASH, storm)
for i := 0; i < len(arg)-3; i += 4 {
- id := m.Grow(ice.CHAT_RIVER, kit.Keys(prefix), kit.Data(
+ id := m.Grow(RIVER, kit.Keys(prefix), kit.Data(
"pod", arg[i], "ctx", arg[i+1], "cmd", arg[i+2], "help", arg[i+3],
))
m.Log_INSERT(RIVER, river, STORM, storm, "hash", id, "tool", arg[i:i+4])
}
}
func _storm_share(m *ice.Message, river, storm, name string, arg ...string) {
- m.Cmdy(ice.WEB_SHARE, ice.TYPE_STORM, name, storm, RIVER, river, arg)
+ m.Cmdy(web.SHARE, web.TYPE_STORM, name, storm, RIVER, river, arg)
}
func _storm_rename(m *ice.Message, river, storm string, name string) {
prefix := kit.Keys(kit.MDB_HASH, river, "tool", kit.MDB_HASH, storm)
- old := m.Conf(ice.CHAT_RIVER, kit.Keys(prefix, kit.MDB_META, kit.MDB_NAME))
+ old := m.Conf(RIVER, kit.Keys(prefix, kit.MDB_META, kit.MDB_NAME))
m.Log_MODIFY(RIVER, river, STORM, storm, "value", name, "old", old)
- m.Conf(ice.CHAT_RIVER, kit.Keys(prefix, kit.MDB_META, kit.MDB_NAME), name)
+ m.Conf(RIVER, kit.Keys(prefix, kit.MDB_META, kit.MDB_NAME), name)
}
func _storm_remove(m *ice.Message, river string, storm string) {
prefix := kit.Keys(kit.MDB_HASH, river, "tool")
- m.Richs(ice.CHAT_RIVER, kit.Keys(prefix), storm, func(value map[string]interface{}) {
+ m.Richs(RIVER, kit.Keys(prefix), storm, func(value map[string]interface{}) {
m.Log_REMOVE(RIVER, river, STORM, storm, "value", kit.Format(value))
})
- m.Conf(ice.CHAT_RIVER, kit.Keys(prefix, kit.MDB_HASH, storm), "")
+ m.Conf(RIVER, kit.Keys(prefix, kit.MDB_HASH, storm), "")
}
func init() {
diff --git a/core/code/code.go b/core/code/code.go
index df649a3c..f81957da 100644
--- a/core/code/code.go
+++ b/core/code/code.go
@@ -2,6 +2,7 @@ package code
import (
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
@@ -11,6 +12,12 @@ import (
"strings"
)
+const ( // CODE
+ INSTALL = "_install"
+ PREPARE = "_prepare"
+ PROJECT = "_project"
+)
+
var Index = &ice.Context{Name: "code", Help: "编程中心",
Configs: map[string]*ice.Config{
"install": {Name: "install", Help: "安装", Value: kit.Data("path", "usr/install",
@@ -38,27 +45,27 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
"login": {Name: "login", Help: "终端接入", Value: kit.Data()},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
}},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save("login")
}},
- ice.CODE_INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
p := path.Join(m.Conf("install", "meta.path"), path.Base(m.Conf("install", kit.Keys("meta", runtime.GOOS))))
// 下载
if _, e := os.Stat(p); e != nil {
m.Option("cmd_dir", m.Conf("install", "meta.path"))
- m.Cmd(ice.CLI_SYSTEM, "wget", m.Conf("install", kit.Keys("meta", runtime.GOOS)))
+ m.Cmd(cli.SYSTEM, "wget", m.Conf("install", kit.Keys("meta", runtime.GOOS)))
}
// 安装
m.Option("cmd_dir", "")
os.MkdirAll(m.Conf("install", kit.Keys("meta.target")), 0777)
- m.Cmdy(ice.CLI_SYSTEM, "tar", "xvf", p, "-C", m.Conf("install", kit.Keys("meta.target")))
+ m.Cmdy(cli.SYSTEM, "tar", "xvf", p, "-C", m.Conf("install", kit.Keys("meta.target")))
}},
- ice.CODE_PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
export := []string{}
kit.Fetch(m.Confv("install", "meta.export"), func(key string, val string) {
export = append(export, key+"="+val)
@@ -70,7 +77,7 @@ export PATH=$GOBIN:$GOROOT/bin:$PATH
export %s
`, kit.Path(m.Conf("install", kit.Keys("meta.target")), "go"), kit.Path("src"), kit.Path("bin"), strings.Join(export, " ")))
}},
- ice.CODE_PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
"install": {Name: "install", Help: "安装", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@@ -89,17 +96,17 @@ export %s
// 编译目标
main := kit.Select("src/main.go", arg, 2)
- arch := kit.Select(m.Conf(ice.CLI_RUNTIME, "host.GOARCH"), arg, 1)
- goos := kit.Select(m.Conf(ice.CLI_RUNTIME, "host.GOOS"), arg, 0)
+ arch := kit.Select(m.Conf(cli.RUNTIME, "host.GOARCH"), arg, 1)
+ goos := kit.Select(m.Conf(cli.RUNTIME, "host.GOOS"), arg, 0)
file := path.Join(m.Conf(cmd, "meta.path"), kit.Keys("ice", goos, arch))
// 编译参数
m.Optionv("cmd_env", "GOCACHE", os.Getenv("GOCACHE"), "HOME", os.Getenv("HOME"),
"GOARCH", arch, "GOOS", goos, "CGO_ENABLED", "0")
- m.Cmd(ice.CLI_SYSTEM, "go", "build", "-o", file, main)
+ m.Cmd(cli.SYSTEM, "go", "build", "-o", file, main)
// 编译记录
- m.Cmdy(ice.WEB_STORY, ice.STORY_CATCH, "bin", file)
+ m.Cmdy(web.STORY, web.CATCH, "bin", file)
m.Logs(ice.LOG_EXPORT, "source", main, "target", file)
}},
"publish": {Name: "publish [source]", Help: "发布", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@@ -112,7 +119,7 @@ export %s
if s, e := os.Stat(arg[0]); m.Assert(e) && s.IsDir() {
// 发布目录
p := path.Base(arg[0]) + ".tar.gz"
- m.Cmd(ice.CLI_SYSTEM, "tar", "-zcf", p, arg[0])
+ m.Cmd(cli.SYSTEM, "tar", "-zcf", p, arg[0])
defer func() { os.Remove(p) }()
arg[0] = p
}
@@ -124,7 +131,7 @@ export %s
os.Link(arg[0], target)
// 发布记录
- m.Cmdy(ice.WEB_STORY, ice.STORY_CATCH, "bin", target)
+ m.Cmdy(web.STORY, web.CATCH, "bin", target)
m.Logs(ice.LOG_EXPORT, "source", arg[0], "target", target)
}},
"upgrade": {Name: "upgrade which", Help: "升级", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@@ -132,20 +139,20 @@ export %s
m.Grows(cmd, kit.Keys(kit.MDB_HASH, kit.Select("system", arg, 0)), "", "", func(index int, value map[string]interface{}) {
if value["file"] == "ice.bin" {
// 程序文件
- value["file"] = kit.Keys("ice", m.Conf(ice.CLI_RUNTIME, "host.GOOS"), m.Conf(ice.CLI_RUNTIME, "host.GOARCH"))
+ value["file"] = kit.Keys("ice", m.Conf(cli.RUNTIME, "host.GOOS"), m.Conf(cli.RUNTIME, "host.GOARCH"))
exit = true
}
// 下载文件
- h := m.Cmdx(ice.WEB_SPIDE, "dev", "cache", "GET", "/publish/"+kit.Format(value["file"]))
+ h := m.Cmdx(web.SPIDE, "dev", "cache", "GET", "/publish/"+kit.Format(value["file"]))
if h == "" {
exit = false
return
}
// 升级记录
- m.Cmd(ice.WEB_STORY, "add", "bin", value["path"], h)
- m.Cmd(ice.WEB_STORY, ice.STORY_WATCH, h, value["path"])
+ m.Cmd(web.STORY, "add", "bin", value["path"], h)
+ m.Cmd(web.STORY, web.SHOW, h, value["path"])
os.Chmod(kit.Format(value["path"]), 0777)
})
if exit {
@@ -187,7 +194,7 @@ export %s
return
}
- you := m.Conf(ice.WEB_SHARE, kit.Keys(kit.MDB_HASH, m.Option("share"), "name"))
+ you := m.Conf(web.SHARE, kit.Keys(kit.MDB_HASH, m.Option("share"), "name"))
// 添加会话
h := m.Rich(cmd, nil, kit.Dict(
"type", kit.Select("zsh", arg, 1),
diff --git a/core/code/inner.go b/core/code/inner.go
index f11f8ab8..428cf5a8 100644
--- a/core/code/inner.go
+++ b/core/code/inner.go
@@ -2,6 +2,7 @@ package code
import (
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
@@ -90,7 +91,7 @@ func _inner_show(m *ice.Message, name string) {
p := _inner_ext(name)
if ls := kit.Simple(m.Confv(INNER, kit.Keys("meta.show", p))); len(ls) > 0 {
- m.Cmdy(ice.CLI_SYSTEM, ls, name)
+ m.Cmdy(cli.SYSTEM, ls, name)
m.Set(ice.MSG_APPEND)
m.Cmd(web.FAVOR, "inner.run", "shell", name, m.Result())
return
@@ -141,12 +142,12 @@ func init() {
}, Action: map[string]*ice.Action{
"cmd": {Name: "cmd arg", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
if m.Cmdy(kit.Split(arg[0])); !m.Hand {
- m.Cmdy(ice.CLI_SYSTEM, kit.Split(arg[0]))
+ m.Cmdy(cli.SYSTEM, kit.Split(arg[0]))
}
}},
"favor": {Name: "favor", Help: "收藏", Hand: func(m *ice.Message, arg ...string) {
- m.Cmd(ice.WEB_FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) {
+ m.Cmd(web.FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) {
m.Push("image", kit.Format(`
`,
value["name"], value["text"], value["extra.poster"]))
m.Push("video", kit.Format(``, value["text"]))
diff --git a/core/code/pprof.go b/core/code/pprof.go
index 2d1618cf..1a051f2f 100644
--- a/core/code/pprof.go
+++ b/core/code/pprof.go
@@ -70,26 +70,26 @@ func _pprof_show(m *ice.Message, zone string, id string) {
m.Cmd(web.FAVOR, favor, kit.MIME_FILE, bin, val[BINNARY])
// 性能分析
- msg := m.Cmd(ice.WEB_SPIDE, "self", "cache", "GET", kit.Select("/code/pprof/profile", val[SERVICE]), "seconds", kit.Select("5", kit.Format(val[SECONDS])))
+ msg := m.Cmd(web.SPIDE, "self", "cache", "GET", kit.Select("/code/pprof/profile", val[SERVICE]), "seconds", kit.Select("5", kit.Format(val[SECONDS])))
m.Cmd(web.FAVOR, favor, PPROF, msg.Append(kit.MDB_TEXT), kit.Keys(zone, "pd.gz"))
// 结果摘要
cmd := kit.Simple(m.Confv(PPROF, "meta.pprof"), "-text", val[BINNARY], msg.Append(kit.MDB_TEXT))
- res := strings.Split(m.Cmdx(ice.CLI_SYSTEM, cmd), "\n")
+ res := strings.Split(m.Cmdx(cli.SYSTEM, cmd), "\n")
if len(res) > 20 {
res = res[:20]
}
- m.Cmd(web.FAVOR, favor, ice.TYPE_SHELL, strings.Join(cmd, " "), strings.Join(res, "\n"))
- list = append(list, ice.TYPE_SHELL+": "+strings.Join(cmd, " "), strings.Join(res, "\n"))
+ m.Cmd(web.FAVOR, favor, web.TYPE_SHELL, strings.Join(cmd, " "), strings.Join(res, "\n"))
+ list = append(list, web.TYPE_SHELL+": "+strings.Join(cmd, " "), strings.Join(res, "\n"))
// 结果展示
- p := kit.Format("%s:%s", m.Conf(ice.WEB_SHARE, "meta.host"), m.Cmdx("tcp.getport"))
+ p := kit.Format("%s:%s", m.Conf(web.SHARE, "meta.host"), m.Cmdx("tcp.getport"))
m.Option(cli.CMD_STDOUT, "var/daemon/stdout")
m.Option(cli.CMD_STDERR, "var/daemon/stderr")
m.Cmd(cli.DAEMON, m.Confv(PPROF, "meta.pprof"), "-http="+p, val[BINNARY], msg.Append(kit.MDB_TEXT))
url := "http://" + p + "/ui/top"
- m.Cmd(web.FAVOR, favor, ice.TYPE_SPIDE, url, msg.Append(kit.MDB_TEXT))
+ m.Cmd(web.FAVOR, favor, web.TYPE_SPIDE, url, msg.Append(kit.MDB_TEXT))
m.Set(ice.MSG_RESULT).Echo(url).Echo(" \n").Echo("\n")
m.Echo(strings.Join(list, "\n")).Echo("\n")
diff --git a/core/code/video.go b/core/code/video.go
index 345cc0a8..152effea 100644
--- a/core/code/video.go
+++ b/core/code/video.go
@@ -2,6 +2,7 @@ package code
import (
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
"github.com/nareix/joy4/av"
@@ -40,7 +41,7 @@ func init() {
}
}},
"video": {Name: "video", Help: "视频", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Cmd(ice.WEB_FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) {
+ m.Cmd(web.FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) {
m.Echo(``, value["text"])
})
}},
diff --git a/core/mall/mall.go b/core/mall/mall.go
index 2d825ec5..8dda26ca 100644
--- a/core/mall/mall.go
+++ b/core/mall/mall.go
@@ -47,10 +47,10 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
))},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
}},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save("asset")
}},
@@ -295,7 +295,7 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心",
})
})
m.Log(ice.LOG_EXPORT, "%s", p)
- m.Cmdy(ice.WEB_STORY, "catch", "csv", p)
+ m.Cmdy(web.STORY, "catch", "csv", p)
}
case "load":
diff --git a/core/shy.go b/core/shy.go
index 88bd58be..fb8c7435 100644
--- a/core/shy.go
+++ b/core/shy.go
@@ -1,15 +1,3 @@
package shy
-import (
- _ "github.com/shylinux/icebergs/base"
-
- _ "github.com/shylinux/icebergs/core/code"
-
- _ "github.com/shylinux/icebergs/core/wiki"
-
- _ "github.com/shylinux/icebergs/core/chat"
-
- _ "github.com/shylinux/icebergs/core/team"
-
- _ "github.com/shylinux/icebergs/core/mall"
-)
+import ()
diff --git a/core/team/team.go b/core/team/team.go
index 204803c6..2520778a 100644
--- a/core/team/team.go
+++ b/core/team/team.go
@@ -207,7 +207,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
MISS: {Name: "miss", Help: "miss", Value: kit.Data(kit.MDB_SHORT, ZONE)},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
if s == c {
return
@@ -216,7 +216,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
})
m.Load()
}},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(TASK) }},
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(TASK) }},
PLAN: {Name: "plan scale:select=day|week|month|year|long begin_time=@date end_time=@date auto", Help: "计划", Meta: kit.Dict(
"display", "/plugin/local/team/plan.js", "detail", []string{StatusPrepare, StatusProcess, StatusCancel, StatusFinish},
@@ -246,7 +246,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
begin_time := time.Now()
if len(arg) > 1 {
- begin_time, _ = time.ParseInLocation(ice.ICE_TIME, arg[1], time.Local)
+ begin_time, _ = time.ParseInLocation(ice.MOD_TIME, arg[1], time.Local)
}
end_time := begin_time
@@ -275,7 +275,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
m.Richs(TASK, nil, kit.Select(kit.MDB_FOREACH, m.Option(ZONE)), func(key string, val map[string]interface{}) {
zone := kit.Format(kit.Value(val, "meta.zone"))
m.Grows(TASK, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
- begin, _ := time.ParseInLocation(ice.ICE_TIME, kit.Format(value[BEGIN_TIME]), time.Local)
+ begin, _ := time.ParseInLocation(ice.MOD_TIME, kit.Format(value[BEGIN_TIME]), time.Local)
if begin_time.Before(begin) && begin.Before(end_time) {
m.Push(zone, value)
m.Push(ZONE, zone)
diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go
index 43eafd24..4132b317 100644
--- a/core/wiki/wiki.go
+++ b/core/wiki/wiki.go
@@ -3,6 +3,7 @@ package wiki
import (
ice "github.com/shylinux/icebergs"
_ "github.com/shylinux/icebergs/base"
+ "github.com/shylinux/icebergs/base/ssh"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
@@ -46,10 +47,10 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
"feel": {Name: "feel", Help: "影音媒体", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.(png|jpg|JPG|MOV|m4v)")},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
}},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save("feel")
}},
@@ -198,7 +199,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
"display", "local/wiki/feel", "detail", []string{"标签", "删除"},
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if m.Option("_action") == "上传" {
- m.Cmd(ice.WEB_CACHE, "watch", m.Option("_data"), path.Join(m.Option("name"), m.Option("_name")))
+ m.Cmd(web.CACHE, "watch", m.Option("_data"), path.Join(m.Option("name"), m.Option("_name")))
return
}
@@ -296,7 +297,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
m.Cmd("word", "action", "追加", arg)
m.Option("scan_mode", "scan")
- m.Cmdy(ice.SSH_SOURCE, path.Join(m.Conf("word", "meta.path"), arg[0]))
+ m.Cmdy(ssh.SOURCE, path.Join(m.Conf("word", "meta.path"), arg[0]))
}},
},
}
diff --git a/core/wiki/word.go b/core/wiki/word.go
index 7779c4d5..38ae60d8 100644
--- a/core/wiki/word.go
+++ b/core/wiki/word.go
@@ -2,6 +2,9 @@ package wiki
import (
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/ctx"
+ "github.com/shylinux/icebergs/base/ssh"
kit "github.com/shylinux/toolkits"
"fmt"
@@ -161,9 +164,9 @@ func init() {
cmds := kit.Split(arg[1])
m.Search(cmds[0], func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
if ls := strings.Split(cmds[0], "."); len(ls) > 1 {
- m.Cmd(ice.CTX_COMMAND, strings.Join(ls[:len(ls)-1], "."), key)
+ m.Cmd(ctx.COMMAND, strings.Join(ls[:len(ls)-1], "."), key)
} else {
- m.Cmd(ice.CTX_COMMAND, key)
+ m.Cmd(ctx.COMMAND, key)
}
if data["feature"], data["inputs"] = cmd.Meta, cmd.List; len(cmd.List) == 0 {
data["inputs"] = m.Confv("field", "meta.some.simple.inputs")
@@ -192,7 +195,7 @@ func init() {
// 渲染引擎
m.Option("input", strings.Join(arg[1:], " "))
- m.Option("output", m.Cmdx(ice.CLI_SYSTEM, "sh", "-c", m.Option("input")))
+ m.Option("output", m.Cmdx(cli.SYSTEM, "sh", "-c", m.Option("input")))
m.Render(ice.RENDER_TEMPLATE, m.Conf(SHELL, "meta.template"))
}},
@@ -209,11 +212,11 @@ func init() {
}
// 解析脚本
- m.Option(ice.WEB_TMPL, "raw")
+ m.Option("render", "raw")
m.Optionv(TITLE, map[string]int{})
m.Optionv("menu", map[string]interface{}{"list": []interface{}{}})
m.Optionv(ice.MSG_ALIAS, m.Confv(WORD, "meta.alias"))
- m.Set(ice.MSG_RESULT).Cmdy(ice.SSH_SOURCE, path.Join(m.Conf(WORD, "meta.path"), arg[0]))
+ m.Set(ice.MSG_RESULT).Cmdy(ssh.SOURCE, path.Join(m.Conf(WORD, "meta.path"), arg[0]))
}},
},
}, nil)
diff --git a/data.go b/data.go
index adf12d7b..68b34a21 100644
--- a/data.go
+++ b/data.go
@@ -2,480 +2,39 @@ package ice
import (
kit "github.com/shylinux/toolkits"
-
- "encoding/csv"
- "encoding/json"
- "fmt"
- "io/ioutil"
- "math/rand"
- "os"
- "path"
- "sort"
- "strings"
+ "github.com/shylinux/toolkits/miss"
)
-const (
- ZONE = "zone"
-)
-
-func (m *Message) Prefile(favor string, id string) map[string]string {
- res := map[string]string{}
- m.Option("render", "")
- m.Option("_action", "")
- m.Cmd(WEB_FAVOR, kit.Select(m.Option("favor"), favor), id).Table(func(index int, value map[string]string, head []string) {
- res[value["key"]] = value["value"]
- })
-
- res["content"] = m.Cmdx(CLI_SYSTEM, "sed", "-n", kit.Format("%d,%dp", kit.Int(res["extra.row"]), kit.Int(res["extra.row"])+3), res["extra.buf"])
- return res
-}
-func (m *Message) Prefix(arg ...string) string {
- return kit.Keys(m.Cap(CTX_FOLLOW), arg)
-}
-func (m *Message) Save(arg ...string) *Message {
- list := []string{}
- for _, k := range arg {
- list = append(list, kit.Keys(m.Cap(CTX_FOLLOW), k))
- }
- m.Cmd(CTX_CONFIG, "save", kit.Keys(m.Cap(CTX_FOLLOW), "json"), list)
- return m
-}
-func (m *Message) Load(arg ...string) *Message {
- list := []string{}
- for _, k := range arg {
- list = append(list, kit.Keys(m.Cap(CTX_FOLLOW), k))
- }
- m.Cmd(CTX_CONFIG, "load", kit.Keys(m.Cap(CTX_FOLLOW), "json"), list)
- return m
-}
-
func (m *Message) Richs(key string, chain interface{}, raw interface{}, cb interface{}) (res map[string]interface{}) {
- // 数据结构
cache := m.Confm(key, chain)
if cache == nil {
return nil
}
- meta, ok := cache[kit.MDB_META].(map[string]interface{})
- hash, ok := cache[kit.MDB_HASH].(map[string]interface{})
- if !ok {
- return nil
- }
-
- h := kit.Format(raw)
- switch h {
- case "*":
- // 全部遍历
- switch cb := cb.(type) {
- case func(string, string):
- for k, v := range hash {
- cb(k, kit.Format(v))
- }
- case func(string, map[string]interface{}):
- for k, v := range hash {
- res = v.(map[string]interface{})
- cb(k, res)
- }
- }
- return res
- case "%":
- // 随机选取
- if len(hash) > 0 {
- list := []string{}
- for k := range hash {
- list = append(list, k)
- }
- h = list[rand.Intn(len(list))]
- res, _ = hash[h].(map[string]interface{})
- }
- default:
- // 单个查询
- if res, ok = hash[h].(map[string]interface{}); !ok {
- switch kit.Format(kit.Value(meta, kit.MDB_SHORT)) {
- case "", "uniq":
- default:
- hh := kit.Hashs(h)
- if res, ok = hash[hh].(map[string]interface{}); ok {
- h = hh
- break
- }
-
- prefix := path.Join(kit.Select(m.Conf(WEB_CACHE, "meta.store"), kit.Format(meta["store"])), key)
- for _, k := range []string{h, hh} {
- if f, e := os.Open(path.Join(prefix, kit.Keys(k, "json"))); e == nil {
- defer f.Close()
- if b, e := ioutil.ReadAll(f); e == nil {
- if json.Unmarshal(b, &res) == e {
- h = k
- m.Log(LOG_IMPORT, "%s/%s.json", prefix, k)
- break
- }
- }
- }
- }
- }
- }
- }
-
- // 返回数据
- if res != nil {
- switch cb := cb.(type) {
- case func(map[string]interface{}):
- cb(res)
- case func(string, map[string]interface{}):
- cb(h, res)
- }
- }
- return res
+ return miss.Richs(m.Confm("miss", nil), kit.Keys(key, chain), cache, raw, cb)
}
func (m *Message) Rich(key string, chain interface{}, data interface{}) string {
- // 数据结构
cache := m.Confm(key, chain)
if cache == nil {
cache = map[string]interface{}{}
m.Confv(key, chain, cache)
}
- meta, ok := cache[kit.MDB_META].(map[string]interface{})
- if !ok {
- meta = map[string]interface{}{}
- cache[kit.MDB_META] = meta
- }
- hash, ok := cache[kit.MDB_HASH].(map[string]interface{})
- if !ok {
- hash = map[string]interface{}{}
- cache[kit.MDB_HASH] = hash
- }
-
- // 通用数据
- prefix := kit.Select("", "meta.", kit.Value(data, "meta") != nil)
- if kit.Value(data, prefix+kit.MDB_TIME) == nil {
- kit.Value(data, prefix+kit.MDB_TIME, m.Time())
- }
-
- // 生成键值
- h := ""
- switch short := kit.Format(kit.Value(meta, kit.MDB_SHORT)); short {
- case "":
- h = kit.ShortKey(hash, 6)
- case "uniq":
- h = kit.Hashs("uniq")
- case "data":
- h = kit.Hashs(kit.Format(data))
- default:
- if kit.Value(data, "meta") != nil {
- h = kit.Hashs(kit.Format(kit.Value(data, "meta."+short)))
- } else {
- h = kit.Hashs(kit.Format(kit.Value(data, short)))
- }
- }
-
- // 添加数据
- if hash[h] = data; len(hash) >= kit.Int(kit.Select(m.Conf(WEB_CACHE, "meta.limit"), kit.Format(meta["limit"]))) {
- least := kit.Int(kit.Select(m.Conf(WEB_CACHE, "meta.least"), kit.Format(meta["least"])))
-
- // 时间淘汰
- list := []int{}
- for _, v := range hash {
- list = append(list, kit.Time(kit.Format(kit.Value(v, "time"))))
- }
- sort.Ints(list)
- dead := list[len(list)-1-least]
-
- prefix := path.Join(kit.Select(m.Conf(WEB_CACHE, "meta.store"), kit.Format(meta["store"])), key)
- for k, v := range hash {
- if kit.Time(kit.Format(kit.Value(v, "time"))) > dead {
- break
- }
-
- name := path.Join(prefix, kit.Keys(k, "json"))
- if f, p, e := kit.Create(name); m.Assert(e) {
- defer f.Close()
- // 保存数据
- if n, e := f.WriteString(kit.Format(v)); m.Assert(e) {
- m.Log(LOG_EXPORT, "%s: %d", p, n)
- delete(hash, k)
- }
- }
- }
- }
-
- return h
+ return miss.Rich(m.Confm("miss", nil), kit.Keys(key, chain), cache, data)
}
func (m *Message) Grow(key string, chain interface{}, data interface{}) int {
- // 数据结构
cache := m.Confm(key, chain)
if cache == nil {
cache = map[string]interface{}{}
m.Confv(key, chain, cache)
}
- meta, ok := cache[kit.MDB_META].(map[string]interface{})
- if !ok {
- meta = map[string]interface{}{}
- cache[kit.MDB_META] = meta
- }
- list, _ := cache[kit.MDB_LIST].([]interface{})
-
- // 通用数据
- id := kit.Int(meta["count"]) + 1
- prefix := kit.Select("", "meta.", kit.Value(data, "meta") != nil)
- if kit.Value(data, prefix+kit.MDB_ID, id); kit.Value(data, prefix+kit.MDB_TIME) == nil {
- kit.Value(data, prefix+kit.MDB_TIME, kit.Select(m.Time(), m.Option("time")))
- }
-
- // 添加数据
- list = append(list, data)
- cache[kit.MDB_LIST] = list
- meta["count"] = id
-
- // 保存数据
- if len(list) >= kit.Int(kit.Select(m.Conf(WEB_CACHE, "meta.limit"), kit.Format(meta["limit"]))) {
- least := kit.Int(kit.Select(m.Conf(WEB_CACHE, "meta.least"), kit.Format(meta["least"])))
-
- record, _ := meta["record"].([]interface{})
-
- // 文件命名
- prefix := path.Join(kit.Select(m.Conf(WEB_CACHE, "meta.store"), kit.Format(meta["store"])), key)
- name := path.Join(prefix, kit.Keys(kit.Select("list", chain), "csv"))
- if len(record) > 0 {
- name = kit.Format(kit.Value(record, kit.Keys(len(record)-1, "file")))
- if s, e := os.Stat(name); e == nil {
- if s.Size() > kit.Int64(kit.Select(m.Conf(WEB_CACHE, "meta.fsize"), kit.Format(meta["fsize"]))) {
- name = fmt.Sprintf("%s/%s_%d.csv", prefix, kit.Select("list", chain), kit.Int(meta["offset"]))
- }
- }
- }
-
- // 打开文件
- f, e := os.OpenFile(name, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
- if e != nil {
- f, _, e = kit.Create(name)
- m.Info("%s.%v create: %s", key, chain, name)
- } else {
- m.Info("%s.%v append: %s", key, chain, name)
- }
- defer f.Close()
- s, e := f.Stat()
- m.Assert(e)
-
- // 保存表头
- keys := []string{}
- w := csv.NewWriter(f)
- if s.Size() == 0 {
- for k := range list[0].(map[string]interface{}) {
- keys = append(keys, k)
- }
- sort.Strings(keys)
- w.Write(keys)
- m.Info("write head: %v", keys)
- w.Flush()
- s, e = f.Stat()
- } else {
- r := csv.NewReader(f)
- keys, e = r.Read()
- m.Info("read head: %v", keys)
- }
-
- // 创建索引
- count := len(list) - least
- offset := kit.Int(meta["offset"])
- meta["record"] = append(record, map[string]interface{}{
- "time": m.Time(), "offset": offset, "count": count,
- "file": name, "position": s.Size(),
- })
-
- // 保存数据
- for i, v := range list {
- if i >= count {
- break
- }
-
- val := v.(map[string]interface{})
-
- values := []string{}
- for _, k := range keys {
- values = append(values, kit.Format(val[k]))
- }
- w.Write(values)
-
- if i < least {
- list[i] = list[count+i]
- }
- }
-
- m.Log(LOG_INFO, "%s.%v save %s offset %v+%v", key, chain, name, offset, count)
- meta["offset"] = offset + count
- list = list[count:]
- cache[kit.MDB_LIST] = list
- w.Flush()
- }
- return id
+ return miss.Grow(m.Confm("miss", nil), kit.Keys(key, chain), cache, data)
}
func (m *Message) Grows(key string, chain interface{}, match string, value string, cb interface{}) map[string]interface{} {
- // 数据结构
cache := m.Confm(key, chain)
if cache == nil {
return nil
}
- meta, ok := cache[kit.MDB_META].(map[string]interface{})
- list, ok := cache[kit.MDB_LIST].([]interface{})
- if !ok {
- return nil
- }
-
- // 数据范围
- offend := kit.Int(kit.Select("0", m.Option("cache.offend")))
- limit := kit.Int(kit.Select("10", m.Option("cache.limit")))
- current := kit.Int(meta["offset"])
- end := current + len(list) - offend
- begin := end - limit
- switch limit {
- case -1:
- begin = current
- case -2:
- begin = 0
- }
-
- if match == kit.MDB_ID {
- begin, end = kit.Int(value)-1, kit.Int(value)
- match, value = "", ""
- }
-
- order := 0
- if begin < current {
- // 读取文件
- // m.Log(LOG_INFO, "%s.%v read %v-%v from %v-%v", key, chain, begin, end, current, current+len(list))
- store, _ := meta["record"].([]interface{})
- for s := len(store) - 1; s > -1; s-- {
- item, _ := store[s].(map[string]interface{})
- line := kit.Int(item["offset"])
- m.Logs(LOG_INFO, "action", "check", "record", s, "offset", line, "count", item["count"])
- if begin < line && s > 0 {
- if kit.Int(item["count"]) != 0 {
- s -= (line - begin) / kit.Int(item["count"])
- }
- // 向后查找
- continue
- }
-
- for ; begin < end && s < len(store); s++ {
- item, _ := store[s].(map[string]interface{})
- name := kit.Format(item["file"])
- pos := kit.Int(item["position"])
- offset := kit.Int(item["offset"])
- if offset+kit.Int(item["count"]) <= begin {
- m.Logs(LOG_INFO, "action", "check", "record", s, "offset", line, "count", item["count"])
- // 向前查找
- continue
- }
-
- if f, e := os.Open(name); m.Assert(e) {
- defer f.Close()
- // 打开文件
- r := csv.NewReader(f)
- heads, _ := r.Read()
- m.Logs(LOG_IMPORT, "head", heads)
-
- f.Seek(int64(pos), os.SEEK_SET)
- r = csv.NewReader(f)
- for i := offset; i < end; i++ {
- lines, e := r.Read()
- if e != nil {
- m.Log(LOG_IMPORT, "load head %v", e)
- break
- }
- if i < begin {
- m.Logs(LOG_INFO, "action", "skip", "offset", i)
- continue
- }
-
- // 读取数据
- item := map[string]interface{}{}
- for i := range heads {
- if heads[i] == "extra" {
- item[heads[i]] = kit.UnMarshal(lines[i])
- } else {
- item[heads[i]] = lines[i]
- }
- }
- m.Logs(LOG_IMPORT, "offset", i, "type", item["type"], "name", item["name"], "text", item["text"])
-
- if match == "" || strings.Contains(kit.Format(item[match]), value) {
- // 匹配成功
- switch cb := cb.(type) {
- case func(int, map[string]interface{}):
- cb(order, item)
- case func(int, map[string]interface{}) bool:
- if cb(order, item) {
- return meta
- }
- }
- order++
- }
- begin = i + 1
- }
- }
- }
- break
- }
- }
-
- if begin < current {
- begin = current
- }
- for i := begin - current; i < end-current; i++ {
- // 读取缓存
- if match == "" || strings.Contains(kit.Format(kit.Value(list[i], match)), value) {
- switch cb := cb.(type) {
- case func(int, map[string]interface{}):
- cb(order, list[i].(map[string]interface{}))
- case func(int, map[string]interface{}) bool:
- if cb(order, list[i].(map[string]interface{})) {
- return meta
- }
- }
- order++
- }
- }
- return meta
-}
-func (m *Message) Show(cmd string, arg ...string) bool {
- if len(arg) == 0 {
- // 日志分类
- m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) {
- m.Push(key, value["meta"])
- })
- return true
- }
- if len(arg) < 3 {
- if m.Richs(cmd, nil, arg[0], func(key string, val map[string]interface{}) {
- if len(arg) == 1 {
- // 日志列表
- m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
- m.Push(key, value)
- })
- return
- }
- // 日志详情
- m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "id", arg[1], func(index int, value map[string]interface{}) {
- m.Push("detail", value)
- })
- }) != nil {
- return true
- }
- }
- return false
-}
-
-func (m *Message) RichCreate(prefix string, zone string, arg ...string) {
-}
-func (m *Message) RichInsert(prefix string, zone string, kind, name, text string, data []string, arg ...string) {
-}
-func ListLook(name ...string) []interface{} {
- list := []interface{}{}
- for _, k := range name {
- list = append(list, kit.MDB_INPUT, "text", "name", k, "action", "auto")
- }
- return kit.List(append(list,
- kit.MDB_INPUT, "button", "name", "查看", "action", "auto",
- kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
- )...)
+ return miss.Grows(m.Confm("miss", nil), kit.Keys(key, chain), cache,
+ kit.Int(kit.Select("0", m.Option("cache.offend"))),
+ kit.Int(kit.Select("10", m.Option("cache.limit"))),
+ match, value, cb)
}
diff --git a/exec.go b/exec.go
index 94c6f125..620e1704 100644
--- a/exec.go
+++ b/exec.go
@@ -1,14 +1,13 @@
package ice
import (
+ kit "github.com/shylinux/toolkits"
+
"errors"
"fmt"
"io"
- "runtime"
- "strings"
"time"
- kit "github.com/shylinux/toolkits"
"github.com/shylinux/toolkits/task"
)
@@ -18,15 +17,13 @@ func (m *Message) TryCatch(msg *Message, safe bool, hand ...func(msg *Message))
case io.EOF:
case nil:
default:
- _, file, line, _ := runtime.Caller(3)
- if list := strings.Split(file, "/"); len(list) > 2 {
- file = strings.Join(list[len(list)-2:], "/")
- }
- m.Log(LOG_WARN, "catch: %s %s:%d", e, file, line)
+ fileline := kit.FileLine(3, 2)
+ m.Log(LOG_WARN, "catch: %s", e, fileline)
m.Log(LOG_INFO, "chain: %s", msg.Format("chain"))
- m.Log(LOG_WARN, "catch: %s %s:%d", e, file, line)
+ m.Log(LOG_WARN, "catch: %s", e, fileline)
m.Log(LOG_INFO, "stack: %s", msg.Format("stack"))
- if m.Log(LOG_WARN, "catch: %s %s:%d", e, file, line); len(hand) > 1 {
+ m.Log(LOG_WARN, "catch: %s", e, fileline)
+ if len(hand) > 1 {
// 捕获异常
m.TryCatch(msg, safe, hand[1:]...)
} else if !safe {
@@ -50,10 +47,10 @@ func (m *Message) Assert(arg interface{}) bool {
if arg == true {
return true
}
+ case error:
+ panic(arg)
}
-
- // 抛出异常
- panic(errors.New(fmt.Sprintf("error %v", arg)))
+ panic(errors.New(fmt.Sprintf("error: %v", arg)))
}
func (m *Message) Sleep(arg string) *Message {
time.Sleep(kit.Duration(arg))
diff --git a/go.mod b/go.mod
index a2dd0311..0f1b88b8 100644
--- a/go.mod
+++ b/go.mod
@@ -3,6 +3,7 @@ module github.com/shylinux/icebergs
go 1.13
require (
+ github.com/gomarkdown/markdown v0.0.0-20200609195525-3f9352745725
github.com/gorilla/websocket v1.4.1
github.com/nareix/joy4 v0.0.0-20200507095837-05a4ffbb5369
github.com/shylinux/toolkits v0.1.5
diff --git a/go.sum b/go.sum
index 1f68e8c1..1c75d9df 100644
--- a/go.sum
+++ b/go.sum
@@ -1,3 +1,5 @@
+github.com/gomarkdown/markdown v0.0.0-20200609195525-3f9352745725 h1:X6sZdr+t2E2jwajTy/FfXbmAKPFTYxEq9hiFgzMiuPQ=
+github.com/gomarkdown/markdown v0.0.0-20200609195525-3f9352745725/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU=
github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s=
github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
@@ -14,3 +16,4 @@ github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086 h1:RYiqpb2ii2Z6J4x
github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo=
github.com/tuotoo/qrcode v0.0.0-20190222102259-ac9c44189bf2 h1:BWVtt2VBY+lmVDu9MGKqLGKl04B+iRHcrW1Ptyi/8tg=
github.com/tuotoo/qrcode v0.0.0-20190222102259-ac9c44189bf2/go.mod h1:lPnW9HVS0vJdeYyQtOvIvlXgZPNhUAhwz+z5r8AJk0Y=
+golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
diff --git a/init.go b/init.go
index e4a5acdf..e0b4bb22 100644
--- a/init.go
+++ b/init.go
@@ -4,7 +4,10 @@ import (
kit "github.com/shylinux/toolkits"
"github.com/shylinux/toolkits/conf"
"github.com/shylinux/toolkits/log"
+ "github.com/shylinux/toolkits/miss"
+ "github.com/shylinux/toolkits/task"
+ "errors"
"fmt"
"os"
"strings"
@@ -79,25 +82,36 @@ var Index = &Context{Name: "ice", Help: "冰山模块",
"",
},
}},
+ "miss": {Value: kit.Dict(
+ kit.MDB_STORE, "var/data",
+ kit.MDB_FSIZE, "200000",
+ kit.MDB_LIMIT, "110",
+ kit.MDB_LEAST, "100",
+ )},
+ "task": {Value: kit.Dict(
+ kit.MDB_STORE, "var/data",
+ kit.MDB_LIMIT, "110",
+ kit.MDB_LEAST, "100",
+ )},
},
Commands: map[string]*Command{
- ICE_INIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
- defer m.Cost(ICE_INIT)
+ CTX_INIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
+ defer m.Cost(CTX_INIT)
m.Travel(func(p *Context, c *Context) {
- if cmd, ok := c.Commands[ICE_INIT]; ok && p != nil {
- c.Run(m.Spawns(c), cmd, ICE_INIT, arg...)
+ if cmd, ok := c.Commands[CTX_INIT]; ok && p != nil {
+ c.cmd(m.Spawns(c), cmd, CTX_INIT, arg...)
}
})
}},
"init": {Name: "init", Help: "启动", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
- m.root.Cmd(ICE_INIT)
+ m.root.Cmd(CTX_INIT)
m.target.root.wg = &sync.WaitGroup{}
for _, k := range kit.Split(kit.Select("gdb,log,ssh,ctx", os.Getenv("ctx_mod"))) {
m.Start(k)
}
- m.Cmd(SSH_SOURCE, "etc/init.shy", "init.shy", "启动配置")
+ m.Cmd("ssh.source", "etc/init.shy", "init.shy", "启动配置")
m.Cmdy(arg)
}},
"help": {Name: "help", Help: "帮助", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
@@ -105,16 +119,16 @@ var Index = &Context{Name: "ice", Help: "冰山模块",
}},
"exit": {Name: "exit", Help: "结束", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
m.root.target.server.(*Frame).code = kit.Int(kit.Select("0", arg, 0))
- m.Cmd(SSH_SOURCE, "etc/exit.shy", "exit.shy", "退出配置")
+ m.Cmd("ssh.source", "etc/exit.shy", "exit.shy", "退出配置")
- m.root.Cmd(ICE_EXIT)
+ m.root.Cmd(CTX_EXIT)
}},
- ICE_EXIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
- defer m.Cost(ICE_EXIT)
+ CTX_EXIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
+ defer m.Cost(CTX_EXIT)
m.root.Travel(func(p *Context, c *Context) {
- if cmd, ok := c.Commands[ICE_EXIT]; ok && p != nil {
+ if cmd, ok := c.Commands[CTX_EXIT]; ok && p != nil {
m.TryCatch(m.Spawns(c), true, func(msg *Message) {
- c.Run(msg, cmd, ICE_EXIT, arg...)
+ c.cmd(msg, cmd, CTX_EXIT, arg...)
})
}
})
@@ -138,10 +152,13 @@ func Run(arg ...string) string {
arg = os.Args[1:]
}
if len(arg) == 0 {
- arg = append(arg, WEB_SPACE, "connect", "self")
+ arg = append(arg, "web.space", "connect", "self")
}
- log.Init(conf.New(nil))
+ conf := conf.New(nil)
+ task.Init(conf, 10)
+ miss.Init(conf)
+ log.Init(conf)
frame := &Frame{}
Index.root = Index
@@ -156,10 +173,22 @@ func Run(arg ...string) string {
}
if Pulse.Result() == "" {
- Pulse.Table()
+ Pulse.Table(nil)
}
fmt.Printf(Pulse.Result())
os.Exit(frame.code)
return ""
}
+
+var names = map[string]interface{}{}
+
+var ErrNameExists = errors.New("name already exists")
+
+func Name(name string, value interface{}) string {
+ if _, ok := names[name]; ok {
+ panic(ErrNameExists)
+ }
+ names[name] = value
+ return name
+}
diff --git a/info.go b/logs.go
similarity index 83%
rename from info.go
rename to logs.go
index 969b7199..ae420130 100644
--- a/info.go
+++ b/logs.go
@@ -1,11 +1,10 @@
package ice
import (
- kit "github.com/shylinux/toolkits"
+ "github.com/shylinux/toolkits"
"github.com/shylinux/toolkits/log"
"fmt"
- "os"
"runtime"
"strings"
)
@@ -33,25 +32,16 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message {
prefix, suffix = "\033[31m", "\033[0m"
}
+ // 文件行号
switch level {
case LOG_CMDS, LOG_INFO, LOG_WARN, "refer", "form":
default:
- _, file, line, _ := runtime.Caller(2)
- ls := strings.Split(file, "/")
- if len(ls) > 2 {
- ls = ls[len(ls)-2:]
- }
- suffix += fmt.Sprintf(" %s:%d", strings.Join(ls, "/"), line)
+ suffix += " " + kit.FileLine(3, 2)
}
- if os.Getenv("ctx_mod") != "" && m != nil {
- // 输出日志
- str := fmt.Sprintf("%s %02d %9s %s%s %s%s",
- m.time.Format(ICE_TIME), m.code, fmt.Sprintf("%4s->%-4s", m.source.Name, m.target.Name),
- prefix, level, str, suffix,
- )
- log.Info(str)
- }
+ // 输出日志
+ log.Info(fmt.Sprintf("%02d %9s %s%s %s%s", m.code, fmt.Sprintf("%4s->%-4s", m.source.Name, m.target.Name),
+ prefix, level, str, suffix))
return m
}
func (m *Message) Log(level string, str string, arg ...interface{}) *Message {
@@ -86,13 +76,6 @@ func (m *Message) Error(err bool, str string, arg ...interface{}) bool {
}
return false
}
-func (m *Message) Trace(key string, str string, arg ...interface{}) *Message {
- if m.Options(key) {
- m.Echo("trace: ").Echo(str, arg...)
- return m.log(LOG_TRACE, str, arg...)
- }
- return m
-}
func (m *Message) Debug(str string, arg ...interface{}) {
m.log(LOG_DEBUG, str, arg...)
}
diff --git a/meta.go b/meta.go
index 396ec19c..07378dab 100644
--- a/meta.go
+++ b/meta.go
@@ -236,25 +236,22 @@ func (m *Message) Sort(key string, arg ...string) *Message {
}
return m
}
-func (m *Message) Table(cbs ...interface{}) *Message {
- if len(cbs) > 0 {
- switch cb := cbs[0].(type) {
- case func(int, map[string]string, []string):
- nrow := 0
- for _, k := range m.meta[MSG_APPEND] {
- if len(m.meta[k]) > nrow {
- nrow = len(m.meta[k])
- }
+func (m *Message) Table(cbs ...func(index int, value map[string]string, head []string)) *Message {
+ if len(cbs) > 0 && cbs[0] != nil {
+ nrow := 0
+ for _, k := range m.meta[MSG_APPEND] {
+ if len(m.meta[k]) > nrow {
+ nrow = len(m.meta[k])
}
+ }
- for i := 0; i < nrow; i++ {
- line := map[string]string{}
- for _, k := range m.meta[MSG_APPEND] {
- line[k] = kit.Select("", m.meta[k], i)
- }
- // 依次回调
- cb(i, line, m.meta[MSG_APPEND])
+ for i := 0; i < nrow; i++ {
+ line := map[string]string{}
+ for _, k := range m.meta[MSG_APPEND] {
+ line[k] = kit.Select("", m.meta[k], i)
}
+ // 依次回调
+ cbs[0](i, line, m.meta[MSG_APPEND])
}
return m
}
diff --git a/misc.go b/misc.go
new file mode 100644
index 00000000..0ba42f38
--- /dev/null
+++ b/misc.go
@@ -0,0 +1,54 @@
+package ice
+
+import (
+ "github.com/shylinux/toolkits"
+
+ "fmt"
+ "sync/atomic"
+)
+
+func (m *Message) Prefix(arg ...string) string {
+ return kit.Keys(m.Cap(CTX_FOLLOW), arg)
+}
+func (m *Message) Save(arg ...string) *Message {
+ list := []string{}
+ for _, k := range arg {
+ list = append(list, kit.Keys(m.Cap(CTX_FOLLOW), k))
+ }
+ m.Cmd("ctx.config", "save", kit.Keys(m.Cap(CTX_FOLLOW), "json"), list)
+ return m
+}
+func (m *Message) Load(arg ...string) *Message {
+ list := []string{}
+ for _, k := range arg {
+ list = append(list, kit.Keys(m.Cap(CTX_FOLLOW), k))
+ }
+ m.Cmd("ctx.config", "load", kit.Keys(m.Cap(CTX_FOLLOW), "json"), list)
+ return m
+}
+
+func (m *Message) Watch(key string, arg ...string) *Message {
+ m.Cmd("gdb.event", "listen", key, arg)
+ return m
+}
+func (m *Message) Event(key string, arg ...string) *Message {
+ m.Cmd("gdb.event", "action", key, arg)
+ return m
+}
+func (m *Message) Right(arg ...interface{}) bool {
+ return m.Option(MSG_USERROLE) == "root" || !m.Warn(m.Cmdx("aaa.role", "right", m.Option(MSG_USERROLE), kit.Keys(arg...)) != "ok", "no right")
+}
+func (m *Message) Space(arg interface{}) []string {
+ if arg == nil || kit.Format(arg) == m.Conf("cli.runtime", "node.name") {
+ return nil
+ }
+ return []string{"web.space", kit.Format(arg)}
+}
+
+var count = int32(0)
+
+func (m *Message) AddCmd(cmd *Command) string {
+ name := fmt.Sprintf("_cb_%d", atomic.AddInt32(&count, 1))
+ m.target.Commands[name] = cmd
+ return kit.Keys(m.target.Cap(CTX_FOLLOW), name)
+}
diff --git a/misc/alpha/alpha.go b/misc/alpha/alpha.go
index c0f05bbd..034c3a2b 100644
--- a/misc/alpha/alpha.go
+++ b/misc/alpha/alpha.go
@@ -105,8 +105,8 @@ var Index = &ice.Context{Name: "alpha", Help: "英汉词典",
)},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(ALPHA) }},
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(ALPHA) }},
"find": {Name: "find word=hi method auto", Help: "查找词汇", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_alpha_find(m, kit.Select("word", arg, 1), arg[0])
diff --git a/misc/chrome/chrome.go b/misc/chrome/chrome.go
index bed63bee..21a49a28 100644
--- a/misc/chrome/chrome.go
+++ b/misc/chrome/chrome.go
@@ -23,7 +23,7 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器",
), Meta: kit.Dict("detail", []string{"编辑", "goBack", "goForward", "duplicate", "reload", "remove"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 {
// 窗口列表
- m.Richs(ice.WEB_SPACE, nil, "*", func(key string, value map[string]interface{}) {
+ m.Richs(web.SPACE, nil, "*", func(key string, value map[string]interface{}) {
if kit.Format(value["type"]) == "chrome" {
m.Push(key, value, []string{"time", "name"})
}
@@ -32,11 +32,11 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器",
}
if arg[0] == "action" {
// 命令转换
- m.Cmdy(ice.WEB_SPACE, m.Option("name"), "tabs", m.Option("tid"), arg[1])
+ m.Cmdy(web.SPACE, m.Option("name"), "tabs", m.Option("tid"), arg[1])
arg = []string{m.Option("name"), m.Option("wid")}
}
// 下发命令
- m.Cmdy(ice.WEB_SPACE, arg[0], "wins", arg[1:])
+ m.Cmdy(web.SPACE, arg[0], "wins", arg[1:])
}},
"cookie": {Name: "cookie", Help: "数据", List: kit.List(
kit.MDB_INPUT, "text", "name", "name", "action", "auto",
@@ -51,11 +51,11 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器",
}
if arg[0] == "action" {
// 命令转换
- m.Cmdy(ice.WEB_SPACE, m.Option("name"), "cookie", arg[1:])
+ m.Cmdy(web.SPACE, m.Option("name"), "cookie", arg[1:])
arg = []string{m.Option("name"), m.Option("id")}
}
// 下发命令
- m.Cmdy(ice.WEB_SPACE, arg[0], "cookie", arg[1:])
+ m.Cmdy(web.SPACE, arg[0], "cookie", arg[1:])
}},
"bookmark": {Name: "bookmark", Help: "书签", List: kit.List(
kit.MDB_INPUT, "text", "name", "name", "action", "auto",
@@ -70,14 +70,14 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器",
}
if arg[0] == "action" {
// 命令转换
- m.Cmdy(ice.WEB_SPACE, m.Option("name"), "bookmark", arg[1:])
+ m.Cmdy(web.SPACE, m.Option("name"), "bookmark", arg[1:])
arg = []string{m.Option("name"), m.Option("id")}
}
// 下发命令
- m.Cmdy(ice.WEB_SPACE, arg[0], "bookmark", arg[1:])
+ m.Cmdy(web.SPACE, arg[0], "bookmark", arg[1:])
}},
- ice.WEB_LOGIN: {Name: "_login", Help: "_login", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ web.LOGIN: {Name: "_login", Help: "_login", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option("you", "")
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
// 查找空间
@@ -99,7 +99,7 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器",
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 {
// 添加收藏
- web.FavorInsert(m, m.Option("tab"), ice.TYPE_SPIDE, m.Option("note"), arg[0])
+ web.FavorInsert(m, m.Option("tab"), web.TYPE_SPIDE, m.Option("note"), arg[0])
return
}
}},
@@ -107,14 +107,14 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器",
"/crx": {Name: "/crx", Help: "/crx", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "login":
- m.Cmdy(ice.WEB_SPIDE, "dev", "msg", "/code/chrome/login", "sid", m.Option("sid"))
+ m.Cmdy(web.SPIDE, "dev", "msg", "/code/chrome/login", "sid", m.Option("sid"))
case "bookmark":
- m.Cmdy(ice.WEB_SPIDE, "dev", "/code/chrome/favor", "cmds", arg[2], "note", arg[3],
+ m.Cmdy(web.SPIDE, "dev", "/code/chrome/favor", "cmds", arg[2], "note", arg[3],
"tab", kit.Select(m.Conf("chrome", "meta.history"), arg, 4), "sid", m.Option("sid"), "type", "spide")
case "history":
- m.Cmdy(ice.WEB_SPIDE, "dev", "/code/chrome/favor", "cmds", arg[2], "note", arg[3],
+ m.Cmdy(web.SPIDE, "dev", "/code/chrome/favor", "cmds", arg[2], "note", arg[3],
"tab", m.Conf("chrome", "meta.history"), "sid", m.Option("sid"))
}
}},
diff --git a/misc/docker/docker.go b/misc/docker/docker.go
index 7b562906..4887ec2f 100644
--- a/misc/docker/docker.go
+++ b/misc/docker/docker.go
@@ -2,12 +2,26 @@ package docker
import (
"github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/gdb"
+ "github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/code"
"github.com/shylinux/toolkits"
"strings"
)
+func ListLook(name ...string) []interface{} {
+ list := []interface{}{}
+ for _, k := range name {
+ list = append(list, kit.MDB_INPUT, "text", "name", k, "action", "auto")
+ }
+ return kit.List(append(list,
+ kit.MDB_INPUT, "button", "name", "查看", "action", "auto",
+ kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
+ )...)
+}
+
var Index = &ice.Context{Name: "docker", Help: "虚拟机",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
@@ -15,16 +29,16 @@ var Index = &ice.Context{Name: "docker", Help: "虚拟机",
},
Commands: map[string]*ice.Command{
"init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Watch(ice.DREAM_START, m.Prefix("auto"))
+ m.Watch(gdb.DREAM_START, m.Prefix("auto"))
- if m.Richs(ice.WEB_FAVOR, nil, "alpine.auto", nil) == nil {
- m.Cmd(ice.WEB_FAVOR, "alpine.auto", ice.TYPE_SHELL, "镜像源", `sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories`)
- m.Cmd(ice.WEB_FAVOR, "alpine.auto", ice.TYPE_SHELL, "软件包", `apk add bash`)
- m.Cmd(ice.WEB_FAVOR, "alpine.auto", ice.TYPE_SHELL, "软件包", `apk add curl`)
+ if m.Richs(web.FAVOR, nil, "alpine.auto", nil) == nil {
+ m.Cmd(web.FAVOR, "alpine.auto", web.TYPE_SHELL, "镜像源", `sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories`)
+ m.Cmd(web.FAVOR, "alpine.auto", web.TYPE_SHELL, "软件包", `apk add bash`)
+ m.Cmd(web.FAVOR, "alpine.auto", web.TYPE_SHELL, "软件包", `apk add curl`)
}
}},
"auto": {Name: "auto", Help: "自动化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- prefix := []string{ice.CLI_SYSTEM, "docker"}
+ prefix := []string{cli.SYSTEM, "docker"}
if m.Cmd(prefix, "container", "start", arg[0]).Append("code") != "1" {
// 启动容器
@@ -37,7 +51,7 @@ var Index = &ice.Context{Name: "docker", Help: "虚拟机",
case "home":
args = append(args, "-w", "/root")
case "mount":
- args = append(args, "--mount", kit.Format("type=bind,source=%s,target=/root", kit.Path(m.Conf(ice.WEB_DREAM, "meta.path"), arg[0])))
+ args = append(args, "--mount", kit.Format("type=bind,source=%s,target=/root", kit.Path(m.Conf(web.DREAM, "meta.path"), arg[0])))
}
})
@@ -45,16 +59,16 @@ var Index = &ice.Context{Name: "docker", Help: "虚拟机",
pid := m.Cmdx(prefix, "run", "-dt", args, "--name", arg[0], "alpine")
m.Log(ice.LOG_CREATE, "%s: %s", arg[0], pid)
- m.Cmd(ice.WEB_FAVOR, kit.Select("alpine.auto", arg, 1)).Table(func(index int, value map[string]string, head []string) {
- if value["type"] == ice.TYPE_SHELL {
+ m.Cmd(web.FAVOR, kit.Select("alpine.auto", arg, 1)).Table(func(index int, value map[string]string, head []string) {
+ if value["type"] == web.TYPE_SHELL {
// 执行命令
m.Cmd(prefix, "exec", arg[0], kit.Split(value["text"]))
}
})
}},
- "image": {Name: "image", Help: "镜像管理", Meta: kit.Dict("detail", []string{"运行", "清理", "删除"}), List: ice.ListLook("IMAGE_ID"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- prefix := []string{ice.CLI_SYSTEM, "docker", "image"}
+ "image": {Name: "image", Help: "镜像管理", Meta: kit.Dict("detail", []string{"运行", "清理", "删除"}), List: ListLook("IMAGE_ID"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ prefix := []string{cli.SYSTEM, "docker", "image"}
if len(arg) > 1 && arg[0] == "action" {
switch arg[1] {
case "运行":
@@ -86,12 +100,12 @@ var Index = &ice.Context{Name: "docker", Help: "虚拟机",
m.Split(strings.Replace(m.Cmdx(prefix, "ls"), "IMAGE ID", "IMAGE_ID", 1), "index", " ", "\n")
m.Sort("REPOSITORY")
}},
- "container": {Name: "container", Help: "容器管理", List: ice.ListLook("CONTAINER_ID"), Meta: kit.Dict("detail", []string{"进入", "启动", "停止", "重启", "清理", "编辑", "删除"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- prefix := []string{ice.CLI_SYSTEM, "docker", "container"}
+ "container": {Name: "container", Help: "容器管理", List: ListLook("CONTAINER_ID"), Meta: kit.Dict("detail", []string{"进入", "启动", "停止", "重启", "清理", "编辑", "删除"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ prefix := []string{cli.SYSTEM, "docker", "container"}
if len(arg) > 1 && arg[0] == "action" {
switch arg[1] {
case "进入":
- m.Cmdy(ice.CLI_SYSTEM, "tmux", "new-window", "-t", m.Option("NAMES"), "-n", m.Option("NAMES"),
+ m.Cmdy(cli.SYSTEM, "tmux", "new-window", "-t", m.Option("NAMES"), "-n", m.Option("NAMES"),
"-PF", "#{session_name}:#{window_name}.1", "docker exec -it "+m.Option("NAMES")+" bash").Set("append")
return
case "停止":
@@ -133,7 +147,7 @@ var Index = &ice.Context{Name: "docker", Help: "虚拟机",
m.Cmdy("container")
return
}
- prefix := []string{ice.CLI_SYSTEM, "docker", "container"}
+ prefix := []string{cli.SYSTEM, "docker", "container"}
m.Cmdy(prefix, "exec", arg[0], arg[1:]).Set("append")
}},
},
diff --git a/misc/git/git.go b/misc/git/git.go
index 33cf0845..5cc234a0 100644
--- a/misc/git/git.go
+++ b/misc/git/git.go
@@ -2,6 +2,7 @@ package git
import (
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/code"
kit "github.com/shylinux/toolkits"
@@ -15,12 +16,12 @@ import (
func add(m *ice.Message, n string, p string) {
if s, e := os.Stat(m.Option("cmd_dir", path.Join(p, ".git"))); e == nil && s.IsDir() {
- ls := strings.SplitN(strings.Trim(m.Cmdx(ice.CLI_SYSTEM, "git", "log", "-n1", `--pretty=format:"%ad %s"`, "--date=iso"), "\""), " ", 4)
+ ls := strings.SplitN(strings.Trim(m.Cmdx(cli.SYSTEM, "git", "log", "-n1", `--pretty=format:"%ad %s"`, "--date=iso"), "\""), " ", 4)
m.Rich("repos", nil, kit.Data(
"name", n, "path", p,
"last", kit.Select("", ls, 3), "time", strings.Join(ls[:2], " "),
- "branch", strings.TrimSpace(m.Cmdx(ice.CLI_SYSTEM, "git", "branch")),
- "remote", strings.TrimSpace(m.Cmdx(ice.CLI_SYSTEM, "git", "remote", "-v")),
+ "branch", strings.TrimSpace(m.Cmdx(cli.SYSTEM, "git", "branch")),
+ "remote", strings.TrimSpace(m.Cmdx(cli.SYSTEM, "git", "remote", "-v")),
))
}
}
@@ -41,28 +42,28 @@ var Index = &ice.Context{Name: "git", Help: "代码库",
"total": {Name: "total", Help: "统计", Value: kit.Data(kit.MDB_SHORT, "name", "skip", kit.Dict("wubi-dict", "true", "word-dict", "true"))},
},
Commands: map[string]*ice.Command{
- ice.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ web.LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
- ice.CODE_INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ code.INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option("cmd_dir", m.Conf("install", "meta.path"))
- m.Cmd(ice.CLI_SYSTEM, "git", "clone", m.Conf("git", "meta.source"))
+ m.Cmd(cli.SYSTEM, "git", "clone", m.Conf("git", "meta.source"))
m.Option("cmd_dir", path.Join(m.Conf("install", "meta.path"), "git"))
- m.Cmd(ice.CLI_SYSTEM, "make", "configure")
- m.Cmd(ice.CLI_SYSTEM, "./configure", "--prefix="+kit.Path("usr/local"))
+ m.Cmd(cli.SYSTEM, "make", "configure")
+ m.Cmd(cli.SYSTEM, "./configure", "--prefix="+kit.Path("usr/local"))
- m.Cmd(ice.CLI_SYSTEM, "make", "-j4")
- m.Cmd(ice.CLI_SYSTEM, "make", "install")
+ m.Cmd(cli.SYSTEM, "make", "-j4")
+ m.Cmd(cli.SYSTEM, "make", "install")
}},
- ice.CODE_PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ code.PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
kit.Fetch(m.Confv("git", "meta.config"), func(conf string, value interface{}) {
kit.Fetch(value, func(key string, value string) {
- m.Cmd(ice.CLI_SYSTEM, "git", "config", "--global", conf+"."+key, value)
+ m.Cmd(cli.SYSTEM, "git", "config", "--global", conf+"."+key, value)
})
})
}},
- ice.CODE_PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ code.PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
"init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@@ -76,7 +77,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库",
})
// 应用项目
- m.Cmd("nfs.dir", m.Conf(ice.WEB_DREAM, "meta.path"), "name path").Table(func(index int, value map[string]string, head []string) {
+ m.Cmd("nfs.dir", m.Conf(web.DREAM, "meta.path"), "name path").Table(func(index int, value map[string]string, head []string) {
add(m, value["name"], value["path"])
})
}},
@@ -89,7 +90,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库",
if len(arg) > 1 {
if _, e := os.Stat(path.Join(arg[1], ".git")); e != nil && os.IsNotExist(e) {
// 下载仓库
- m.Cmd(ice.CLI_SYSTEM, "git", "clone", "-b", kit.Select("master", arg, 3),
+ m.Cmd(cli.SYSTEM, "git", "clone", "-b", kit.Select("master", arg, 3),
kit.Select(m.Conf("repos", "meta.owner")+"/"+arg[0], arg, 2), arg[1])
add(m, arg[0], arg[1])
}
@@ -157,7 +158,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库",
kit.MDB_INPUT, "text", "name", "name", "value", "some",
))},
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- prefix := []string{ice.CLI_SYSTEM, "git"}
+ prefix := []string{cli.SYSTEM, "git"}
if len(arg) > 1 && arg[0] == "action" {
m.Richs("repos", nil, m.Option("name"), func(key string, value map[string]interface{}) {
@@ -220,7 +221,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库",
var total_day time.Duration
count, count_add, count_del := 0, 0, 0
- for i, v := range strings.Split(m.Cmdx(ice.CLI_SYSTEM, "git", args), "commit: ") {
+ for i, v := range strings.Split(m.Cmdx(cli.SYSTEM, "git", args), "commit: ") {
if i > 0 {
l := strings.Split(v, "\n")
hs := strings.Split(l[0], " ")
diff --git a/misc/input/input.go b/misc/input/input.go
index 520e5cf1..626f9cd2 100644
--- a/misc/input/input.go
+++ b/misc/input/input.go
@@ -2,6 +2,7 @@ package input
import (
"github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/code"
"github.com/shylinux/toolkits"
@@ -50,7 +51,7 @@ func _input_find(m *ice.Message, method, word, limit string) {
}
// 搜索词汇
- res := m.Cmdx(ice.CLI_SYSTEM, "grep", "-rn", word, m.Conf(INPUT, "meta.store"))
+ res := m.Cmdx(cli.SYSTEM, "grep", "-rn", word, m.Conf(INPUT, "meta.store"))
bio := csv.NewReader(bytes.NewBufferString(strings.Replace(res, ":", ",", -1)))
for i := 0; i < kit.Int(limit); i++ {
@@ -187,8 +188,8 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
)},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(INPUT) }},
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(INPUT) }},
"list": {Name: "list [lib]", Help: "查看词库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_input_list(m, kit.Select("", arg, 0))
diff --git a/misc/lark/lark.go b/misc/lark/lark.go
index a7f10717..5cb9c63e 100644
--- a/misc/lark/lark.go
+++ b/misc/lark/lark.go
@@ -2,6 +2,8 @@ package lark
import (
"github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/aaa"
+ "github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/chat"
"github.com/shylinux/toolkits"
@@ -22,7 +24,7 @@ const (
func post(m *ice.Message, bot string, arg ...interface{}) {
m.Richs("app", nil, bot, func(key string, value map[string]interface{}) {
m.Option("header", "Authorization", "Bearer "+m.Cmdx("app", "token", bot), "Content-Type", "application/json")
- m.Cmdy(ice.WEB_SPIDE, "lark", arg)
+ m.Cmdy(web.SPIDE, "lark", arg)
})
}
@@ -64,12 +66,12 @@ var Index = &ice.Context{Name: "lark", Help: "机器人",
USER: &ice.Config{Name: "user", Help: "用户配置", Value: kit.Data()},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
m.Cmd(web.SPIDE, "add", LARK, m.Conf(APP, "meta.lark"))
- m.Cmd(DUTY, "boot", m.Conf(ice.CLI_RUNTIME, "boot.hostname"), m.Time())
+ m.Cmd(DUTY, "boot", m.Conf(cli.RUNTIME, "boot.hostname"), m.Time())
}},
- ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save(APP, USER)
}},
DUTY: {Name: "send [title] text", Help: "消息", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
@@ -116,10 +118,10 @@ var Index = &ice.Context{Name: "lark", Help: "机器人",
post(m, "bot", "/open-apis/message/v4/send/", "data", kit.Formats(form))
}},
- ice.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ web.LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
"login": {Name: "login", Help: "应用", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
- m.Cmdy(ice.WEB_SHARE, "user", m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_SESSID))
+ m.Cmdy(web.SHARE, "user", m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_SESSID))
}},
"app": {Name: "app login|token bot", Help: "应用", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
@@ -138,7 +140,7 @@ var Index = &ice.Context{Name: "lark", Help: "机器人",
case "token":
m.Richs("app", nil, arg[1], func(key string, value map[string]interface{}) {
if now := time.Now().Unix(); kit.Format(value["token"]) == "" || kit.Int64(value["expire"]) < now {
- m.Cmdy(ice.WEB_SPIDE, "lark", "/open-apis/auth/v3/tenant_access_token/internal/", "app_id", value["id"], "app_secret", value["mm"])
+ m.Cmdy(web.SPIDE, "lark", "/open-apis/auth/v3/tenant_access_token/internal/", "app_id", value["id"], "app_secret", value["mm"])
value["token"] = m.Append("tenant_access_token")
value["expire"] = kit.Int64(m.Append("expire")) + now
m.Set("result")
@@ -155,7 +157,7 @@ var Index = &ice.Context{Name: "lark", Help: "机器人",
return
}},
"ship": {Name: "ship", Help: "组织", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
- data := kit.UnMarshal(m.Cmdx(ice.WEB_SPIDE, "lark", "/open-apis/contact/v1/scope/get/",
+ data := kit.UnMarshal(m.Cmdx(web.SPIDE, "lark", "/open-apis/contact/v1/scope/get/",
"headers", "Authorization", "Bearer "+m.Cmdx(".app", "token", "bot"),
))
kit.Fetch(kit.Value(data, "data.authed_departments"), func(index int, value string) {
@@ -190,14 +192,14 @@ var Index = &ice.Context{Name: "lark", Help: "机器人",
switch arg[0] {
case "code":
m.Richs("app", nil, "bot", func(key string, value map[string]interface{}) {
- m.Cmd(ice.WEB_SPIDE, "lark", "/connect/qrconnect/oauth2/access_token/",
+ m.Cmd(web.SPIDE, "lark", "/connect/qrconnect/oauth2/access_token/",
"app_secret", value["mm"], "app_id", value["id"],
"grant_type", "authorization_code", "code", arg[1],
)
})
- msg := m.Cmd(ice.WEB_SPIDE, "lark", "/connect/qrconnect/oauth2/user_info/",
+ msg := m.Cmd(web.SPIDE, "lark", "/connect/qrconnect/oauth2/user_info/",
"headers", "Authorization", "Bearer "+m.Append("access_token"),
)
m.Confv("user", m.Append("open_id"), map[string]interface{}{
@@ -356,14 +358,14 @@ var Index = &ice.Context{Name: "lark", Help: "机器人",
if m.Options("open_chat_id") {
// 用户登录
m.Option(ice.MSG_USERNAME, m.Option("open_id"))
- m.Option(ice.MSG_USERROLE, m.Cmdx(ice.AAA_ROLE, "check", m.Option(ice.MSG_USERNAME)))
+ m.Option(ice.MSG_USERROLE, m.Cmdx(aaa.ROLE, "check", m.Option(ice.MSG_USERNAME)))
m.Info("%s: %s", m.Option(ice.MSG_USERROLE), m.Option(ice.MSG_USERNAME))
if cmd := kit.Split(m.Option("text_without_at_bot")); cmd[0] == "login" || m.Right(cmd) {
// 执行命令
msg := m.Cmd(cmd)
if m.Hand = false; !msg.Hand {
- msg = m.Cmd(ice.CLI_SYSTEM, cmd)
+ msg = m.Cmd(cli.SYSTEM, cmd)
}
if msg.Result() == "" {
msg.Table()
diff --git a/misc/md/md.go b/misc/md/md.go
index ebf3c26a..b1f505f0 100644
--- a/misc/md/md.go
+++ b/misc/md/md.go
@@ -11,6 +11,20 @@ import (
"strings"
)
+/*
+func (m *Message) Prefile(favor string, id string) map[string]string {
+ // TODO
+ res := map[string]string{}
+ m.Option("render", "")
+ m.Option("_action", "")
+ m.Cmd("web.favor", kit.Select(m.Option("favor"), favor), id).Table(func(index int, value map[string]string, head []string) {
+ res[value["key"]] = value["value"]
+ })
+
+ res["content"] = m.Cmdx("cli.system", "sed", "-n", kit.Format("%d,%dp", kit.Int(res["extra.row"]), kit.Int(res["extra.row"])+3), res["extra.buf"])
+ return res
+}
+*/
var Index = &ice.Context{Name: "md", Help: "md",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
diff --git a/misc/mp/mp.go b/misc/mp/mp.go
index 0ba088fa..aac293f5 100644
--- a/misc/mp/mp.go
+++ b/misc/mp/mp.go
@@ -24,7 +24,7 @@ var Index = &ice.Context{Name: "mp", Help: "小程序",
m.Load()
web.SpideCreate(m, "weixin", m.Conf("login", "meta.weixin"))
m.Confm("login", "meta.userrole", func(key string, value string) {
- m.Cmd(ice.AAA_ROLE, value, key)
+ m.Cmd(aaa.ROLE, value, key)
})
}},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@@ -56,16 +56,16 @@ var Index = &ice.Context{Name: "mp", Help: "小程序",
"/login/": {Name: "/login/", Help: "登录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "code":
- msg := m.Cmd(ice.WEB_SPIDE, "weixin", "GET", m.Conf("login", "meta.auth"), "js_code", m.Option("code"),
+ msg := m.Cmd(web.SPIDE, "weixin", "GET", m.Conf("login", "meta.auth"), "js_code", m.Option("code"),
"appid", m.Conf("login", "meta.appid"), "secret", m.Conf("login", "meta.appmm"))
// 用户登录
- m.Echo(m.Option(ice.MSG_SESSID, m.Cmdx(ice.AAA_USER, "login", msg.Append("openid"))))
+ m.Echo(m.Option(ice.MSG_SESSID, m.Cmdx(aaa.USER, "login", msg.Append("openid"))))
case "info":
// 用户信息
- m.Richs(ice.AAA_SESS, nil, m.Option(ice.MSG_SESSID), func(key string, value map[string]interface{}) {
- m.Richs(ice.AAA_USER, nil, value["username"], func(key string, value map[string]interface{}) {
+ m.Richs(aaa.SESS, nil, m.Option(ice.MSG_SESSID), func(key string, value map[string]interface{}) {
+ m.Richs(aaa.USER, nil, value["username"], func(key string, value map[string]interface{}) {
value["gender"] = m.Option("gender")
value["avatar"] = m.Option("avatarUrl")
value["nickname"] = m.Option("nickName")
@@ -77,7 +77,7 @@ var Index = &ice.Context{Name: "mp", Help: "小程序",
})
case "scan":
- m.Cmd(ice.WEB_FAVOR, "device", "scan", m.Option("name"), m.Option("text"))
+ m.Cmd(web.FAVOR, "device", "scan", m.Option("name"), m.Option("text"))
case "auth":
if !m.Options(ice.MSG_USERNAME) {
@@ -87,11 +87,11 @@ var Index = &ice.Context{Name: "mp", Help: "小程序",
switch kit.Select("active", m.Option("type")) {
case "share":
- m.Richs(ice.WEB_SHARE, nil, m.Option("text"), func(key string, value map[string]interface{}) {
+ m.Richs(web.SHARE, nil, m.Option("text"), func(key string, value map[string]interface{}) {
switch value["type"] {
case "invite":
if m.Option(ice.MSG_USERROLE) != value["name"] {
- m.Cmd(ice.AAA_ROLE, value["name"], m.Option(ice.MSG_USERNAME))
+ m.Cmd(aaa.ROLE, value["name"], m.Option(ice.MSG_USERNAME))
m.Cmd("web.chat.auto", m.Option(ice.MSG_USERNAME), value["name"])
}
break
@@ -106,16 +106,16 @@ var Index = &ice.Context{Name: "mp", Help: "小程序",
switch kit.Select("active", m.Option("type")) {
case "active":
// 网页登录
- m.Cmdy(ice.WEB_SPACE, m.Option("name"), "sessid", m.Cmdx(ice.AAA_SESS, "create", m.Option(ice.MSG_USERNAME)))
+ m.Cmdy(web.SPACE, m.Option("name"), "sessid", m.Cmdx(aaa.SESS, "create", m.Option(ice.MSG_USERNAME)))
case "login":
// 终端登录
- m.Cmdy(ice.AAA_SESS, "auth", m.Option("text"), m.Option(ice.MSG_USERNAME))
+ m.Cmdy(aaa.SESS, "auth", m.Option("text"), m.Option(ice.MSG_USERNAME))
}
case "upload":
- msg := m.Cmd(ice.WEB_CACHE, "upload")
- m.Cmd(ice.WEB_STORY, ice.STORY_WATCH, msg.Append("data"), path.Join("usr/local/mp/", path.Base(msg.Append("name"))))
- m.Cmd(ice.WEB_FAVOR, "device", "file", msg.Append("name"), msg.Append("data"))
+ msg := m.Cmd(web.CACHE, "upload")
+ m.Cmd(web.STORY, ice.STORY_WATCH, msg.Append("data"), path.Join("usr/local/mp/", path.Base(msg.Append("name"))))
+ m.Cmd(web.FAVOR, "device", "file", msg.Append("name"), msg.Append("data"))
m.Render(msg.Append("data"))
case "cmds":
diff --git a/misc/shy.go b/misc/shy.go
index be9ac41e..c3cb8579 100644
--- a/misc/shy.go
+++ b/misc/shy.go
@@ -1,9 +1,3 @@
package misc
-import (
- _ "github.com/shylinux/icebergs/misc/docker"
- _ "github.com/shylinux/icebergs/misc/git"
- _ "github.com/shylinux/icebergs/misc/tmux"
- _ "github.com/shylinux/icebergs/misc/vim"
- _ "github.com/shylinux/icebergs/misc/zsh"
-)
+import ()
diff --git a/misc/tmux/tmux.go b/misc/tmux/tmux.go
index 1c9d0a0e..4840c7b5 100644
--- a/misc/tmux/tmux.go
+++ b/misc/tmux/tmux.go
@@ -2,6 +2,8 @@ package tmux
import (
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/gdb"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/code"
kit "github.com/shylinux/toolkits"
@@ -15,7 +17,7 @@ import (
var Index = &ice.Context{Name: "tmux", Help: "工作台",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
- "prefix": {Name: "prefix", Help: "前缀", Value: kit.Data("cmd", []interface{}{ice.CLI_SYSTEM, "tmux"})},
+ "prefix": {Name: "prefix", Help: "前缀", Value: kit.Data("cmd", []interface{}{cli.SYSTEM, "tmux"})},
"buffer": {Name: "buffer", Help: "缓存", Value: kit.Data()},
"session": {Name: "session", Help: "会话", Value: kit.Data(
@@ -42,12 +44,12 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
)},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- if m.Cmdy(ice.CLI_SYSTEM, "tmux", "ls"); m.Append("code") != "0" {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ if m.Cmdy(cli.SYSTEM, "tmux", "ls"); m.Append("code") != "0" {
return
}
- m.Cmd(ice.WEB_PROXY, "add", "tmux", m.AddCmd(&ice.Command{Name: "proxy", Help: "代理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Cmd(web.PROXY, "add", "tmux", m.AddCmd(&ice.Command{Name: "proxy", Help: "代理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd("session").Table(func(index int, value map[string]string, head []string) {
if value["tag"] == "1" {
m.Echo(value["session"])
@@ -55,31 +57,31 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
})
}}))
}},
- ice.CODE_INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ code.INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option("cmd_dir", m.Conf("install", "meta.path"))
- m.Cmd(ice.CLI_SYSTEM, "git", "clone", "https://github.com/tmux/tmux")
+ m.Cmd(cli.SYSTEM, "git", "clone", "https://github.com/tmux/tmux")
}},
- ice.CODE_PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ code.PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd("nfs.link", path.Join(os.Getenv("HOME"), ".tmux.conf"), "etc/conf/tmux.conf")
}},
- ice.CODE_PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ code.PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
"init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Watch(ice.DREAM_START, m.Prefix("auto"))
+ m.Watch(gdb.DREAM_START, m.Prefix("auto"))
- if m.Richs(ice.WEB_FAVOR, nil, "tmux.auto", nil) == nil {
- m.Cmd(ice.WEB_FAVOR, "tmux.auto", ice.TYPE_SHELL, "脚本", `curl $ctx_dev/publish/auto.sh > auto.sh`)
- m.Cmd(ice.WEB_FAVOR, "tmux.auto", ice.TYPE_SHELL, "脚本", `source auto.sh`)
- m.Cmd(ice.WEB_FAVOR, "tmux.auto", ice.TYPE_SHELL, "脚本", `ShyInit && ShyLogin && trap ShyLogout EXIT`)
+ if m.Richs(web.FAVOR, nil, "tmux.auto", nil) == nil {
+ m.Cmd(web.FAVOR, "tmux.auto", web.TYPE_SHELL, "脚本", `curl $ctx_dev/publish/auto.sh > auto.sh`)
+ m.Cmd(web.FAVOR, "tmux.auto", web.TYPE_SHELL, "脚本", `source auto.sh`)
+ m.Cmd(web.FAVOR, "tmux.auto", web.TYPE_SHELL, "脚本", `ShyInit && ShyLogin && trap ShyLogout EXIT`)
}
for _, v := range []string{"auto.sh", "auto.vim", "auto.tmux"} {
p := path.Join(m.Conf("web.code.publish", "meta.path"), v)
if _, e := os.Stat(p); e != nil && os.IsNotExist(e) {
// 下载脚本
- if h := m.Cmdx(ice.WEB_SPIDE, "shy", "cache", "GET", "/publish/"+v); h != "" {
- m.Cmd(ice.WEB_STORY, ice.STORY_WATCH, h, p)
+ if h := m.Cmdx(web.SPIDE, "shy", "cache", "GET", "/publish/"+v); h != "" {
+ m.Cmd(web.STORY, web.SHOW, h, p)
}
}
}
@@ -88,14 +90,14 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
prefix := kit.Simple(m.Confv("prefix", "meta.cmd"))
// 共享空间
- share, dev := "", kit.Select(m.Conf(ice.CLI_RUNTIME, "conf.ctx_dev"), m.Conf(ice.CLI_RUNTIME, "host.ctx_self"))
- m.Richs(ice.WEB_SPACE, nil, arg[0], func(key string, value map[string]interface{}) {
+ share, dev := "", kit.Select(m.Conf(cli.RUNTIME, "conf.ctx_dev"), m.Conf(cli.RUNTIME, "host.ctx_self"))
+ m.Richs(web.SPACE, nil, arg[0], func(key string, value map[string]interface{}) {
share = kit.Format(value["share"])
})
// 环境变量
m.Option("cmd_env", "TMUX", "", "ctx_dev", dev, "ctx_share", share)
- m.Option("cmd_dir", path.Join(m.Conf(ice.WEB_DREAM, "meta.path"), arg[0]))
+ m.Option("cmd_dir", path.Join(m.Conf(web.DREAM, "meta.path"), arg[0]))
if arg[0] != "" && m.Cmd(prefix, "has-session", "-t", arg[0]).Append("code") != "0" {
// 创建会话
@@ -120,9 +122,9 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
m.Cmdy(prefix, "send-keys", "-t", arg[0], "export ctx_dev=", dev, "Enter")
m.Cmdy(prefix, "send-keys", "-t", arg[0], "export ctx_share=", share, "Enter")
- m.Cmd(ice.WEB_FAVOR, kit.Select("tmux.auto", arg, 1)).Table(func(index int, value map[string]string, head []string) {
+ m.Cmd(web.FAVOR, kit.Select("tmux.auto", arg, 1)).Table(func(index int, value map[string]string, head []string) {
switch value["type"] {
- case ice.TYPE_SHELL:
+ case web.TYPE_SHELL:
// 发送命令
m.Cmdy(prefix, "send-keys", "-t", arg[0], value["text"], "Enter")
time.Sleep(10 * time.Millisecond)
@@ -136,7 +138,7 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
}},
"make": {Name: "make name cmd...", Help: "个性化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
prefix := kit.Simple(m.Confv("prefix", "meta.cmd"))
- session := m.Conf(ice.CLI_RUNTIME, "node.name")
+ session := m.Conf(cli.RUNTIME, "node.name")
if arg[1] == "session" {
session, arg[2], arg = arg[2], arg[0], arg[2:]
}
@@ -267,7 +269,7 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
if m.Cmd(prefix, "has-session", "-t", target).Append("code") != "0" {
// 创建会话
m.Option("cmd_env", "TMUX", "")
- m.Option("cmd_dir", m.Conf(ice.WEB_DREAM, "meta.path"))
+ m.Option("cmd_dir", m.Conf(web.DREAM, "meta.path"))
m.Cmd(prefix, "new-session", "-ds", arg[0])
m.Cmd("auto", arg[0])
}
diff --git a/misc/totp/totp.go b/misc/totp/totp.go
index cd950918..da20dc3c 100644
--- a/misc/totp/totp.go
+++ b/misc/totp/totp.go
@@ -49,8 +49,8 @@ var Index = &ice.Context{Name: "totp", Help: "动态码",
"totp": {Name: "totp", Help: "动态码", Value: kit.Data(kit.MDB_SHORT, "name", "share", "otpauth://totp/%s?secret=%s")},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {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) {}},
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
+ ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
"new": {Name: "new user [secret]", Help: "创建密钥", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 {
diff --git a/misc/vim/vim.go b/misc/vim/vim.go
index 7a0c372a..2f3d2669 100644
--- a/misc/vim/vim.go
+++ b/misc/vim/vim.go
@@ -4,6 +4,7 @@ import (
"fmt"
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/code"
kit "github.com/shylinux/toolkits"
@@ -27,8 +28,8 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
)},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Conf(ice.WEB_FAVOR, "meta.render.vimrc", m.AddCmd(&ice.Command{Name: "render favor id", Help: "渲染引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Conf(web.FAVOR, "meta.render.vimrc", m.AddCmd(&ice.Command{Name: "render favor id", Help: "渲染引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
value := m.Optionv("value").(map[string]interface{})
switch value["name"] {
case "read", "write", "exec":
@@ -44,29 +45,29 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
m.Assert(e)
m.Echo(string(b))
default:
- m.Cmdy(ice.CLI_SYSTEM, "sed", "-n", fmt.Sprintf("/%s/,/^}$/p", value["text"]), kit.Value(value, "extra.buf"))
+ m.Cmdy(cli.SYSTEM, "sed", "-n", fmt.Sprintf("/%s/,/^}$/p", value["text"]), kit.Value(value, "extra.buf"))
}
}}))
}},
- ice.CODE_INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ code.INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
p := path.Join(m.Conf("install", "meta.path"), m.Conf("vim", "meta.version"))
if _, e := os.Stat(p); e != nil {
// 下载源码
m.Option("cmd_dir", m.Conf("install", "meta.path"))
- m.Cmd(ice.CLI_SYSTEM, "wget", "-O", "vim.tar.gz", m.Conf("vim", "meta.source"))
- m.Cmd(ice.CLI_SYSTEM, "tar", "xvf", "vim.tar.gz")
+ m.Cmd(cli.SYSTEM, "wget", "-O", "vim.tar.gz", m.Conf("vim", "meta.source"))
+ m.Cmd(cli.SYSTEM, "tar", "xvf", "vim.tar.gz")
}
// 配置选项
m.Option("cmd_dir", p)
- m.Cmdy(ice.CLI_SYSTEM, "./configure", "--prefix="+kit.Path(m.Conf("vim", "meta.target")),
+ m.Cmdy(cli.SYSTEM, "./configure", "--prefix="+kit.Path(m.Conf("vim", "meta.target")),
"--enable-multibyte=yes", m.Confv("vim", "meta.config"))
// 编译安装
- m.Cmdy(ice.CLI_SYSTEM, "make", "-j4")
- m.Cmdy(ice.CLI_SYSTEM, "make", "install")
+ m.Cmdy(cli.SYSTEM, "make", "-j4")
+ m.Cmdy(cli.SYSTEM, "make", "install")
}},
- ice.CODE_PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ code.PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
// 语法脚本
for _, s := range []string{"go.vim", "shy.vim", "javascript.vim"} {
m.Cmd("nfs.link", path.Join(os.Getenv("HOME"), ".vim/syntax/"+s), "etc/conf/"+s)
@@ -80,10 +81,10 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
m.Echo("vim -c PlugInstall\n")
m.Echo("vim -c GoInstallBinaries\n")
}},
- ice.CODE_PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ code.PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
- ice.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ web.LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, _, e := m.R.FormFile("sub"); e == nil {
defer f.Close()
// 文件参数
@@ -115,7 +116,7 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
"/sync": {Name: "/sync", Help: "同步", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "read", "write", "exec", "insert":
- m.Cmd(ice.WEB_FAVOR, m.Conf("vim", "meta.history"), ice.TYPE_VIMRC, arg[0], kit.Select(m.Option("arg"), m.Option("sub")),
+ m.Cmd(web.FAVOR, m.Conf("vim", "meta.history"), web.TYPE_VIMRC, arg[0], kit.Select(m.Option("arg"), m.Option("sub")),
"sid", m.Option("sid"), "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col"))
default:
@@ -152,16 +153,16 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if m.Options("arg") {
// 添加收藏
- m.Cmdy(ice.WEB_FAVOR, kit.Select(m.Conf("vim", "meta.history"), m.Option("tab")),
- ice.TYPE_VIMRC, m.Option("note"), m.Option("arg"),
+ m.Cmdy(web.FAVOR, kit.Select(m.Conf("vim", "meta.history"), m.Option("tab")),
+ web.TYPE_VIMRC, m.Option("note"), m.Option("arg"),
"pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col"))
return
}
// 查看收藏
- m.Cmd(ice.WEB_PROXY, m.Option("you"), ice.WEB_FAVOR, m.Option("tab"), "extra", "extra.pwd", "extra.buf", "extra.row", "extra.col").Table(func(index int, value map[string]string, head []string) {
+ m.Cmd(web.PROXY, m.Option("you"), web.FAVOR, m.Option("tab"), "extra", "extra.pwd", "extra.buf", "extra.row", "extra.col").Table(func(index int, value map[string]string, head []string) {
switch value["type"] {
- case ice.TYPE_VIMRC:
+ case web.TYPE_VIMRC:
m.Echo("%v\n", m.Option("tab")).Echo("%v:%v:%v:(%v): %v\n",
value["extra.buf"], value["extra.row"], value["extra.col"], value["name"], value["text"])
}
diff --git a/misc/wx/wx.go b/misc/wx/wx.go
index f22944a1..f17a3dbe 100644
--- a/misc/wx/wx.go
+++ b/misc/wx/wx.go
@@ -97,7 +97,7 @@ var Index = &ice.Context{Name: "wx", Help: "公众号",
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
m.Confm("login", "meta.userrole", func(key string, value string) {
- m.Cmd(ice.AAA_ROLE, value, key)
+ m.Cmd(aaa.ROLE, value, key)
})
}},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@@ -123,9 +123,9 @@ var Index = &ice.Context{Name: "wx", Help: "公众号",
// 用户登录
m.Option(ice.MSG_USERNAME, m.Option("FromUserName"))
- m.Option(ice.MSG_USERROLE, m.Cmdx(ice.AAA_ROLE, "check", m.Option("FromUserName")))
+ m.Option(ice.MSG_USERROLE, m.Cmdx(aaa.ROLE, "check", m.Option("FromUserName")))
m.Info("%s: %s", m.Option(ice.MSG_USERROLE), m.Option(ice.MSG_USERNAME))
- m.Option(ice.MSG_SESSID, m.Cmdx(ice.AAA_USER, "login", m.Option(ice.MSG_USERNAME)))
+ m.Option(ice.MSG_SESSID, m.Cmdx(aaa.USER, "login", m.Option(ice.MSG_USERNAME)))
switch m.Option("MsgType") {
case "text":
@@ -139,7 +139,7 @@ var Index = &ice.Context{Name: "wx", Help: "公众号",
// 执行命令
msg := m.Cmd(cmds)
if m.Hand = false; !msg.Hand {
- msg = m.Cmd(ice.CLI_SYSTEM, cmds)
+ msg = m.Cmd(cli.SYSTEM, cmds)
}
if msg.Result() == "" {
msg.Table()
diff --git a/misc/zsh/zsh.go b/misc/zsh/zsh.go
index c3e5415c..bcae3fe4 100644
--- a/misc/zsh/zsh.go
+++ b/misc/zsh/zsh.go
@@ -2,6 +2,7 @@ package zsh
import (
ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/code"
kit "github.com/shylinux/toolkits"
@@ -26,32 +27,32 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
)},
},
Commands: map[string]*ice.Command{
- ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Conf(ice.WEB_FAVOR, "meta.render.shell", m.AddCmd(&ice.Command{Name: "render type name text", Help: "渲染引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Conf(web.FAVOR, "meta.render.shell", m.AddCmd(&ice.Command{Name: "render type name text", Help: "渲染引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
value, _ := m.Optionv(kit.MDB_VALUE).(map[string]interface{})
m.Option("cmd_dir", kit.Value(value, "extra.pwd"))
- m.Cmdy(ice.CLI_SYSTEM, kit.Select(kit.Format(value["text"]), arg, 2))
+ m.Cmdy(cli.SYSTEM, kit.Select(kit.Format(value["text"]), arg, 2))
}}))
- m.Conf(ice.WEB_FAVOR, "meta.render.cmd", m.AddCmd(&ice.Command{Name: "render type name text", Help: "渲染引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Conf(web.FAVOR, "meta.render.cmd", m.AddCmd(&ice.Command{Name: "render type name text", Help: "渲染引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
value, _ := m.Optionv(kit.MDB_VALUE).(map[string]interface{})
m.Cmdy(kit.Split(kit.Format(kit.Select(kit.Format(value["text"], arg, 2)))))
}}))
- m.Conf(ice.WEB_FAVOR, "meta.render.bin", m.AddCmd(&ice.Command{Name: "render type name text", Help: "渲染引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Cmdy(ice.CLI_SYSTEM, "file", arg[2])
+ m.Conf(web.FAVOR, "meta.render.bin", m.AddCmd(&ice.Command{Name: "render type name text", Help: "渲染引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ m.Cmdy(cli.SYSTEM, "file", arg[2])
}}))
}},
- ice.CODE_PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ code.PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd("web.code.git.repos", "shell", "usr/shell")
p := path.Join(os.Getenv("HOME"), ".ish")
- m.Cmd(ice.CLI_SYSTEM, "rm", p)
- m.Cmd(ice.CLI_SYSTEM, "ln", "-s", kit.Path("usr/shell"), p)
+ m.Cmd(cli.SYSTEM, "rm", p)
+ m.Cmd(cli.SYSTEM, "ln", "-s", kit.Path("usr/shell"), p)
list := kit.Simple(m.Confv("zsh", "meta.script"))
for i := 0; i < len(list); i += 2 {
m.Cmd("nfs.link", path.Join(os.Getenv("HOME"), list[i]), list[i+1])
}
}},
- ice.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ web.LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, _, e := m.R.FormFile("sub"); e == nil {
defer f.Close()
// 文件参数
@@ -88,7 +89,7 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
if strings.Contains(m.Option("SHELL"), "zsh") {
vs = []string{vs[0], m.Time("2006-01-02"), m.Time("15:04:05"), strings.Join(vs[1:], " ")}
}
- m.Cmd(ice.WEB_FAVOR, m.Conf("zsh", "meta.history"), ice.TYPE_SHELL, vs[0], kit.Select("", vs, 3),
+ m.Cmd(web.FAVOR, m.Conf("zsh", "meta.history"), web.TYPE_SHELL, vs[0], kit.Select("", vs, 3),
"sid", m.Option("sid"), "pwd", m.Option("pwd"), "time", vs[1]+" "+vs[2])
default:
@@ -190,21 +191,21 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 && arg[0] != "sh" {
// 添加收藏
- m.Cmdy(ice.WEB_FAVOR, kit.Select(m.Conf("zsh", "meta.history"), m.Option("tab")),
- kit.Select(ice.TYPE_SHELL, m.Option("type")), m.Option("note"), arg[0])
+ m.Cmdy(web.FAVOR, kit.Select(m.Conf("zsh", "meta.history"), m.Option("tab")),
+ kit.Select(web.TYPE_SHELL, m.Option("type")), m.Option("note"), arg[0])
return
}
if m.Option("tab") == "" {
// 收藏列表
- m.Cmdy(ice.WEB_FAVOR).Table()
+ m.Cmdy(web.FAVOR).Table()
return
}
m.Echo("#/bin/sh\n\n")
- m.Cmd(ice.WEB_PROXY, m.Option("you"), ice.WEB_FAVOR, m.Option("tab")).Table(func(index int, value map[string]string, head []string) {
+ m.Cmd(web.PROXY, m.Option("you"), web.FAVOR, m.Option("tab")).Table(func(index int, value map[string]string, head []string) {
switch value["type"] {
- case ice.TYPE_SHELL:
+ case web.TYPE_SHELL:
// 查看收藏
if m.Option("note") == "" || m.Option("note") == value["name"] {
m.Echo("# %v\n%v\n\n", value["name"], value["text"])
@@ -224,15 +225,15 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
"/download": {Name: "/download", Help: "下载", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 || arg[0] == "" {
// 文件列表
- m.Cmdy(ice.WEB_PROXY, m.Option("you"), ice.WEB_STORY).Table()
+ m.Cmdy(web.PROXY, m.Option("you"), web.STORY).Table()
return
}
// 查找文件
- if m.Cmdy(ice.WEB_STORY, "index", arg[0]).Append("text") == "" && m.Option("you") != "" {
+ if m.Cmdy(web.STORY, "index", arg[0]).Append("text") == "" && m.Option("you") != "" {
// 上发文件
- m.Cmd(ice.WEB_PROXY, m.Option("you"), ice.WEB_STORY, "push", arg[0], "dev", arg[0])
- m.Cmdy(ice.WEB_STORY, "index", arg[0])
+ m.Cmd(web.PROXY, m.Option("you"), web.STORY, "push", arg[0], "dev", arg[0])
+ m.Cmdy(web.STORY, "index", arg[0])
}
// 下载文件
@@ -240,7 +241,7 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
}},
"/upload": {Name: "/upload", Help: "上传", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
// 缓存文件
- msg := m.Cmd(ice.WEB_STORY, "upload")
+ msg := m.Cmd(web.STORY, "upload")
m.Echo("data: %s\n", msg.Append("data"))
m.Echo("time: %s\n", msg.Append("time"))
m.Echo("type: %s\n", msg.Append("type"))
diff --git a/name.go b/name.go
deleted file mode 100644
index c5c6636e..00000000
--- a/name.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package ice
-
-import (
- "errors"
-)
-
-var names = map[string]interface{}{}
-
-var ErrNameExists = errors.New("name already exists")
-
-func Name(name string, value interface{}) string {
- if _, ok := names[name]; ok {
- panic(ErrNameExists)
- }
- names[name] = value
- return name
-}
diff --git a/type.go b/type.go
index aebc1e6e..fbf1132e 100644
--- a/type.go
+++ b/type.go
@@ -77,12 +77,10 @@ func (c *Context) Cap(key string, arg ...interface{}) string {
}
return c.Caches[key].Value
}
-func (c *Context) Run(m *Message, cmd *Command, key string, arg ...string) *Message {
- if cmd == nil {
+func (c *Context) cmd(m *Message, cmd *Command, key string, arg ...string) *Message {
+ if m.meta[MSG_DETAIL] = kit.Simple(key, arg); cmd == nil {
return m
}
- m.meta[MSG_DETAIL] = kit.Simple(key, arg)
- m.Hand = true
action, args := m.Option("_action"), arg
if len(arg) > 0 && arg[0] == "action" {
@@ -115,11 +113,11 @@ func (c *Context) Run(m *Message, cmd *Command, key string, arg ...string) *Mess
cmd.Hand(m, c, key, arg...)
return m
}
-func (c *Context) Runs(m *Message, cmd string, key string, arg ...string) {
- if s, ok := m.Target().Commands[key]; ok {
- c.Run(m, s, cmd, arg...)
+func (c *Context) Cmd(m *Message, cmd string, key string, arg ...string) *Message {
+ if s, ok := m.Target().Commands[cmd]; ok {
+ c.cmd(m, s, cmd, arg...)
}
- return
+ return m
}
func (c *Context) Server() Server {
return c.server
@@ -183,6 +181,9 @@ func (c *Context) Begin(m *Message, arg ...string) *Context {
if c.Configs == nil {
c.Configs = map[string]*Config{}
}
+ if c.Commands == nil {
+ c.Commands = map[string]*Command{}
+ }
c.Caches[CTX_FOLLOW] = &Cache{Name: CTX_FOLLOW, Value: ""}
c.Caches[CTX_STREAM] = &Cache{Name: CTX_STREAM, Value: ""}
c.Caches[CTX_STATUS] = &Cache{Name: CTX_STATUS, Value: ""}
@@ -192,8 +193,8 @@ func (c *Context) Begin(m *Message, arg ...string) *Context {
} else if c.context != nil {
c.Cap(CTX_FOLLOW, kit.Keys(c.context.Cap(CTX_FOLLOW), c.Name))
}
- m.Log(LOG_BEGIN, "%s", c.Cap(CTX_FOLLOW))
- c.Cap(CTX_STATUS, ICE_BEGIN)
+ m.Logs(LOG_BEGIN, CTX_FOLLOW, c.Cap(CTX_FOLLOW))
+ c.Cap(CTX_STATUS, CTX_BEGIN)
if c.begin = m; c.server != nil {
m.TryCatch(m, true, func(m *Message) {
@@ -209,12 +210,11 @@ func (c *Context) Start(m *Message, arg ...string) bool {
wait := make(chan bool)
m.Gos(m, func(m *Message) {
- m.Log(LOG_START, "%s", c.Cap(CTX_FOLLOW))
- c.Cap(CTX_STATUS, ICE_START)
- wait <- true
+ m.Logs(LOG_START, CTX_FOLLOW, c.Cap(CTX_FOLLOW))
+ c.Cap(CTX_STATUS, CTX_START)
// 启动模块
- if c.server != nil {
+ if wait <- true; c.server != nil {
c.server.Start(m, arg...)
}
if m.Done(); m.wait != nil {
@@ -226,7 +226,7 @@ func (c *Context) Start(m *Message, arg ...string) bool {
}
func (c *Context) Close(m *Message, arg ...string) bool {
m.Log(LOG_CLOSE, "%s", c.Cap(CTX_FOLLOW))
- c.Cap(CTX_STATUS, ICE_CLOSE)
+ c.Cap(CTX_STATUS, CTX_CLOSE)
if c.server != nil {
// 结束模块
@@ -249,7 +249,6 @@ type Message struct {
source *Context
target *Context
- frames interface{}
cb func(*Message) *Message
W http.ResponseWriter
@@ -271,7 +270,7 @@ func (m *Message) Time(args ...interface{}) string {
}
}
}
- f := ICE_TIME
+ f := MOD_TIME
if len(args) > 0 {
switch arg := args[0].(type) {
case string:
@@ -373,7 +372,7 @@ func (m *Message) Format(key interface{}) string {
case []byte:
json.Unmarshal(key, &m.meta)
}
- return m.time.Format(ICE_TIME)
+ return m.time.Format(MOD_TIME)
}
func (m *Message) Formats(key string) string {
switch key {
@@ -414,11 +413,6 @@ func (m *Message) Spawn(arg ...interface{}) *Message {
}
return msg
}
-
-func (m *Message) Run(arg ...string) *Message {
- m.target.server.Start(m, arg...)
- return m
-}
func (m *Message) Start(key string, arg ...string) *Message {
m.Travel(func(p *Context, s *Context) {
if s.Name == key {
@@ -433,25 +427,6 @@ func (m *Message) Starts(name string, help string, arg ...string) *Message {
<-m.wait
return m
}
-
-func (m *Message) Right(arg ...interface{}) bool {
- return m.Option(MSG_USERROLE) == ROLE_ROOT || !m.Warn(m.Cmdx(AAA_ROLE, "right", m.Option(MSG_USERROLE), kit.Keys(arg...)) != "ok", "no right")
-}
-func (m *Message) Space(arg interface{}) []string {
- if arg == nil || kit.Format(arg) == m.Conf(CLI_RUNTIME, "node.name") {
- return nil
- }
- return []string{WEB_SPACE, kit.Format(arg)}
-}
-func (m *Message) Event(key string, arg ...string) *Message {
- m.Cmd(GDB_EVENT, "action", key, arg)
- return m
-}
-func (m *Message) Watch(key string, arg ...string) *Message {
- m.Cmd(GDB_EVENT, "listen", key, arg)
- return m
-}
-
func (m *Message) Travel(cb interface{}) *Message {
list := []*Context{m.target}
for i := 0; i < len(list); i++ {
@@ -496,10 +471,6 @@ func (m *Message) Travel(cb interface{}) *Message {
func (m *Message) Search(key interface{}, cb interface{}) *Message {
switch key := key.(type) {
case string:
- if k, ok := Alias[key]; ok {
- key = k
- }
-
// 查找模块
p := m.target.root
if ctx, ok := names[key].(*Context); ok {
@@ -567,32 +538,13 @@ func (m *Message) Search(key interface{}, cb interface{}) *Message {
}
return m
}
-func (m *Message) Preview(arg string) (res string) {
- list := kit.Split(arg)
- m.Search(list[0], func(p *Context, s *Context, key string, cmd *Command) {
- res = kit.Format(kit.Dict("feature", cmd.Meta, "inputs", cmd.List))
- })
- return res
-}
-var count = int32(0)
-
-func (m *Message) AddCmd(cmd *Command) string {
- name := fmt.Sprintf("_cb_%d", atomic.AddInt32(&count, 1))
- m.target.Commands[name] = cmd
- return kit.Keys(m.target.Cap(CTX_FOLLOW), name)
-}
func (m *Message) Cmdy(arg ...interface{}) *Message {
- msg := m.Cmd(arg...)
- m.Copy(msg)
- return m
+ return m.Copy(m.Cmd(arg...))
}
func (m *Message) Cmdx(arg ...interface{}) string {
return kit.Select("", m.Cmd(arg...).meta[MSG_RESULT], 0)
}
-func (m *Message) Cmds(arg ...interface{}) bool {
- return kit.Select("", m.Cmd(arg...).meta[MSG_RESULT], 0) != ""
-}
func (m *Message) Cmd(arg ...interface{}) *Message {
list := kit.Simple(arg...)
if len(list) == 0 {
@@ -604,12 +556,12 @@ func (m *Message) Cmd(arg ...interface{}) *Message {
m.Search(list[0], func(p *Context, c *Context, key string, cmd *Command) {
m.TryCatch(m.Spawns(c), true, func(msg *Message) {
- m = p.Run(msg, cmd, key, list[1:]...)
+ m = p.cmd(msg, cmd, key, list[1:]...)
})
})
if m.Warn(m.Hand == false, "not found %v", list) {
- return m.Set(MSG_RESULT).Cmd(CLI_SYSTEM, list)
+ return m.Set(MSG_RESULT).Cmd("cli.system", list)
}
return m
}
@@ -642,9 +594,6 @@ func (m *Message) Confm(key string, chain interface{}, cbs ...interface{}) map[s
value, _ := val.(map[string]interface{})
return value
}
-func (m *Message) Confs(arg ...interface{}) bool {
- return kit.Format(m.Confv(arg...)) != ""
-}
func (m *Message) Confi(arg ...interface{}) int {
return kit.Int(m.Confv(arg...))
}