forked from x/icebergs
opt icebergs
This commit is contained in:
parent
daa01fcdb6
commit
f8e96a5d76
@ -139,7 +139,7 @@ func init() {
|
|||||||
m.Option(FG, kit.Select(BLUE, arg, 1))
|
m.Option(FG, kit.Select(BLUE, arg, 1))
|
||||||
|
|
||||||
if m.IsCliUA() {
|
if m.IsCliUA() {
|
||||||
_qrcode_cli(m, kit.Select(m.Conf("web.share", kit.Keym(kit.MDB_DOMAIN)), arg, 0))
|
_qrcode_cli(m, kit.Select(m.Conf("share", kit.Keym(kit.MDB_DOMAIN)), arg, 0))
|
||||||
} else {
|
} else {
|
||||||
_qrcode_web(m, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))
|
_qrcode_web(m, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (f *Frame) Close(m *ice.Message, arg ...string) bool {
|
func (f *Frame) Close(m *ice.Message, arg ...string) bool {
|
||||||
|
f.e <- true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,9 +50,6 @@ var Index = &ice.Context{Name: GDB, Help: "事件模块", Commands: map[string]*
|
|||||||
m.Load(TIMER)
|
m.Load(TIMER)
|
||||||
}},
|
}},
|
||||||
ice.CTX_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 {
|
|
||||||
f.e <- true
|
|
||||||
}
|
|
||||||
m.Save(TIMER)
|
m.Save(TIMER)
|
||||||
}},
|
}},
|
||||||
}}
|
}}
|
||||||
|
@ -9,9 +9,6 @@ import (
|
|||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
INNER = "inner"
|
|
||||||
)
|
|
||||||
const ROUTINE = "routine"
|
const ROUTINE = "routine"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -27,13 +24,13 @@ func init() {
|
|||||||
m.Cmdy(mdb.PRUNES, ROUTINE, "", mdb.HASH, kit.MDB_STATUS, cli.STOP)
|
m.Cmdy(mdb.PRUNES, ROUTINE, "", mdb.HASH, kit.MDB_STATUS, cli.STOP)
|
||||||
m.Cmdy(mdb.PRUNES, ROUTINE, "", mdb.HASH, kit.MDB_STATUS, cli.ERROR)
|
m.Cmdy(mdb.PRUNES, ROUTINE, "", mdb.HASH, kit.MDB_STATUS, cli.ERROR)
|
||||||
}},
|
}},
|
||||||
INNER: {Name: "inner", Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
"inner": {Name: "inner", Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
||||||
ls := kit.Split(m.Option("fileline"), ":")
|
ls := kit.Split(m.Option("fileline"), ":")
|
||||||
m.ProcessCommand(INNER, []string{path.Dir(ls[0]), path.Base(ls[0]), ls[1]}, arg...)
|
m.ProcessCommand("inner", []string{path.Dir(ls[0]), path.Base(ls[0]), ls[1]}, arg...)
|
||||||
}},
|
}},
|
||||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
mdb.HashSelect(m, arg...)
|
mdb.HashSelect(m, arg...)
|
||||||
m.PushAction(INNER, mdb.REMOVE)
|
m.PushAction("inner", mdb.REMOVE)
|
||||||
}},
|
}},
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,7 @@ const TIMER = "timer"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||||
TIMER: {Name: TIMER, Help: "定时器", Value: kit.Data(
|
TIMER: {Name: TIMER, Help: "定时器", Value: kit.Data(
|
||||||
kit.MDB_FIELD, "time,hash,delay,interval,order,next,cmd",
|
kit.MDB_FIELD, "time,hash,delay,interval,order,next,cmd", TICK, "1s",
|
||||||
TICK, "1s",
|
|
||||||
)},
|
)},
|
||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
TIMER: {Name: "timer hash id auto create prunes", Help: "定时器", Action: ice.MergeAction(map[string]*ice.Action{
|
TIMER: {Name: "timer hash id auto create prunes", Help: "定时器", Action: ice.MergeAction(map[string]*ice.Action{
|
||||||
|
@ -61,6 +61,8 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (f *Frame) Close(m *ice.Message, arg ...string) bool {
|
func (f *Frame) Close(m *ice.Message, arg ...string) bool {
|
||||||
|
ice.Info.Log = nil
|
||||||
|
close(f.p)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,30 +92,32 @@ var Index = &ice.Context{Name: "log", Help: "日志模块", Configs: map[string]
|
|||||||
WATCH, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "watch.log"), kit.MDB_LIST, []string{
|
WATCH, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "watch.log"), kit.MDB_LIST, []string{
|
||||||
ice.LOG_CREATE, ice.LOG_REMOVE,
|
ice.LOG_CREATE, ice.LOG_REMOVE,
|
||||||
ice.LOG_INSERT, ice.LOG_DELETE,
|
ice.LOG_INSERT, ice.LOG_DELETE,
|
||||||
ice.LOG_SELECT, ice.LOG_MODIFY,
|
ice.LOG_MODIFY, ice.LOG_SELECT,
|
||||||
ice.LOG_EXPORT, ice.LOG_IMPORT,
|
ice.LOG_EXPORT, ice.LOG_IMPORT,
|
||||||
}),
|
}),
|
||||||
BENCH, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "bench.log"), kit.MDB_LIST, []string{}),
|
BENCH, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "bench.log"), kit.MDB_LIST, []string{}),
|
||||||
ERROR, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "error.log"), kit.MDB_LIST, []string{
|
ERROR, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "error.log"), kit.MDB_LIST, []string{
|
||||||
ice.LOG_WARN, ice.LOG_ERROR,
|
ice.LOG_WARN, ice.LOG_ERROR, ice.LOG_DEBUG,
|
||||||
}),
|
}),
|
||||||
TRACE, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "trace.log"), kit.MDB_LIST, []string{}),
|
TRACE, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "trace.log"), kit.MDB_LIST, []string{}),
|
||||||
)},
|
)},
|
||||||
VIEW: {Name: VIEW, Help: "日志格式", Value: kit.Dict(
|
VIEW: {Name: VIEW, Help: "日志格式", Value: kit.Dict(
|
||||||
GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
||||||
ice.LOG_START, ice.LOG_SERVE,
|
ice.LOG_START, ice.LOG_SERVE, ice.LOG_CMDS,
|
||||||
ice.LOG_CMDS,
|
|
||||||
}),
|
}),
|
||||||
YELLOW, kit.Dict(PREFIX, "\033[33m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
YELLOW, kit.Dict(PREFIX, "\033[33m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
||||||
ice.LOG_AUTH, ice.LOG_COST,
|
ice.LOG_AUTH, ice.LOG_COST,
|
||||||
}),
|
}),
|
||||||
RED, kit.Dict(PREFIX, "\033[31m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
RED, kit.Dict(PREFIX, "\033[31m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
||||||
ice.LOG_WARN, ice.LOG_CLOSE,
|
ice.LOG_CLOSE, ice.LOG_WARN,
|
||||||
}),
|
}),
|
||||||
)},
|
)},
|
||||||
SHOW: {Name: SHOW, Help: "日志分流", Value: kit.Dict()},
|
SHOW: {Name: SHOW, Help: "日志分流", Value: kit.Dict()},
|
||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
ice.CTX_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 log.LogDisable {
|
||||||
|
return // 禁用日志
|
||||||
|
}
|
||||||
m.Confm(VIEW, nil, func(key string, value map[string]interface{}) {
|
m.Confm(VIEW, nil, func(key string, value map[string]interface{}) {
|
||||||
kit.Fetch(value[kit.MDB_LIST], func(index int, k string) {
|
kit.Fetch(value[kit.MDB_LIST], func(index int, k string) {
|
||||||
m.Conf(SHOW, kit.Keys(k, VIEW), key)
|
m.Conf(SHOW, kit.Keys(k, VIEW), key)
|
||||||
@ -123,9 +127,6 @@ var Index = &ice.Context{Name: "log", Help: "日志模块", Configs: map[string]
|
|||||||
kit.Fetch(value[kit.MDB_LIST], func(index int, k string) {
|
kit.Fetch(value[kit.MDB_LIST], func(index int, k string) {
|
||||||
m.Conf(SHOW, kit.Keys(k, FILE), key)
|
m.Conf(SHOW, kit.Keys(k, FILE), key)
|
||||||
})
|
})
|
||||||
if log.LogDisable {
|
|
||||||
return // 禁用日志
|
|
||||||
}
|
|
||||||
// 日志文件
|
// 日志文件
|
||||||
if f, p, e := kit.Create(kit.Format(value[kit.MDB_PATH])); m.Assert(e) {
|
if f, p, e := kit.Create(kit.Format(value[kit.MDB_PATH])); m.Assert(e) {
|
||||||
m.Cap(ice.CTX_STREAM, path.Base(p))
|
m.Cap(ice.CTX_STREAM, path.Base(p))
|
||||||
@ -135,10 +136,6 @@ var Index = &ice.Context{Name: "log", Help: "日志模块", Configs: map[string]
|
|||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
ice.CTX_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.Info.Log = nil
|
|
||||||
close(f.p)
|
|
||||||
}
|
|
||||||
}},
|
}},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ func init() {
|
|||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
ENGINE: {Name: "engine type name text auto", Help: "引擎", Action: map[string]*ice.Action{
|
ENGINE: {Name: "engine type name text auto", Help: "引擎", Action: map[string]*ice.Action{
|
||||||
CREATE: {Name: "create type cmd ctx", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
CREATE: {Name: "create type cmd ctx", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Log_CREATE(ENGINE, arg[0], kit.MDB_NAME, kit.Select(arg[0], arg, 1))
|
||||||
m.Rich(ENGINE, nil, kit.Dict(kit.MDB_TYPE, arg[0], kit.MDB_NAME, kit.Select(arg[0], arg, 1), kit.MDB_TEXT, kit.Select("", arg, 2)))
|
m.Rich(ENGINE, nil, kit.Dict(kit.MDB_TYPE, arg[0], kit.MDB_NAME, kit.Select(arg[0], arg, 1), kit.MDB_TEXT, kit.Select("", arg, 2)))
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func _hash_fields(m *ice.Message) []string {
|
func _hash_fields(m *ice.Message) []string {
|
||||||
return kit.Split(kit.Select("time,hash,type,name,text", kit.Join(kit.Simple(m.Optionv(FIELDS)))))
|
return kit.Split(kit.Select("time,hash,type,name,text", m.OptionFields()))
|
||||||
}
|
}
|
||||||
func _hash_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
func _hash_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
||||||
list := map[string]int{}
|
list := map[string]int{}
|
||||||
@ -57,9 +57,8 @@ func _hash_select(m *ice.Message, prefix, chain, field, value string) {
|
|||||||
value = kit.MDB_RANDOMS
|
value = kit.MDB_RANDOMS
|
||||||
}
|
}
|
||||||
fields := _hash_fields(m)
|
fields := _hash_fields(m)
|
||||||
cb := m.Optionv(kit.Keycb(SELECT))
|
|
||||||
m.Richs(prefix, chain, value, func(key string, val map[string]interface{}) {
|
m.Richs(prefix, chain, value, func(key string, val map[string]interface{}) {
|
||||||
switch val = kit.GetMeta(val); cb := cb.(type) {
|
switch val = kit.GetMeta(val); cb := m.Optionv(kit.Keycb(SELECT)).(type) {
|
||||||
case func(fields []string, value map[string]interface{}):
|
case func(fields []string, value map[string]interface{}):
|
||||||
cb(fields, val)
|
cb(fields, val)
|
||||||
default:
|
default:
|
||||||
@ -81,7 +80,7 @@ func _hash_export(m *ice.Message, prefix, chain, file string) {
|
|||||||
|
|
||||||
en := json.NewEncoder(f)
|
en := json.NewEncoder(f)
|
||||||
en.SetIndent("", " ")
|
en.SetIndent("", " ")
|
||||||
e = en.Encode(m.Confv(prefix, kit.Keys(chain, HASH)))
|
m.Assert(en.Encode(m.Confv(prefix, kit.Keys(chain, HASH))))
|
||||||
|
|
||||||
m.Log_EXPORT(kit.MDB_KEY, path.Join(prefix, chain), kit.MDB_FILE, p)
|
m.Log_EXPORT(kit.MDB_KEY, path.Join(prefix, chain), kit.MDB_FILE, p)
|
||||||
m.Conf(prefix, kit.Keys(chain, kit.MDB_HASH), "")
|
m.Conf(prefix, kit.Keys(chain, kit.MDB_HASH), "")
|
||||||
@ -93,8 +92,7 @@ func _hash_import(m *ice.Message, prefix, chain, file string) {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
list := map[string]interface{}{}
|
list := map[string]interface{}{}
|
||||||
de := json.NewDecoder(f)
|
m.Assert(json.NewDecoder(f).Decode(&list))
|
||||||
de.Decode(&list)
|
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
if m.Conf(prefix, kit.Keys(chain, kit.MDB_META, kit.MDB_SHORT)) == "" {
|
if m.Conf(prefix, kit.Keys(chain, kit.MDB_META, kit.MDB_SHORT)) == "" {
|
||||||
@ -115,10 +113,7 @@ func _hash_import(m *ice.Message, prefix, chain, file string) {
|
|||||||
func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
|
func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
|
||||||
fields := _hash_fields(m)
|
fields := _hash_fields(m)
|
||||||
m.Richs(prefix, chain, kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
m.Richs(prefix, chain, kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
||||||
if val[kit.MDB_META] != nil {
|
switch val = kit.GetMeta(val); cb := m.Optionv(kit.Keycb(PRUNES)).(type) {
|
||||||
val = val[kit.MDB_META].(map[string]interface{})
|
|
||||||
}
|
|
||||||
switch cb := m.Optionv(kit.Keycb(PRUNES)).(type) {
|
|
||||||
case func(string, map[string]interface{}) bool:
|
case func(string, map[string]interface{}) bool:
|
||||||
if !cb(key, val) {
|
if !cb(key, val) {
|
||||||
return
|
return
|
||||||
|
@ -4,14 +4,13 @@ import (
|
|||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _list_fields(m *ice.Message) []string {
|
func _list_fields(m *ice.Message) []string {
|
||||||
return kit.Split(kit.Select("time,id,type,name,text", kit.Join(kit.Simple(m.Optionv(FIELDS)))))
|
return kit.Split(kit.Select("time,id,type,name,text", m.OptionFields()))
|
||||||
}
|
}
|
||||||
func _list_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
func _list_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
||||||
list := map[string]int{}
|
list := map[string]int{}
|
||||||
@ -51,9 +50,8 @@ func _list_select(m *ice.Message, prefix, chain, field, value string) {
|
|||||||
field = ""
|
field = ""
|
||||||
}
|
}
|
||||||
fields := _list_fields(m)
|
fields := _list_fields(m)
|
||||||
cb := m.Optionv(kit.Keycb(SELECT))
|
m.Grows(prefix, chain, kit.Select(m.Option(ice.CACHE_FIELD), field), kit.Select(m.Option(ice.CACHE_VALUE), value), func(index int, val map[string]interface{}) {
|
||||||
m.Grows(prefix, chain, kit.Select(m.Option(CACHE_FIELD), field), kit.Select(m.Option(CACHE_VALUE), value), func(index int, val map[string]interface{}) {
|
switch val = kit.GetMeta(val); cb := m.Optionv(kit.Keycb(SELECT)).(type) {
|
||||||
switch val = kit.GetMeta(val); cb := cb.(type) {
|
|
||||||
case func(fields []string, value map[string]interface{}):
|
case func(fields []string, value map[string]interface{}):
|
||||||
cb(fields, val)
|
cb(fields, val)
|
||||||
default:
|
default:
|
||||||
@ -74,14 +72,14 @@ func _list_export(m *ice.Message, prefix, chain, file string) {
|
|||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
head := kit.Split(m.Option(FIELDS))
|
head := kit.Split(m.OptionFields())
|
||||||
m.Grows(prefix, chain, "", "", func(index int, val map[string]interface{}) {
|
m.Grows(prefix, chain, "", "", func(index int, val map[string]interface{}) {
|
||||||
if val = kit.GetMeta(val); index == 0 {
|
if val = kit.GetMeta(val); index == 0 {
|
||||||
if len(head) == 0 { // 默认表头
|
if len(head) == 0 || head[0] == "detail" { // 默认表头
|
||||||
for k := range val {
|
for k := range val {
|
||||||
head = append(head, k)
|
head = append(head, k)
|
||||||
}
|
}
|
||||||
sort.Strings(head)
|
kit.Sort(head)
|
||||||
}
|
}
|
||||||
w.Write(head) // 输出表头
|
w.Write(head) // 输出表头
|
||||||
}
|
}
|
||||||
@ -95,6 +93,8 @@ func _list_export(m *ice.Message, prefix, chain, file string) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
m.Log_EXPORT(kit.MDB_KEY, path.Join(prefix, chain), kit.MDB_FILE, p, kit.MDB_COUNT, count)
|
m.Log_EXPORT(kit.MDB_KEY, path.Join(prefix, chain), kit.MDB_FILE, p, kit.MDB_COUNT, count)
|
||||||
|
m.Conf(prefix, kit.Keys(chain, kit.Keym(kit.MDB_COUNT)), 0)
|
||||||
|
m.Conf(prefix, kit.Keys(chain, kit.MDB_LIST), "")
|
||||||
m.Echo(p)
|
m.Echo(p)
|
||||||
}
|
}
|
||||||
func _list_import(m *ice.Message, prefix, chain, file string) {
|
func _list_import(m *ice.Message, prefix, chain, file string) {
|
||||||
@ -154,7 +154,7 @@ func ListAction(fields ...string) map[string]*ice.Action {
|
|||||||
m.Config(kit.MDB_COUNT, 0)
|
m.Config(kit.MDB_COUNT, 0)
|
||||||
}},
|
}},
|
||||||
IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmdy(IMPORT, m.PrefixKey(), "", LIST)
|
m.Cmdy(IMPORT, m.PrefixKey(), "", LIST, arg)
|
||||||
}},
|
}},
|
||||||
PRUNES: {Name: "prunes", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
PRUNES: {Name: "prunes", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmdy(PRUNES, m.PrefixKey(), "", LIST, arg)
|
m.Cmdy(PRUNES, m.PrefixKey(), "", LIST, arg)
|
||||||
|
@ -46,12 +46,6 @@ const (
|
|||||||
PREV = "prev"
|
PREV = "prev"
|
||||||
)
|
)
|
||||||
const (
|
const (
|
||||||
CACHE_LIMIT = "cache.limit"
|
|
||||||
CACHE_FIELD = "cache.field"
|
|
||||||
CACHE_VALUE = "cache.value"
|
|
||||||
CACHE_OFFEND = "cache.offend"
|
|
||||||
CACHE_FILTER = "cache.filter"
|
|
||||||
|
|
||||||
CACHE_CLEAR_ON_EXIT = "cache.clear.on.exit"
|
CACHE_CLEAR_ON_EXIT = "cache.clear.on.exit"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -92,19 +86,12 @@ func NextPageLimit(m *ice.Message, total string, arg ...string) {
|
|||||||
m.ProcessHold()
|
m.ProcessHold()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func SetPage(m *ice.Message, arg ...string) {
|
|
||||||
m.Option(CACHE_LIMIT, kit.Select("10", arg, 0))
|
|
||||||
m.Option(CACHE_OFFEND, kit.Select("0", arg, 1))
|
|
||||||
m.Option(CACHE_FILTER, kit.Select("", arg, 2))
|
|
||||||
}
|
|
||||||
|
|
||||||
const MDB = "mdb"
|
const MDB = "mdb"
|
||||||
|
|
||||||
var Index = &ice.Context{Name: MDB, Help: "数据模块", Commands: map[string]*ice.Command{
|
var Index = &ice.Context{Name: MDB, Help: "数据模块", Commands: map[string]*ice.Command{
|
||||||
ice.CTX_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) {}},
|
||||||
}},
|
ice.CTX_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) {
|
|
||||||
}},
|
|
||||||
INSERT: {Name: "insert key sub type arg...", Help: "添加", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
INSERT: {Name: "insert key sub type arg...", Help: "添加", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
switch arg[2] {
|
switch arg[2] {
|
||||||
case ZONE:
|
case ZONE:
|
||||||
@ -168,11 +155,11 @@ var Index = &ice.Context{Name: MDB, Help: "数据模块", Commands: map[string]*
|
|||||||
INPUTS: {Name: "inputs key sub type field value", Help: "补全", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
INPUTS: {Name: "inputs key sub type field value", Help: "补全", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
switch arg[2] {
|
switch arg[2] {
|
||||||
case ZONE:
|
case ZONE:
|
||||||
_list_inputs(m, arg[0], _domain_chain(m, kit.Keys(arg[1], kit.KeyHash(arg[3]))), kit.Select("name", arg, 4), kit.Select("", arg, 5))
|
_list_inputs(m, arg[0], _domain_chain(m, kit.Keys(arg[1], kit.KeyHash(arg[3]))), kit.Select(kit.MDB_NAME, arg, 4), kit.Select("", arg, 5))
|
||||||
case HASH:
|
case HASH:
|
||||||
_hash_inputs(m, arg[0], _domain_chain(m, arg[1]), kit.Select("name", arg, 3), kit.Select("", arg, 4))
|
_hash_inputs(m, arg[0], _domain_chain(m, arg[1]), kit.Select(kit.MDB_NAME, arg, 3), kit.Select("", arg, 4))
|
||||||
case LIST:
|
case LIST:
|
||||||
_list_inputs(m, arg[0], _domain_chain(m, arg[1]), kit.Select("name", arg, 3), kit.Select("", arg, 4))
|
_list_inputs(m, arg[0], _domain_chain(m, arg[1]), kit.Select(kit.MDB_NAME, arg, 3), kit.Select("", arg, 4))
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
PRUNES: {Name: "prunes key sub type [field value]...", Help: "清理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
PRUNES: {Name: "prunes key sub type [field value]...", Help: "清理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
@ -13,6 +13,7 @@ func init() {
|
|||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
PLUGIN: {Name: "plugin type name text auto", Help: "插件", Action: map[string]*ice.Action{
|
PLUGIN: {Name: "plugin type name text auto", Help: "插件", Action: map[string]*ice.Action{
|
||||||
CREATE: {Name: "create type cmd ctx", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
CREATE: {Name: "create type cmd ctx", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Log_CREATE(PLUGIN, arg[0], kit.MDB_NAME, kit.Select(arg[0], arg, 1))
|
||||||
m.Rich(PLUGIN, nil, kit.Dict(kit.MDB_TYPE, arg[0], kit.MDB_NAME, kit.Select(arg[0], arg, 1), kit.MDB_TEXT, kit.Select("", arg, 2)))
|
m.Rich(PLUGIN, nil, kit.Dict(kit.MDB_TYPE, arg[0], kit.MDB_NAME, kit.Select(arg[0], arg, 1), kit.MDB_TEXT, kit.Select("", arg, 2)))
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
@ -26,7 +26,7 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Option(ice.MSG_FIELDS, kit.Select("ctx,cmd,time,size,type,name,text", kit.Select(m.Option(ice.MSG_FIELDS), arg, 2)))
|
m.OptionFields(kit.Select("ctx,cmd,time,size,type,name,text", kit.Select(m.OptionFields(), arg, 2)))
|
||||||
for _, k := range strings.Split(arg[0], ",") {
|
for _, k := range strings.Split(arg[0], ",") {
|
||||||
for _, kk := range strings.Split(arg[1], ",") {
|
for _, kk := range strings.Split(arg[1], ",") {
|
||||||
m.Richs(SEARCH, nil, k, func(key string, value map[string]interface{}) {
|
m.Richs(SEARCH, nil, k, func(key string, value map[string]interface{}) {
|
||||||
|
@ -61,7 +61,7 @@ func _cat_find(m *ice.Message, name string) io.ReadCloser {
|
|||||||
return NewReadCloser(bytes.NewBuffer(b))
|
return NewReadCloser(bytes.NewBuffer(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := m.Cmd("web.spide", ice.DEV, "raw", "GET", path.Join("/share/local/", name))
|
msg := m.Cmd("spide", ice.DEV, "raw", "GET", path.Join("/share/local/", name))
|
||||||
if msg.Result(0) == ice.ErrWarn {
|
if msg.Result(0) == ice.ErrWarn {
|
||||||
return NewReadCloser(bytes.NewBufferString(""))
|
return NewReadCloser(bytes.NewBufferString(""))
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ func _cat_list(m *ice.Message, name string) {
|
|||||||
|
|
||||||
f := _cat_find(m, name)
|
f := _cat_find(m, name)
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return
|
return // 没有文件
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ func init() {
|
|||||||
_cat_list(m, path.Join(arg[2], arg[1]))
|
_cat_list(m, path.Join(arg[2], arg[1]))
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
|
if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) {
|
||||||
m.Cmdy(DIR, arg)
|
m.Cmdy(DIR, arg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func _dir_list(m *ice.Message, root string, name string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) *ice.Message {
|
func _dir_list(m *ice.Message, root string, name string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) *ice.Message {
|
||||||
if !_cat_right(m, name) {
|
if !_cat_right(m, path.Join(root, name)) {
|
||||||
return m // 没有权限
|
return m // 没有权限
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range fs {
|
for _, f := range fs {
|
||||||
if f.Name() == "." || f.Name() == ".." {
|
if f.Name() == ice.PT || f.Name() == ".." {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(f.Name(), ".") && dir_type != TYPE_ALL {
|
if strings.HasPrefix(f.Name(), ice.PT) && dir_type != TYPE_ALL {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,11 +61,11 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
|
|||||||
m.Push(field, strings.Repeat("| ", level-1)+"|-"+f.Name())
|
m.Push(field, strings.Repeat("| ", level-1)+"|-"+f.Name())
|
||||||
}
|
}
|
||||||
case "full":
|
case "full":
|
||||||
m.Push(field, path.Join(root, name, f.Name())+kit.Select("", "/", f.IsDir()))
|
m.Push(field, path.Join(root, name, f.Name())+kit.Select("", ice.PS, f.IsDir()))
|
||||||
case kit.MDB_PATH:
|
case kit.MDB_PATH:
|
||||||
m.Push(field, path.Join(name, f.Name())+kit.Select("", "/", f.IsDir()))
|
m.Push(field, path.Join(name, f.Name())+kit.Select("", ice.PS, f.IsDir()))
|
||||||
case kit.MDB_FILE:
|
case kit.MDB_FILE:
|
||||||
m.Push(field, f.Name()+kit.Select("", "/", f.IsDir()))
|
m.Push(field, f.Name()+kit.Select("", ice.PS, f.IsDir()))
|
||||||
case kit.MDB_NAME:
|
case kit.MDB_NAME:
|
||||||
m.Push(field, f.Name())
|
m.Push(field, f.Name())
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ func _defs_file(m *ice.Message, name string, text ...string) {
|
|||||||
}
|
}
|
||||||
func _push_file(m *ice.Message, name string, text ...string) {
|
func _push_file(m *ice.Message, name string, text ...string) {
|
||||||
p := path.Join(m.Option(DIR_ROOT), name)
|
p := path.Join(m.Option(DIR_ROOT), name)
|
||||||
if strings.Contains(p, "/") {
|
if strings.Contains(p, ice.PS) {
|
||||||
os.MkdirAll(path.Dir(p), ice.MOD_DIR)
|
os.MkdirAll(path.Dir(p), ice.MOD_DIR)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ func _link_file(m *ice.Message, name string, from string) {
|
|||||||
}
|
}
|
||||||
os.Remove(name)
|
os.Remove(name)
|
||||||
os.MkdirAll(path.Dir(name), ice.MOD_DIR)
|
os.MkdirAll(path.Dir(name), ice.MOD_DIR)
|
||||||
os.Link(from, name)
|
m.Warn(os.Link(from, name) != nil, "link err of", from)
|
||||||
m.Echo(name)
|
m.Echo(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ func init() {
|
|||||||
m.Cmdy(DIR, kit.Select("./", arg, 1), PATH).RenameAppend(PATH, FILE)
|
m.Cmdy(DIR, kit.Select("./", arg, 1), PATH).RenameAppend(PATH, FILE)
|
||||||
m.ProcessAgain()
|
m.ProcessAgain()
|
||||||
case kit.MDB_NAME:
|
case kit.MDB_NAME:
|
||||||
m.Push(arg[0], kit.Split(m.Option(FILE), "/"))
|
m.Push(arg[0], kit.Split(m.Option(FILE), ice.PS))
|
||||||
case kit.MDB_LIMIT:
|
case kit.MDB_LIMIT:
|
||||||
m.Push(arg[0], kit.List("10", "20", "30", "50"))
|
m.Push(arg[0], kit.List("10", "20", "30", "50"))
|
||||||
}
|
}
|
||||||
@ -66,10 +66,10 @@ func init() {
|
|||||||
}},
|
}},
|
||||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Fields(len(kit.Slice(arg, 0, 2)), "time,name,count,file", m.Config(kit.MDB_FIELD))
|
m.Fields(len(kit.Slice(arg, 0, 2)), "time,name,count,file", m.Config(kit.MDB_FIELD))
|
||||||
mdb.SetPage(m, kit.Slice(arg, 2)...)
|
m.OptionPage(kit.Slice(arg, 2)...)
|
||||||
|
|
||||||
mdb.ZoneSelect(m.Spawn(c), arg...).Table(func(index int, value map[string]string, head []string) {
|
mdb.ZoneSelect(m.Spawn(c), arg...).Table(func(index int, value map[string]string, head []string) {
|
||||||
if strings.Contains(value[kit.MDB_TEXT], m.Option(mdb.CACHE_FILTER)) {
|
if strings.Contains(value[kit.MDB_TEXT], m.Option(ice.CACHE_FILTER)) {
|
||||||
m.Push("", value, head)
|
m.Push("", value, head)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -22,7 +22,7 @@ func _trash_create(m *ice.Message, name string) {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
h := kit.Hashs(f)
|
h := kit.Hashs(f)
|
||||||
p := path.Join(m.Conf(TRASH, kit.META_PATH), h[:2], h)
|
p := path.Join(m.Config(kit.MDB_PATH), h[:2], h)
|
||||||
os.MkdirAll(path.Dir(p), ice.MOD_DIR)
|
os.MkdirAll(path.Dir(p), ice.MOD_DIR)
|
||||||
os.Rename(name, p)
|
os.Rename(name, p)
|
||||||
m.Cmdy(mdb.INSERT, TRASH, "", mdb.HASH, kit.MDB_FILE, p, kit.MDB_FROM, name)
|
m.Cmdy(mdb.INSERT, TRASH, "", mdb.HASH, kit.MDB_FILE, p, kit.MDB_FROM, name)
|
||||||
|
@ -95,8 +95,8 @@ func (f *Frame) change(m *ice.Message, ls []string) []string {
|
|||||||
if target == "~" {
|
if target == "~" {
|
||||||
target = ""
|
target = ""
|
||||||
}
|
}
|
||||||
m.Spawn(f.target).Search(target+".", func(p *ice.Context, s *ice.Context, key string) {
|
m.Spawn(f.target).Search(target+ice.PT, func(p *ice.Context, s *ice.Context, key string) {
|
||||||
m.Info("choice: %s", s.Name)
|
m.Log_SELECT(ctx.CONTEXT, s.Name)
|
||||||
f.target = s
|
f.target = s
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -113,20 +113,14 @@ func (f *Frame) alias(m *ice.Message, ls []string) []string {
|
|||||||
return ls
|
return ls
|
||||||
}
|
}
|
||||||
func (f *Frame) parse(m *ice.Message, line string) string {
|
func (f *Frame) parse(m *ice.Message, line string) string {
|
||||||
if strings.HasPrefix(line, "<") {
|
|
||||||
fmt.Fprintf(m.O, line)
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, one := range kit.Split(line, ";", ";", ";") {
|
for _, one := range kit.Split(line, ";", ";", ";") {
|
||||||
one = strings.TrimSpace(one)
|
|
||||||
msg := m.Spawn(f.target)
|
msg := m.Spawn(f.target)
|
||||||
msg.Option("_cmd", one)
|
|
||||||
|
|
||||||
ls := f.change(msg, f.alias(msg, kit.Split(one)))
|
ls := f.change(msg, f.alias(msg, kit.Split(strings.TrimSpace(one))))
|
||||||
if len(ls) == 0 {
|
if len(ls) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Cmdy(ls[0], ls[1:])
|
msg.Cmdy(ls[0], ls[1:])
|
||||||
|
|
||||||
_args, _ := msg.Optionv(ice.MSG_ARGS).([]interface{})
|
_args, _ := msg.Optionv(ice.MSG_ARGS).([]interface{})
|
||||||
@ -176,12 +170,6 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
|
|||||||
}
|
}
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
func (f *Frame) close() {
|
|
||||||
if stdin, ok := f.stdin.(io.Closer); ok {
|
|
||||||
stdin.Close()
|
|
||||||
}
|
|
||||||
f.stdin = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
|
func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
|
||||||
return f
|
return f
|
||||||
@ -211,7 +199,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
|||||||
f.scan(m, STDIO, "")
|
f.scan(m, STDIO, "")
|
||||||
|
|
||||||
default: // 脚本文件
|
default: // 脚本文件
|
||||||
if strings.Contains(m.Option(ice.MSG_SCRIPT), "/") {
|
if strings.Contains(m.Option(ice.MSG_SCRIPT), ice.PS) {
|
||||||
f.source = path.Join(path.Dir(m.Option(ice.MSG_SCRIPT)), f.source)
|
f.source = path.Join(path.Dir(m.Option(ice.MSG_SCRIPT)), f.source)
|
||||||
}
|
}
|
||||||
m.Option(ice.MSG_SCRIPT, f.source)
|
m.Option(ice.MSG_SCRIPT, f.source)
|
||||||
@ -232,6 +220,10 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (f *Frame) Close(m *ice.Message, arg ...string) bool {
|
func (f *Frame) Close(m *ice.Message, arg ...string) bool {
|
||||||
|
if stdin, ok := f.stdin.(io.Closer); ok {
|
||||||
|
stdin.Close()
|
||||||
|
}
|
||||||
|
f.stdin = nil
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,11 +251,6 @@ func init() {
|
|||||||
PS2, []interface{}{kit.MDB_COUNT, " ", TARGET, "> "},
|
PS2, []interface{}{kit.MDB_COUNT, " ", TARGET, "> "},
|
||||||
)},
|
)},
|
||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
if f, ok := m.Target().Server().(*Frame); ok {
|
|
||||||
f.close()
|
|
||||||
}
|
|
||||||
}},
|
|
||||||
SOURCE: {Name: "source file", Help: "脚本解析", Action: ice.MergeAction(map[string]*ice.Action{
|
SOURCE: {Name: "source file", Help: "脚本解析", Action: ice.MergeAction(map[string]*ice.Action{
|
||||||
mdb.REPEAT: {Name: "repeat", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
|
mdb.REPEAT: {Name: "repeat", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmdy(SCREEN, m.Option(kit.MDB_TEXT))
|
m.Cmdy(SCREEN, m.Option(kit.MDB_TEXT))
|
||||||
@ -300,7 +287,7 @@ func init() {
|
|||||||
}},
|
}},
|
||||||
RETURN: {Name: "return", Help: "结束脚本", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
RETURN: {Name: "return", Help: "结束脚本", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
f := m.Optionv(FRAME).(*Frame)
|
f := m.Optionv(FRAME).(*Frame)
|
||||||
f.close()
|
f.Close(m, arg...)
|
||||||
}},
|
}},
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ func _host_list(m *ice.Message, name string) {
|
|||||||
|
|
||||||
if ips, e := v.Addrs(); m.Assert(e) {
|
if ips, e := v.Addrs(); m.Assert(e) {
|
||||||
for _, x := range ips {
|
for _, x := range ips {
|
||||||
ip := strings.Split(x.String(), "/")
|
ip := strings.Split(x.String(), ice.PS)
|
||||||
if strings.Contains(ip[0], ":") || len(ip) == 0 {
|
if strings.Contains(ip[0], ":") || len(ip) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -145,10 +145,10 @@ func init() {
|
|||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
"/cache/": {Name: "/cache/", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"/cache/": {Name: "/cache/", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Richs(CACHE, nil, arg[0], func(key string, value map[string]interface{}) {
|
m.Richs(CACHE, nil, arg[0], func(key string, value map[string]interface{}) {
|
||||||
if kit.Format(value[kit.MDB_FILE]) != "" {
|
if kit.Format(value[kit.MDB_FILE]) == "" {
|
||||||
m.RenderDownload(value[kit.MDB_FILE])
|
|
||||||
} else {
|
|
||||||
m.RenderResult(value[kit.MDB_TEXT])
|
m.RenderResult(value[kit.MDB_TEXT])
|
||||||
|
} else {
|
||||||
|
m.RenderDownload(value[kit.MDB_FILE])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
|
@ -122,7 +122,8 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if len(arg) > 2 { // 加载插件
|
} else if len(arg) > 2 { // 加载插件
|
||||||
m.ShowPlugin(arg[0], arg[1], arg[2], ctx.ACTION, ctx.COMMAND)
|
m.Cmdy(SPACE, arg[0], ctx.CONTEXT, arg[1], ctx.COMMAND, arg[2])
|
||||||
|
m.ProcessField(ctx.ACTION, ctx.COMMAND)
|
||||||
|
|
||||||
} else if len(arg) > 1 { // 命令列表
|
} else if len(arg) > 1 { // 命令列表
|
||||||
m.Cmd(SPACE, arg[0], ctx.CONTEXT, arg[1], ctx.COMMAND).Table(func(index int, value map[string]string, head []string) {
|
m.Cmd(SPACE, arg[0], ctx.CONTEXT, arg[1], ctx.COMMAND).Table(func(index int, value map[string]string, head []string) {
|
||||||
|
@ -99,7 +99,7 @@ func _serve_params(msg *ice.Message, path string) {
|
|||||||
}
|
}
|
||||||
func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.ResponseWriter, r *http.Request) {
|
func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.ResponseWriter, r *http.Request) {
|
||||||
// 环境变量
|
// 环境变量
|
||||||
msg.Option(mdb.CACHE_LIMIT, "10")
|
msg.Option(ice.CACHE_LIMIT, "10")
|
||||||
msg.Option(ice.MSG_OUTPUT, "")
|
msg.Option(ice.MSG_OUTPUT, "")
|
||||||
msg.Option(ice.MSG_SESSID, "")
|
msg.Option(ice.MSG_SESSID, "")
|
||||||
for _, v := range r.Cookies() {
|
for _, v := range r.Cookies() {
|
||||||
@ -173,7 +173,7 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
|||||||
if cmds, ok := _serve_login(msg, kit.Simple(msg.Optionv(ice.MSG_CMDS)), w, r); ok {
|
if cmds, ok := _serve_login(msg, kit.Simple(msg.Optionv(ice.MSG_CMDS)), w, r); ok {
|
||||||
msg.Option(ice.MSG_OPTS, msg.Optionv(ice.MSG_OPTION))
|
msg.Option(ice.MSG_OPTS, msg.Optionv(ice.MSG_OPTION))
|
||||||
msg.Target().Cmd(msg, key, cmds...)
|
msg.Target().Cmd(msg, key, cmds...)
|
||||||
msg.Cost(kit.Format("%s %v %v", r.URL.Path, cmds, msg.Format(ice.MSG_APPEND)))
|
msg.Cost(kit.Format("%s %v %v", r.URL.Path, cmds, msg.FormatSize()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 输出响应
|
// 输出响应
|
||||||
@ -255,7 +255,6 @@ func init() {
|
|||||||
)},
|
)},
|
||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
ice.CTX_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.Done(true)
|
|
||||||
m.Cmd(SERVE).Table(func(index int, value map[string]string, head []string) {
|
m.Cmd(SERVE).Table(func(index int, value map[string]string, head []string) {
|
||||||
m.Done(value[kit.MDB_STATUS] == tcp.START)
|
m.Done(value[kit.MDB_STATUS] == tcp.START)
|
||||||
})
|
})
|
||||||
|
@ -83,7 +83,7 @@ func _space_handle(m *ice.Message, safe bool, send map[string]*ice.Message, c *w
|
|||||||
socket, msg := c, m.Spawn(b)
|
socket, msg := c, m.Spawn(b)
|
||||||
target := kit.Simple(msg.Optionv(ice.MSG_TARGET))
|
target := kit.Simple(msg.Optionv(ice.MSG_TARGET))
|
||||||
source := kit.Simple(msg.Optionv(ice.MSG_SOURCE), name)
|
source := kit.Simple(msg.Optionv(ice.MSG_SOURCE), name)
|
||||||
msg.Log("recv", "%v->%v %s %v", source, target, msg.Detailv(), msg.Format(kit.MDB_META))
|
msg.Log("recv", "%v->%v %s %v", source, target, msg.Detailv(), msg.FormatMeta())
|
||||||
|
|
||||||
if len(target) == 0 { // 本地执行
|
if len(target) == 0 { // 本地执行
|
||||||
msg.Log_AUTH(aaa.USERROLE, msg.Option(ice.MSG_USERROLE), aaa.USERNAME, msg.Option(ice.MSG_USERNAME))
|
msg.Log_AUTH(aaa.USERROLE, msg.Option(ice.MSG_USERROLE), aaa.USERNAME, msg.Option(ice.MSG_USERNAME))
|
||||||
@ -134,15 +134,15 @@ func _space_exec(msg *ice.Message, source, target []string, c *websocket.Conn, n
|
|||||||
|
|
||||||
msg.Set(ice.MSG_OPTS)
|
msg.Set(ice.MSG_OPTS)
|
||||||
_space_echo(msg, []string{}, kit.Revert(source)[1:], c, name)
|
_space_echo(msg, []string{}, kit.Revert(source)[1:], c, name)
|
||||||
msg.Cost(kit.Format("%v->%v %v %v", source, target, msg.Detailv(), msg.Format(ice.MSG_APPEND)))
|
msg.Cost(kit.Format("%v->%v %v %v", source, target, msg.Detailv(), msg.FormatSize()))
|
||||||
}
|
}
|
||||||
func _space_echo(msg *ice.Message, source, target []string, c *websocket.Conn, name string) {
|
func _space_echo(msg *ice.Message, source, target []string, c *websocket.Conn, name string) {
|
||||||
msg.Optionv(ice.MSG_SOURCE, source)
|
msg.Optionv(ice.MSG_SOURCE, source)
|
||||||
msg.Optionv(ice.MSG_TARGET, target)
|
msg.Optionv(ice.MSG_TARGET, target)
|
||||||
msg.Assert(c.WriteMessage(1, []byte(msg.Format(kit.MDB_META))))
|
msg.Assert(c.WriteMessage(1, []byte(msg.FormatMeta())))
|
||||||
|
|
||||||
target = append([]string{name}, target...)
|
target = append([]string{name}, target...)
|
||||||
msg.Log("send", "%v->%v %v %v", source, target, msg.Detailv(), msg.Format(kit.MDB_META))
|
msg.Log("send", "%v->%v %v %v", source, target, msg.Detailv(), msg.FormatMeta())
|
||||||
}
|
}
|
||||||
func _space_send(m *ice.Message, space string, arg ...string) {
|
func _space_send(m *ice.Message, space string, arg ...string) {
|
||||||
if space == "" || space == MYSELF || space == ice.Info.NodeName {
|
if space == "" || space == MYSELF || space == ice.Info.NodeName {
|
||||||
|
@ -58,7 +58,7 @@ func _story_index(m *ice.Message, name string, withdata bool) {
|
|||||||
func _story_history(m *ice.Message, name string) {
|
func _story_history(m *ice.Message, name string) {
|
||||||
// 历史记录
|
// 历史记录
|
||||||
list := m.Cmd(STORY, INDEX, name).Append(LIST)
|
list := m.Cmd(STORY, INDEX, name).Append(LIST)
|
||||||
for i := 0; i < kit.Int(kit.Select("30", m.Option(mdb.CACHE_LIMIT))) && list != ""; i++ {
|
for i := 0; i < kit.Int(kit.Select("30", m.Option(ice.CACHE_LIMIT))) && list != ""; i++ {
|
||||||
m.Richs(STORY, nil, list, func(key string, value map[string]interface{}) {
|
m.Richs(STORY, nil, list, func(key string, value map[string]interface{}) {
|
||||||
// 直连节点
|
// 直连节点
|
||||||
m.Push(key, value, []string{kit.MDB_TIME, kit.MDB_KEY, kit.MDB_COUNT, SCENE, STORY})
|
m.Push(key, value, []string{kit.MDB_TIME, kit.MDB_KEY, kit.MDB_COUNT, SCENE, STORY})
|
||||||
|
@ -88,6 +88,7 @@ func (web *Frame) Start(m *ice.Message, arg ...string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (web *Frame) Close(m *ice.Message, arg ...string) bool {
|
func (web *Frame) Close(m *ice.Message, arg ...string) bool {
|
||||||
|
m.Done(true)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +418,7 @@ func init() {
|
|||||||
m.ProcessInner()
|
m.ProcessInner()
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||||
m.Option(mdb.CACHE_LIMIT, -1)
|
m.Option(ice.CACHE_LIMIT, -1)
|
||||||
if m.Action(mdb.CREATE); len(arg) == 0 { // 矩阵列表
|
if m.Action(mdb.CREATE); len(arg) == 0 { // 矩阵列表
|
||||||
m.Fields(len(arg), "time,name,npage,nhash")
|
m.Fields(len(arg), "time,name,npage,nhash")
|
||||||
m.Cmdy(mdb.SELECT, m.Prefix(MATRIX), "", mdb.HASH)
|
m.Cmdy(mdb.SELECT, m.Prefix(MATRIX), "", mdb.HASH)
|
||||||
|
28
conf.go
28
conf.go
@ -3,6 +3,7 @@ package ice
|
|||||||
const (
|
const (
|
||||||
TB = "\t"
|
TB = "\t"
|
||||||
SP = " "
|
SP = " "
|
||||||
|
PS = "/"
|
||||||
PT = "."
|
PT = "."
|
||||||
NL = "\n"
|
NL = "\n"
|
||||||
OF = " of "
|
OF = " of "
|
||||||
@ -106,11 +107,11 @@ const ( // DIR
|
|||||||
ETC_PATH = "etc/path"
|
ETC_PATH = "etc/path"
|
||||||
|
|
||||||
SRC_HELP = "src/help"
|
SRC_HELP = "src/help"
|
||||||
SRC_MAIN_SHY = "src/main.shy"
|
|
||||||
SRC_MAIN_GO = "src/main.go"
|
SRC_MAIN_GO = "src/main.go"
|
||||||
|
SRC_MAIN_SHY = "src/main.shy"
|
||||||
SRC_VERSION_GO = "src/version.go"
|
SRC_VERSION_GO = "src/version.go"
|
||||||
SRC_BINPACK_GO = "src/binpack.go"
|
SRC_BINPACK_GO = "src/binpack.go"
|
||||||
MAKEFILE = "makefile"
|
MAKEFILE = "Makefile"
|
||||||
GO_MOD = "go.mod"
|
GO_MOD = "go.mod"
|
||||||
GO_SUM = "go.sum"
|
GO_SUM = "go.sum"
|
||||||
)
|
)
|
||||||
@ -125,7 +126,6 @@ const ( // MSG
|
|||||||
MSG_SOURCE = "_source"
|
MSG_SOURCE = "_source"
|
||||||
MSG_TARGET = "_target"
|
MSG_TARGET = "_target"
|
||||||
MSG_HANDLE = "_handle"
|
MSG_HANDLE = "_handle"
|
||||||
MSG_RENDER = "_render"
|
|
||||||
MSG_OUTPUT = "_output"
|
MSG_OUTPUT = "_output"
|
||||||
MSG_ARGS = "_args"
|
MSG_ARGS = "_args"
|
||||||
|
|
||||||
@ -149,9 +149,9 @@ const ( // MSG
|
|||||||
MSG_USERPOD = "user.pod"
|
MSG_USERPOD = "user.pod"
|
||||||
MSG_USERADDR = "user.addr"
|
MSG_USERADDR = "user.addr"
|
||||||
MSG_USERDATA = "user.data"
|
MSG_USERDATA = "user.data"
|
||||||
MSG_USERNICK = "user.nick"
|
|
||||||
MSG_USERNAME = "user.name"
|
|
||||||
MSG_USERROLE = "user.role"
|
MSG_USERROLE = "user.role"
|
||||||
|
MSG_USERNAME = "user.name"
|
||||||
|
MSG_USERNICK = "user.nick"
|
||||||
MSG_USERZONE = "user.zone"
|
MSG_USERZONE = "user.zone"
|
||||||
MSG_LANGUAGE = "user.lang"
|
MSG_LANGUAGE = "user.lang"
|
||||||
|
|
||||||
@ -159,13 +159,16 @@ const ( // MSG
|
|||||||
MSG_TOPIC = "sess.topic"
|
MSG_TOPIC = "sess.topic"
|
||||||
MSG_RIVER = "sess.river"
|
MSG_RIVER = "sess.river"
|
||||||
MSG_STORM = "sess.storm"
|
MSG_STORM = "sess.storm"
|
||||||
MSG_LOCAL = "sess.local"
|
|
||||||
MSG_TOAST = "sess.toast"
|
MSG_TOAST = "sess.toast"
|
||||||
|
MSG_LOCAL = "sess.local"
|
||||||
|
|
||||||
CACHE_LIMIT = "cache.limit"
|
CACHE_LIMIT = "cache.limit"
|
||||||
CACHE_BEGIN = "cache.begin"
|
CACHE_BEGIN = "cache.begin"
|
||||||
CACHE_COUNT = "cache.count"
|
CACHE_COUNT = "cache.count"
|
||||||
CACHE_OFFEND = "cache.offend"
|
CACHE_OFFEND = "cache.offend"
|
||||||
|
CACHE_FILTER = "cache.filter"
|
||||||
|
CACHE_VALUE = "cache.value"
|
||||||
|
CACHE_FIELD = "cache.field"
|
||||||
)
|
)
|
||||||
const ( // RENDER
|
const ( // RENDER
|
||||||
RENDER_RAW = "_raw"
|
RENDER_RAW = "_raw"
|
||||||
@ -198,12 +201,13 @@ const ( // PROCESS
|
|||||||
FIELD_PREFIX = "_prefix"
|
FIELD_PREFIX = "_prefix"
|
||||||
)
|
)
|
||||||
const ( // Err
|
const ( // Err
|
||||||
ErrWarn = "warn: "
|
ErrWarn = "warn: "
|
||||||
ErrExists = "exists: "
|
ErrExists = "exists: "
|
||||||
ErrExpire = "expire: "
|
ErrExpire = "expire: "
|
||||||
ErrNotLogin = "not login: "
|
ErrNotLogin = "not login: "
|
||||||
ErrNotFound = "not found: "
|
ErrNotFound = "not found: "
|
||||||
ErrNotRight = "not right: "
|
ErrNotRight = "not right: "
|
||||||
|
ErrNotImplement = "not implement: "
|
||||||
)
|
)
|
||||||
const ( // LOG
|
const ( // LOG
|
||||||
// 通用
|
// 通用
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
package code
|
|
||||||
|
|
||||||
import (
|
|
||||||
ice "shylinux.com/x/icebergs"
|
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
|
||||||
kit "shylinux.com/x/toolkits"
|
|
||||||
)
|
|
||||||
|
|
||||||
func _csdn_show(m *ice.Message, name, text string, arg ...string) {
|
|
||||||
}
|
|
||||||
func _csdn_search(m *ice.Message, kind, name, text string) {
|
|
||||||
if kit.Contains(kind, kit.MDB_FOREACH) || kit.Contains(kind, CSDN) {
|
|
||||||
m.PushSearchWeb(CSDN, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const CSDN = "csdn"
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
Index.Merge(&ice.Context{
|
|
||||||
Configs: map[string]*ice.Config{
|
|
||||||
CSDN: {Name: "csdn", Help: "博客", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
|
|
||||||
}, Commands: map[string]*ice.Command{
|
|
||||||
CSDN: {Name: "csdn [name] word", Help: "博客", Action: map[string]*ice.Action{
|
|
||||||
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Cmd(mdb.INSERT, m.Prefix(CSDN), "", mdb.HASH, arg)
|
|
||||||
}},
|
|
||||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_csdn_search(m, arg[0], arg[1], arg[2])
|
|
||||||
}},
|
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
_csdn_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
|
||||||
}},
|
|
||||||
}})
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package code
|
|
||||||
|
|
||||||
import (
|
|
||||||
ice "shylinux.com/x/icebergs"
|
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
|
||||||
kit "shylinux.com/x/toolkits"
|
|
||||||
)
|
|
||||||
|
|
||||||
func _github_show(m *ice.Message, name, text string, arg ...string) {
|
|
||||||
}
|
|
||||||
func _github_search(m *ice.Message, kind, name, text string) {
|
|
||||||
if kit.Contains(kind, kit.MDB_FOREACH) || kit.Contains(kind, GITHUB) {
|
|
||||||
m.PushSearchWeb(GITHUB, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const GITHUB = "github"
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
Index.Merge(&ice.Context{
|
|
||||||
Configs: map[string]*ice.Config{
|
|
||||||
GITHUB: {Name: "github", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
|
|
||||||
},
|
|
||||||
Commands: map[string]*ice.Command{
|
|
||||||
GITHUB: {Name: "github [name] word", Help: "百度", Action: map[string]*ice.Action{
|
|
||||||
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Cmd(mdb.INSERT, m.Prefix(GITHUB), "", mdb.HASH, arg)
|
|
||||||
}},
|
|
||||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_github_search(m, arg[0], arg[1], arg[2])
|
|
||||||
}},
|
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
_github_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
|
||||||
}},
|
|
||||||
}})
|
|
||||||
}
|
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func _plan_list(m *ice.Message, begin_time, end_time time.Time) *ice.Message {
|
func _plan_list(m *ice.Message, begin_time, end_time time.Time) *ice.Message {
|
||||||
m.Option(mdb.CACHE_LIMIT, "100")
|
m.Option(ice.CACHE_LIMIT, "100")
|
||||||
m.Fields(0, "begin_time,close_time,zone,id,level,status,score,type,name,text,extra")
|
m.Fields(0, "begin_time,close_time,zone,id,level,status,score,type,name,text,extra")
|
||||||
m.Option(kit.Keycb(mdb.SELECT), func(key string, fields []string, value, val map[string]interface{}) {
|
m.Option(kit.Keycb(mdb.SELECT), func(key string, fields []string, value, val map[string]interface{}) {
|
||||||
begin, _ := time.ParseInLocation(ice.MOD_TIME, kit.Format(value[BEGIN_TIME]), time.Local)
|
begin, _ := time.ParseInLocation(ice.MOD_TIME, kit.Format(value[BEGIN_TIME]), time.Local)
|
||||||
|
@ -7,6 +7,27 @@ import (
|
|||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Parse(m *ice.Message, meta string, key string, arg ...string) *ice.Message {
|
||||||
|
list := []string{}
|
||||||
|
for _, line := range kit.Split(strings.Join(arg, ice.SP), ice.NL) {
|
||||||
|
ls := kit.Split(line)
|
||||||
|
for i := 0; i < len(ls); i++ {
|
||||||
|
if strings.HasPrefix(ls[i], "#") {
|
||||||
|
ls = ls[:i]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list = append(list, ls...)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch data := kit.Parse(nil, "", list...); meta {
|
||||||
|
case ice.MSG_OPTION:
|
||||||
|
m.Option(key, data)
|
||||||
|
case ice.MSG_APPEND:
|
||||||
|
m.Append(key, data)
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
func _field_show(m *ice.Message, name, text string, arg ...string) {
|
func _field_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
// 命令参数
|
// 命令参数
|
||||||
meta, cmds := kit.Dict(), kit.Split(text)
|
meta, cmds := kit.Dict(), kit.Split(text)
|
||||||
@ -32,7 +53,7 @@ func _field_show(m *ice.Message, name, text string, arg ...string) {
|
|||||||
m.Option(arg[i], kit.Split(strings.TrimSuffix(strings.TrimPrefix(arg[i+1], "["), "]")))
|
m.Option(arg[i], kit.Split(strings.TrimSuffix(strings.TrimPrefix(arg[i+1], "["), "]")))
|
||||||
kit.Value(meta, arg[i], m.Optionv(arg[i]))
|
kit.Value(meta, arg[i], m.Optionv(arg[i]))
|
||||||
} else {
|
} else {
|
||||||
m.Parse(ice.MSG_OPTION, arg[i], arg[i+1])
|
Parse(m, ice.MSG_OPTION, arg[i], arg[i+1])
|
||||||
kit.Value(meta, arg[i], m.Optionv(arg[i]))
|
kit.Value(meta, arg[i], m.Optionv(arg[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ func _word_show(m *ice.Message, name string, arg ...string) {
|
|||||||
|
|
||||||
m.Option(ice.MSG_ALIAS, m.Confv(WORD, kit.Keym(kit.MDB_ALIAS)))
|
m.Option(ice.MSG_ALIAS, m.Confv(WORD, kit.Keym(kit.MDB_ALIAS)))
|
||||||
m.Option(nfs.DIR_ROOT, _wiki_path(m, WORD))
|
m.Option(nfs.DIR_ROOT, _wiki_path(m, WORD))
|
||||||
m.Option(ice.MSG_RENDER, ice.RENDER_RAW)
|
|
||||||
m.Cmdy(ssh.SOURCE, name)
|
m.Cmdy(ssh.SOURCE, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
data.go
7
data.go
@ -24,7 +24,7 @@ func (m *Message) Config(key string, arg ...interface{}) string {
|
|||||||
return m.Conf(m.PrefixKey(), kit.Keym(key))
|
return m.Conf(m.PrefixKey(), kit.Keym(key))
|
||||||
}
|
}
|
||||||
func (m *Message) ConfigSimple(key string) []string {
|
func (m *Message) ConfigSimple(key string) []string {
|
||||||
return []string{key, m.Conf(m.PrefixKey(), kit.Keym(key))}
|
return []string{key, m.Config(key)}
|
||||||
}
|
}
|
||||||
func (m *Message) Save(arg ...string) *Message {
|
func (m *Message) Save(arg ...string) *Message {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
@ -36,7 +36,7 @@ func (m *Message) Save(arg ...string) *Message {
|
|||||||
for _, k := range arg {
|
for _, k := range arg {
|
||||||
list = append(list, m.Prefix(k))
|
list = append(list, m.Prefix(k))
|
||||||
}
|
}
|
||||||
m.Cmd("ctx.config", SAVE, m.Prefix("json"), list)
|
m.Cmd("config", SAVE, m.Prefix("json"), list)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Load(arg ...string) *Message {
|
func (m *Message) Load(arg ...string) *Message {
|
||||||
@ -44,7 +44,7 @@ func (m *Message) Load(arg ...string) *Message {
|
|||||||
for _, k := range arg {
|
for _, k := range arg {
|
||||||
list = append(list, m.Prefix(k))
|
list = append(list, m.Prefix(k))
|
||||||
}
|
}
|
||||||
m.Cmd("ctx.config", LOAD, m.Prefix("json"), list)
|
m.Cmd("config", LOAD, m.Prefix("json"), list)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,6 @@ func (m *Message) Richs(prefix string, chain interface{}, raw interface{}, cb in
|
|||||||
switch cb := cb.(type) {
|
switch cb := cb.(type) {
|
||||||
case func(*sync.Mutex, string, map[string]interface{}):
|
case func(*sync.Mutex, string, map[string]interface{}):
|
||||||
mu := &sync.Mutex{}
|
mu := &sync.Mutex{}
|
||||||
|
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
defer wg.Wait()
|
defer wg.Wait()
|
||||||
|
|
||||||
|
21
exec.go
21
exec.go
@ -82,8 +82,8 @@ func (m *Message) Call(sync bool, cb func(*Message) *Message) *Message {
|
|||||||
p := kit.Select("10s", m.Option(kit.MDB_TIMEOUT))
|
p := kit.Select("10s", m.Option(kit.MDB_TIMEOUT))
|
||||||
t := time.AfterFunc(kit.Duration(p), func() {
|
t := time.AfterFunc(kit.Duration(p), func() {
|
||||||
m.Warn(true, "%s timeout %v", p, m.Detailv())
|
m.Warn(true, "%s timeout %v", p, m.Detailv())
|
||||||
wait <- false
|
|
||||||
m.Back(nil)
|
m.Back(nil)
|
||||||
|
wait <- false
|
||||||
})
|
})
|
||||||
|
|
||||||
m.cb = func(sub *Message) *Message {
|
m.cb = func(sub *Message) *Message {
|
||||||
@ -109,8 +109,8 @@ func (m *Message) Back(res *Message) *Message {
|
|||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Go(cb interface{}, args ...interface{}) *Message {
|
func (m *Message) Go(cb interface{}) *Message {
|
||||||
task.Put(kit.FileLine(3, 3), func(task *task.Task) error {
|
task.Put(kit.FileLine(cb, 3), func(task *task.Task) error {
|
||||||
m.TryCatch(m, true, func(m *Message) {
|
m.TryCatch(m, true, func(m *Message) {
|
||||||
switch cb := cb.(type) {
|
switch cb := cb.(type) {
|
||||||
case func(*Message):
|
case func(*Message):
|
||||||
@ -128,28 +128,27 @@ func (m *Message) Watch(key string, arg ...string) *Message {
|
|||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
arg = append(arg, m.Prefix(AUTO))
|
arg = append(arg, m.Prefix(AUTO))
|
||||||
}
|
}
|
||||||
m.Cmd("gdb.event", "action", "listen", "event", key, CMD, strings.Join(arg, SP))
|
m.Cmd("event", "action", "listen", "event", key, CMD, strings.Join(arg, SP))
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Event(key string, arg ...string) *Message {
|
func (m *Message) Event(key string, arg ...string) *Message {
|
||||||
m.Cmd("gdb.event", "action", "action", "event", key, arg)
|
m.Cmd("event", "action", "action", "event", key, arg)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Right(arg ...interface{}) bool {
|
func (m *Message) Right(arg ...interface{}) bool {
|
||||||
return m.Option(MSG_USERROLE) == "root" || !m.Warn(m.Cmdx("aaa.role", "right",
|
return m.Option(MSG_USERROLE) == "root" || !m.Warn(m.Cmdx("role", "right",
|
||||||
m.Option(MSG_USERROLE), strings.ReplaceAll(kit.Keys(arg...), "/", PT)) != OK,
|
m.Option(MSG_USERROLE), strings.ReplaceAll(kit.Keys(arg...), "/", PT)) != OK,
|
||||||
ErrNotRight, m.Option(MSG_USERROLE), " of ", strings.Join(kit.Simple(arg), PT), " at ", kit.FileLine(2, 3))
|
ErrNotRight, m.Option(MSG_USERROLE), OF, strings.Join(kit.Simple(arg), PT), " at ", kit.FileLine(2, 3))
|
||||||
}
|
}
|
||||||
func (m *Message) Space(arg interface{}) []string {
|
func (m *Message) Space(arg interface{}) []string {
|
||||||
if arg == nil || arg == "" || kit.Format(arg) == m.Conf("cli.runtime", "node.name") {
|
if arg == nil || arg == "" || kit.Format(arg) == m.Conf("runtime", "node.name") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return []string{"web.space", kit.Format(arg)}
|
return []string{"space", kit.Format(arg)}
|
||||||
}
|
}
|
||||||
func (m *Message) PodCmd(arg ...interface{}) bool {
|
func (m *Message) PodCmd(arg ...interface{}) bool {
|
||||||
if pod := m.Option(POD); pod != "" {
|
if pod := m.Option(POD); pod != "" {
|
||||||
m.Option(POD, "")
|
if m.Option(POD, ""); m.Option(MSG_UPLOAD) != "" {
|
||||||
if m.Option(MSG_UPLOAD) != "" {
|
|
||||||
msg := m.Cmd("cache", "upload")
|
msg := m.Cmd("cache", "upload")
|
||||||
m.Option(MSG_UPLOAD, msg.Append(kit.MDB_HASH), msg.Append(kit.MDB_NAME), msg.Append(kit.MDB_SIZE))
|
m.Option(MSG_UPLOAD, msg.Append(kit.MDB_HASH), msg.Append(kit.MDB_NAME), msg.Append(kit.MDB_SIZE))
|
||||||
}
|
}
|
||||||
|
36
init.go
36
init.go
@ -10,16 +10,14 @@ import (
|
|||||||
log "shylinux.com/x/toolkits/logs"
|
log "shylinux.com/x/toolkits/logs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Frame struct {
|
type Frame struct{}
|
||||||
wait chan int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Frame) Spawn(m *Message, c *Context, arg ...string) Server {
|
func (f *Frame) Spawn(m *Message, c *Context, arg ...string) Server {
|
||||||
return &Frame{}
|
return &Frame{}
|
||||||
}
|
}
|
||||||
func (f *Frame) Begin(m *Message, arg ...string) Server {
|
func (f *Frame) Begin(m *Message, arg ...string) Server {
|
||||||
m.Log(LOG_BEGIN, ICE)
|
m.Log(LOG_BEGIN, ICE)
|
||||||
defer m.Cost("begin ice")
|
defer m.Cost(LOG_BEGIN, ICE)
|
||||||
|
|
||||||
list := map[*Context]*Message{m.target: m}
|
list := map[*Context]*Message{m.target: m}
|
||||||
m.Travel(func(p *Context, s *Context) {
|
m.Travel(func(p *Context, s *Context) {
|
||||||
@ -33,24 +31,25 @@ func (f *Frame) Begin(m *Message, arg ...string) Server {
|
|||||||
}
|
}
|
||||||
func (f *Frame) Start(m *Message, arg ...string) bool {
|
func (f *Frame) Start(m *Message, arg ...string) bool {
|
||||||
m.Log(LOG_START, ICE)
|
m.Log(LOG_START, ICE)
|
||||||
defer m.Cost("start ice")
|
defer m.Cost(LOG_START, ICE)
|
||||||
|
|
||||||
m.Cap(CTX_STATUS, CTX_START)
|
m.Cap(CTX_STATUS, CTX_START)
|
||||||
m.Cap(CTX_STREAM, strings.Split(m.Time(), " ")[1])
|
m.Cap(CTX_STREAM, strings.Split(m.Time(), SP)[1])
|
||||||
|
|
||||||
m.Cmdy(INIT, arg)
|
m.Cmdy(INIT, arg)
|
||||||
|
|
||||||
m.target.root.wg = &sync.WaitGroup{}
|
m.target.root.wg = &sync.WaitGroup{}
|
||||||
for _, k := range kit.Split(kit.Select("ssh,gdb,log")) {
|
for _, k := range kit.Split("log,gdb,ssh") {
|
||||||
m.Start(k)
|
m.Start(k)
|
||||||
}
|
}
|
||||||
|
defer m.TryCatch(m, true, func(msg *Message) { m.target.root.wg.Wait() })
|
||||||
|
|
||||||
m.Cmdy(arg)
|
m.Cmdy(arg)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (f *Frame) Close(m *Message, arg ...string) bool {
|
func (f *Frame) Close(m *Message, arg ...string) bool {
|
||||||
m.TryCatch(m, true, func(m *Message) { m.target.wg.Wait() })
|
|
||||||
|
|
||||||
m.Log(LOG_CLOSE, ICE)
|
m.Log(LOG_CLOSE, ICE)
|
||||||
defer m.Cost("close ice")
|
defer m.Cost(LOG_CLOSE, ICE)
|
||||||
|
|
||||||
list := map[*Context]*Message{m.target: m}
|
list := map[*Context]*Message{m.target: m}
|
||||||
m.Travel(func(p *Context, s *Context) {
|
m.Travel(func(p *Context, s *Context) {
|
||||||
@ -63,7 +62,7 @@ func (f *Frame) Close(m *Message, arg ...string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Index = &Context{Name: "ice", Help: "冰山模块", Caches: map[string]*Cache{
|
var Index = &Context{Name: "ice", Help: "冰山模块", Caches: map[string]*Cache{
|
||||||
CTX_FOLLOW: {Value: ICE}, CTX_STREAM: {Value: SHY}, CTX_STATUS: {Value: CTX_BEGIN},
|
CTX_FOLLOW: {Value: ICE}, CTX_STATUS: {Value: CTX_BEGIN}, CTX_STREAM: {Value: SHY},
|
||||||
}, Configs: map[string]*Config{
|
}, Configs: map[string]*Config{
|
||||||
HELP: {Value: kit.Data("index", Info.Help)},
|
HELP: {Value: kit.Data("index", Info.Help)},
|
||||||
}, Commands: map[string]*Command{
|
}, Commands: map[string]*Command{
|
||||||
@ -77,14 +76,15 @@ var Index = &Context{Name: "ice", Help: "冰山模块", Caches: map[string]*Cach
|
|||||||
}},
|
}},
|
||||||
INIT: {Name: "init", Help: "启动", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
INIT: {Name: "init", Help: "启动", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
||||||
m.root.Cmd(CTX_INIT)
|
m.root.Cmd(CTX_INIT)
|
||||||
m.Cmd("ssh.source", ETC_INIT_SHY)
|
m.Cmd("source", ETC_INIT_SHY)
|
||||||
}},
|
}},
|
||||||
HELP: {Name: "help", Help: "帮助", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
HELP: {Name: "help", Help: "帮助", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
||||||
m.Echo(m.Config("index"))
|
m.Echo(m.Config("index"))
|
||||||
}},
|
}},
|
||||||
EXIT: {Name: "exit", Help: "结束", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
EXIT: {Name: "exit", Help: "结束", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
||||||
|
defer c.server.(*Frame).Close(m.root.Spawn(), arg...)
|
||||||
m.root.Option(EXIT, kit.Select("0", arg, 0))
|
m.root.Option(EXIT, kit.Select("0", arg, 0))
|
||||||
m.Cmd("ssh.source", ETC_EXIT_SHY)
|
m.Cmd("source", ETC_EXIT_SHY)
|
||||||
m.root.Cmd(CTX_EXIT)
|
m.root.Cmd(CTX_EXIT)
|
||||||
}},
|
}},
|
||||||
CTX_EXIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
CTX_EXIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
||||||
@ -96,7 +96,6 @@ var Index = &Context{Name: "ice", Help: "冰山模块", Caches: map[string]*Cach
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
c.server.(*Frame).wait <- kit.Int(m.root.Option(EXIT))
|
|
||||||
}},
|
}},
|
||||||
}}
|
}}
|
||||||
var Pulse = &Message{
|
var Pulse = &Message{
|
||||||
@ -115,7 +114,7 @@ func Run(arg ...string) string {
|
|||||||
arg = append(arg, HELP)
|
arg = append(arg, HELP)
|
||||||
}
|
}
|
||||||
|
|
||||||
frame := &Frame{wait: make(chan int, 1)}
|
frame := &Frame{}
|
||||||
Index.Merge(Index)
|
Index.Merge(Index)
|
||||||
Index.server = frame
|
Index.server = frame
|
||||||
Index.root = Index
|
Index.root = Index
|
||||||
@ -124,18 +123,13 @@ func Run(arg ...string) string {
|
|||||||
switch kit.Select("", arg, 0) {
|
switch kit.Select("", arg, 0) {
|
||||||
case "space", "serve":
|
case "space", "serve":
|
||||||
if log.LogDisable = false; frame.Begin(Pulse.Spawn(), arg...).Start(Pulse, arg...) {
|
if log.LogDisable = false; frame.Begin(Pulse.Spawn(), arg...).Start(Pulse, arg...) {
|
||||||
frame.Close(Pulse.Spawn(), arg...)
|
os.Exit(kit.Int(Pulse.Option(EXIT)))
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(<-frame.wait)
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if Pulse.Cmdy(arg); Pulse.Result() == "" {
|
if Pulse.Cmdy(arg); Pulse.Result() == "" {
|
||||||
Pulse.Table()
|
Pulse.Table()
|
||||||
}
|
}
|
||||||
if strings.TrimSpace(Pulse.Result()) == "" {
|
|
||||||
Pulse.Set(MSG_RESULT).Cmdy("cli.system", arg)
|
|
||||||
}
|
|
||||||
Pulse.Sleep("10ms")
|
Pulse.Sleep("10ms")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
106
logs.go
106
logs.go
@ -15,7 +15,7 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message {
|
|||||||
return m // 禁用日志
|
return m // 禁用日志
|
||||||
}
|
}
|
||||||
if str = strings.TrimSpace(kit.Format(str, arg...)); Info.Log != nil {
|
if str = strings.TrimSpace(kit.Format(str, arg...)); Info.Log != nil {
|
||||||
Info.Log(m, m.Format(kit.MDB_PREFIX), level, str) // 日志分流
|
Info.Log(m, m.FormatPrefix(), level, str) // 日志分流
|
||||||
}
|
}
|
||||||
|
|
||||||
// 日志颜色
|
// 日志颜色
|
||||||
@ -41,7 +41,7 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message {
|
|||||||
|
|
||||||
// 长度截断
|
// 长度截断
|
||||||
switch level {
|
switch level {
|
||||||
case LOG_INFO, "send", "recv":
|
case LOG_INFO, LOG_SEND, LOG_RECV:
|
||||||
if len(str) > 1024 {
|
if len(str) > 1024 {
|
||||||
str = str[:1024]
|
str = str[:1024]
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ func (m *Message) join(arg ...interface{}) string {
|
|||||||
list = append(list, kit.Format(arg[i])+":", kit.Format(arg[i+1]))
|
list = append(list, kit.Format(arg[i])+":", kit.Format(arg[i+1]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return strings.Join(list, " ")
|
return kit.Join(list, SP)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) Log(level string, str string, arg ...interface{}) *Message {
|
func (m *Message) Log(level string, str string, arg ...interface{}) *Message {
|
||||||
@ -72,7 +72,7 @@ func (m *Message) Info(str string, arg ...interface{}) *Message {
|
|||||||
}
|
}
|
||||||
func (m *Message) Cost(arg ...interface{}) *Message {
|
func (m *Message) Cost(arg ...interface{}) *Message {
|
||||||
list := []string{m.FormatCost(), m.join(arg...)}
|
list := []string{m.FormatCost(), m.join(arg...)}
|
||||||
return m.log(LOG_COST, strings.Join(list, " "))
|
return m.log(LOG_COST, kit.Join(list, SP))
|
||||||
}
|
}
|
||||||
func (m *Message) Warn(err bool, arg ...interface{}) bool {
|
func (m *Message) Warn(err bool, arg ...interface{}) bool {
|
||||||
if !err || len(m.meta[MSG_RESULT]) > 0 && m.meta[MSG_RESULT][0] == ErrWarn {
|
if !err || len(m.meta[MSG_RESULT]) > 0 && m.meta[MSG_RESULT][0] == ErrWarn {
|
||||||
@ -85,7 +85,7 @@ func (m *Message) Warn(err bool, arg ...interface{}) bool {
|
|||||||
}
|
}
|
||||||
func (m *Message) Error(err bool, str string, arg ...interface{}) bool {
|
func (m *Message) Error(err bool, str string, arg ...interface{}) bool {
|
||||||
if err {
|
if err {
|
||||||
m.Echo("error: ").Echo(str, arg...)
|
m.Echo(ErrWarn).Echo(str, arg...)
|
||||||
m.log(LOG_ERROR, m.FormatStack())
|
m.log(LOG_ERROR, m.FormatStack())
|
||||||
m.log(LOG_ERROR, str, arg...)
|
m.log(LOG_ERROR, str, arg...)
|
||||||
m.log(LOG_ERROR, m.FormatChain())
|
m.log(LOG_ERROR, m.FormatChain())
|
||||||
@ -131,8 +131,29 @@ func (m *Message) Log_IMPORT(arg ...interface{}) *Message {
|
|||||||
return m.log(LOG_IMPORT, m.join(arg...))
|
return m.log(LOG_IMPORT, m.join(arg...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Message) FormatPrefix() string {
|
||||||
|
return kit.Format("%s %d %s->%s", m.Time(), m.code, m.source.Name, m.target.Name)
|
||||||
|
}
|
||||||
|
func (m *Message) FormatTime() string {
|
||||||
|
return m.Time()
|
||||||
|
}
|
||||||
|
func (m *Message) FormatShip() string {
|
||||||
|
return kit.Format("%s->%s", m.source.Name, m.target.Name)
|
||||||
|
}
|
||||||
|
func (m *Message) FormatCost() string {
|
||||||
|
return kit.FmtTime(kit.Int64(time.Since(m.time)))
|
||||||
|
}
|
||||||
|
func (m *Message) FormatSize() string {
|
||||||
|
if len(m.meta[MSG_APPEND]) == 0 {
|
||||||
|
return kit.Format("%dx%d %s", 0, 0, "[]")
|
||||||
|
} else {
|
||||||
|
return kit.Format("%dx%d %v", len(m.meta[m.meta[MSG_APPEND][0]]), len(m.meta[MSG_APPEND]), kit.Format(m.meta[MSG_APPEND]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (m *Message) FormatMeta() string {
|
||||||
|
return kit.Format(m.meta)
|
||||||
|
}
|
||||||
func (m *Message) FormatStack() string {
|
func (m *Message) FormatStack() string {
|
||||||
// 调用栈
|
|
||||||
pc := make([]uintptr, 100)
|
pc := make([]uintptr, 100)
|
||||||
pc = pc[:runtime.Callers(5, pc)]
|
pc = pc[:runtime.Callers(5, pc)]
|
||||||
frames := runtime.CallersFrames(pc)
|
frames := runtime.CallersFrames(pc)
|
||||||
@ -140,14 +161,14 @@ func (m *Message) FormatStack() string {
|
|||||||
meta := []string{}
|
meta := []string{}
|
||||||
for {
|
for {
|
||||||
frame, more := frames.Next()
|
frame, more := frames.Next()
|
||||||
file := strings.Split(frame.File, "/")
|
file := kit.Split(frame.File, "/")
|
||||||
name := strings.Split(frame.Function, "/")
|
name := kit.Split(frame.Function, "/")
|
||||||
meta = append(meta, kit.Format("\n%s:%d\t%s", file[len(file)-1], frame.Line, name[len(name)-1]))
|
meta = append(meta, kit.Format("%s:%d\t%s", file[len(file)-1], frame.Line, name[len(name)-1]))
|
||||||
if !more {
|
if !more {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return strings.Join(meta, "")
|
return kit.Join(meta, NL)
|
||||||
}
|
}
|
||||||
func (m *Message) FormatChain() string {
|
func (m *Message) FormatChain() string {
|
||||||
ms := []*Message{}
|
ms := []*Message{}
|
||||||
@ -155,51 +176,40 @@ func (m *Message) FormatChain() string {
|
|||||||
ms = append(ms, msg)
|
ms = append(ms, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
meta := append([]string{}, "\n\n")
|
meta := append([]string{}, NL)
|
||||||
for i := len(ms) - 1; i >= 0; i-- {
|
for i := len(ms) - 1; i >= 0; i-- {
|
||||||
msg := ms[i]
|
msg := ms[i]
|
||||||
|
|
||||||
meta = append(meta, kit.Format("%s ", msg.Format("prefix")))
|
|
||||||
if len(msg.meta[MSG_DETAIL]) > 0 {
|
if len(msg.meta[MSG_DETAIL]) > 0 {
|
||||||
meta = append(meta, kit.Format("%s:%d %v", MSG_DETAIL, len(msg.meta[MSG_DETAIL]), msg.meta[MSG_DETAIL]))
|
meta = append(meta, kit.Format("%s %s:%d %v", msg.FormatPrefix(), MSG_DETAIL, len(msg.meta[MSG_DETAIL]), msg.meta[MSG_DETAIL]))
|
||||||
|
} else {
|
||||||
|
meta = append(meta, kit.Format("%s ", msg.FormatPrefix()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.meta[MSG_OPTION]) > 0 {
|
if len(msg.meta[MSG_OPTION]) > 0 {
|
||||||
meta = append(meta, kit.Format("%s:%d %v\n", MSG_OPTION, len(msg.meta[MSG_OPTION]), msg.meta[MSG_OPTION]))
|
meta = append(meta, kit.Format("%s:%d %v", MSG_OPTION, len(msg.meta[MSG_OPTION]), msg.meta[MSG_OPTION]))
|
||||||
for _, k := range msg.meta[MSG_OPTION] {
|
for _, k := range msg.meta[MSG_OPTION] {
|
||||||
if v, ok := msg.meta[k]; ok {
|
if v, ok := msg.meta[k]; ok {
|
||||||
meta = append(meta, kit.Format(" %s: %d %v\n", k, len(v), v))
|
meta = append(meta, kit.Format("\t%s: %d %v", k, len(v), v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
meta = append(meta, "\n")
|
meta = append(meta, NL)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.meta[MSG_APPEND]) > 0 {
|
if len(msg.meta[MSG_APPEND]) > 0 {
|
||||||
meta = append(meta, kit.Format(" %s:%d %v\n", MSG_APPEND, len(msg.meta[MSG_APPEND]), msg.meta[MSG_APPEND]))
|
meta = append(meta, kit.Format("%s:%d %v", MSG_APPEND, len(msg.meta[MSG_APPEND]), msg.meta[MSG_APPEND]))
|
||||||
for _, k := range msg.meta[MSG_APPEND] {
|
for _, k := range msg.meta[MSG_APPEND] {
|
||||||
if v, ok := msg.meta[k]; ok {
|
if v, ok := msg.meta[k]; ok {
|
||||||
meta = append(meta, kit.Format(" %s: %d %v\n", k, len(v), v))
|
meta = append(meta, kit.Format("\t%s: %d %v", k, len(v), v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(msg.meta[MSG_RESULT]) > 0 {
|
if len(msg.meta[MSG_RESULT]) > 0 {
|
||||||
meta = append(meta, kit.Format(" %s:%d %v\n", MSG_RESULT, len(msg.meta[MSG_RESULT]), msg.meta[MSG_RESULT]))
|
meta = append(meta, kit.Format("%s:%d %v", MSG_RESULT, len(msg.meta[MSG_RESULT]), msg.meta[MSG_RESULT]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return strings.Join(meta, "")
|
return kit.Join(meta, NL)
|
||||||
}
|
|
||||||
func (m *Message) FormatTime() string {
|
|
||||||
return m.Format(kit.MDB_TIME)
|
|
||||||
}
|
|
||||||
func (m *Message) FormatMeta() string {
|
|
||||||
return m.Format(kit.MDB_META)
|
|
||||||
}
|
|
||||||
func (m *Message) FormatSize() string {
|
|
||||||
return m.Format(kit.MDB_SIZE)
|
|
||||||
}
|
|
||||||
func (m *Message) FormatCost() string {
|
|
||||||
return m.Format(kit.MDB_COST)
|
|
||||||
}
|
}
|
||||||
func (m *Message) Format(key interface{}) string {
|
func (m *Message) Format(key interface{}) string {
|
||||||
switch key := key.(type) {
|
switch key := key.(type) {
|
||||||
@ -207,35 +217,23 @@ func (m *Message) Format(key interface{}) string {
|
|||||||
json.Unmarshal(key, &m.meta)
|
json.Unmarshal(key, &m.meta)
|
||||||
case string:
|
case string:
|
||||||
switch key {
|
switch key {
|
||||||
case kit.MDB_COST:
|
|
||||||
return kit.FmtTime(kit.Int64(time.Since(m.time)))
|
|
||||||
case kit.MDB_SIZE:
|
|
||||||
if len(m.meta[MSG_APPEND]) == 0 {
|
|
||||||
return kit.Format("%dx%d", 0, 0)
|
|
||||||
} else {
|
|
||||||
return kit.Format("%dx%d", len(m.meta[m.meta[MSG_APPEND][0]]), len(m.meta[MSG_APPEND]))
|
|
||||||
}
|
|
||||||
case kit.MDB_META:
|
|
||||||
return kit.Format(m.meta)
|
|
||||||
case kit.MDB_SHIP:
|
|
||||||
return kit.Format("%s->%s", m.source.Name, m.target.Name)
|
|
||||||
case kit.MDB_PREFIX:
|
case kit.MDB_PREFIX:
|
||||||
return kit.Format("%s %d %s->%s", m.Time(), m.code, m.source.Name, m.target.Name)
|
return m.FormatPrefix()
|
||||||
|
case kit.MDB_SHIP:
|
||||||
case MSG_APPEND:
|
return m.FormatShip()
|
||||||
if len(m.meta[MSG_APPEND]) == 0 {
|
case kit.MDB_COST:
|
||||||
return kit.Format("%dx%d %s", 0, 0, "[]")
|
return m.FormatCost()
|
||||||
} else {
|
case kit.MDB_SIZE:
|
||||||
return kit.Format("%dx%d %s", len(m.meta[m.meta[MSG_APPEND][0]]), len(m.meta[MSG_APPEND]), kit.Format(m.meta[MSG_APPEND]))
|
return m.FormatSize()
|
||||||
}
|
case kit.MDB_META:
|
||||||
|
return m.FormatMeta()
|
||||||
case kit.MDB_CHAIN:
|
case kit.MDB_CHAIN:
|
||||||
return m.FormatChain()
|
return m.FormatChain()
|
||||||
case kit.MDB_STACK:
|
case kit.MDB_STACK:
|
||||||
return m.FormatStack()
|
return m.FormatStack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m.time.Format(MOD_TIME)
|
return m.FormatTime()
|
||||||
}
|
}
|
||||||
func (m *Message) Formats(key string) string {
|
func (m *Message) Formats(key string) string {
|
||||||
switch key {
|
switch key {
|
||||||
|
133
meta.go
133
meta.go
@ -1,7 +1,6 @@
|
|||||||
package ice
|
package ice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -26,9 +25,13 @@ func (m *Message) Set(key string, arg ...string) *Message {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if len(m.meta[MSG_APPEND]) == 2 && m.meta[MSG_APPEND][0] == kit.MDB_KEY && m.meta[MSG_APPEND][1] == kit.MDB_VALUE {
|
if m.FieldsIsDetail() {
|
||||||
for i := 0; i < len(m.meta[kit.MDB_KEY]); i++ {
|
for i := 0; i < len(m.meta[kit.MDB_KEY]); i++ {
|
||||||
if m.meta[kit.MDB_KEY][i] == key {
|
if m.meta[kit.MDB_KEY][i] == key {
|
||||||
|
if len(arg) > 0 {
|
||||||
|
m.meta[kit.MDB_VALUE][i] = arg[0]
|
||||||
|
return m
|
||||||
|
}
|
||||||
for ; i < len(m.meta[kit.MDB_KEY])-1; i++ {
|
for ; i < len(m.meta[kit.MDB_KEY])-1; i++ {
|
||||||
m.meta[kit.MDB_KEY][i] = m.meta[kit.MDB_KEY][i+1]
|
m.meta[kit.MDB_KEY][i] = m.meta[kit.MDB_KEY][i+1]
|
||||||
m.meta[kit.MDB_VALUE][i] = m.meta[kit.MDB_VALUE][i+1]
|
m.meta[kit.MDB_VALUE][i] = m.meta[kit.MDB_VALUE][i+1]
|
||||||
@ -38,12 +41,9 @@ func (m *Message) Set(key string, arg ...string) *Message {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
return m
|
||||||
}
|
}
|
||||||
delete(m.meta, key)
|
delete(m.meta, key)
|
||||||
for _, k := range arg {
|
|
||||||
delete(m.meta, k)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return m.Add(key, arg...)
|
return m.Add(key, arg...)
|
||||||
}
|
}
|
||||||
@ -68,26 +68,11 @@ func (m *Message) Cut(fields ...string) *Message {
|
|||||||
}
|
}
|
||||||
func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Message {
|
func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Message {
|
||||||
switch value := value.(type) {
|
switch value := value.(type) {
|
||||||
case map[string]string:
|
|
||||||
head := kit.Simple(arg)
|
|
||||||
if len(head) == 0 || (len(head) == 1 && head[0] == "detail") {
|
|
||||||
head = head[:0]
|
|
||||||
for k := range value {
|
|
||||||
head = append(head, k)
|
|
||||||
}
|
|
||||||
sort.Strings(head)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, k := range head {
|
|
||||||
m.Push(k, value[k])
|
|
||||||
}
|
|
||||||
|
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
// 键值排序
|
|
||||||
head := kit.Simple()
|
head := kit.Simple()
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
head = kit.Simple(arg[0])
|
head = kit.Simple(arg[0])
|
||||||
} else {
|
} else { // 键值排序
|
||||||
for k := range kit.KeyValue(map[string]interface{}{}, "", value) {
|
for k := range kit.KeyValue(map[string]interface{}{}, "", value) {
|
||||||
head = append(head, k)
|
head = append(head, k)
|
||||||
}
|
}
|
||||||
@ -104,7 +89,7 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa
|
|||||||
var v interface{}
|
var v interface{}
|
||||||
switch k {
|
switch k {
|
||||||
case kit.MDB_KEY, kit.MDB_HASH:
|
case kit.MDB_KEY, kit.MDB_HASH:
|
||||||
if key != "" {
|
if key != "" && key != "detail" {
|
||||||
v = key
|
v = key
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -129,8 +114,23 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case map[string]string:
|
||||||
|
head := kit.Simple()
|
||||||
|
if len(arg) > 0 {
|
||||||
|
head = kit.Simple(arg[0])
|
||||||
|
} else { // 键值排序
|
||||||
|
for k := range value {
|
||||||
|
head = append(head, k)
|
||||||
|
}
|
||||||
|
sort.Strings(head)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, k := range head {
|
||||||
|
m.Push(k, value[k])
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if m.Option(MSG_FIELDS) == "detail" || (len(m.meta[MSG_APPEND]) == 2 && m.meta[MSG_APPEND][0] == kit.MDB_KEY && m.meta[MSG_APPEND][1] == kit.MDB_VALUE) {
|
if m.FieldsIsDetail() {
|
||||||
if key != kit.MDB_KEY || key != kit.MDB_VALUE {
|
if key != kit.MDB_KEY || key != kit.MDB_VALUE {
|
||||||
m.Add(MSG_APPEND, kit.MDB_KEY, key)
|
m.Add(MSG_APPEND, kit.MDB_KEY, key)
|
||||||
m.Add(MSG_APPEND, kit.MDB_VALUE, kit.Format(value))
|
m.Add(MSG_APPEND, kit.MDB_VALUE, kit.Format(value))
|
||||||
@ -145,59 +145,31 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Echo(str string, arg ...interface{}) *Message {
|
func (m *Message) Echo(str string, arg ...interface{}) *Message {
|
||||||
if len(arg) > 0 {
|
m.meta[MSG_RESULT] = append(m.meta[MSG_RESULT], kit.Format(str, arg...))
|
||||||
str = fmt.Sprintf(str, arg...)
|
|
||||||
}
|
|
||||||
m.meta[MSG_RESULT] = append(m.meta[MSG_RESULT], str)
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Copy(msg *Message, arg ...string) *Message {
|
func (m *Message) Copy(msg *Message, arg ...string) *Message {
|
||||||
if m == msg {
|
if m == nil || m == msg {
|
||||||
return m
|
|
||||||
}
|
|
||||||
if m == nil {
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
if len(arg) > 0 { // 精确复制
|
if len(arg) > 0 { // 精确复制
|
||||||
for _, k := range arg[1:] {
|
for _, k := range arg[1:] {
|
||||||
if kit.IndexOf(m.meta[arg[0]], k) == -1 {
|
m.Add(arg[0], kit.Simple(k, msg.meta[k])...)
|
||||||
m.meta[arg[0]] = append(m.meta[arg[0]], k)
|
|
||||||
}
|
|
||||||
m.meta[k] = append(m.meta[k], msg.meta[k]...)
|
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, k := range msg.meta[MSG_OPTION] { // 复制选项
|
for _, k := range msg.meta[MSG_OPTION] {
|
||||||
if kit.IndexOf(m.meta[MSG_OPTION], k) == -1 {
|
m.Add(MSG_OPTION, kit.Simple(k, msg.meta[k])...)
|
||||||
m.meta[MSG_OPTION] = append(m.meta[MSG_OPTION], k)
|
|
||||||
}
|
|
||||||
if _, ok := msg.meta[k]; ok {
|
|
||||||
m.meta[k] = msg.meta[k]
|
|
||||||
} else {
|
|
||||||
m.data[k] = msg.data[k]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
for _, k := range msg.meta[MSG_APPEND] {
|
||||||
for _, k := range msg.meta[MSG_APPEND] { // 复制数据
|
m.Add(MSG_APPEND, kit.Simple(k, msg.meta[k])...)
|
||||||
if i := kit.IndexOf(m.meta[MSG_OPTION], k); i > -1 && len(m.meta[k]) > 0 {
|
|
||||||
m.meta[k] = m.meta[k][:0]
|
|
||||||
}
|
|
||||||
if i := kit.IndexOf(m.meta[MSG_OPTS], k); i > -1 && len(m.meta[k]) > 0 {
|
|
||||||
m.meta[k] = m.meta[k][:0]
|
|
||||||
}
|
|
||||||
if kit.IndexOf(m.meta[MSG_APPEND], k) == -1 {
|
|
||||||
m.meta[MSG_APPEND] = append(m.meta[MSG_APPEND], k)
|
|
||||||
}
|
|
||||||
m.meta[k] = append(m.meta[k], msg.meta[k]...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 复制文本
|
|
||||||
m.meta[MSG_RESULT] = append(m.meta[MSG_RESULT], msg.meta[MSG_RESULT]...)
|
m.meta[MSG_RESULT] = append(m.meta[MSG_RESULT], msg.meta[MSG_RESULT]...)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Sort(key string, arg ...string) *Message {
|
func (m *Message) Sort(key string, arg ...string) *Message {
|
||||||
if m.Option(MSG_FIELDS) == "detail" {
|
if m.FieldsIsDetail() && key != kit.MDB_KEY {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
// 排序方法
|
// 排序方法
|
||||||
@ -217,8 +189,7 @@ func (m *Message) Sort(key string, arg ...string) *Message {
|
|||||||
number := map[int]int64{}
|
number := map[int]int64{}
|
||||||
table := []map[string]string{}
|
table := []map[string]string{}
|
||||||
m.Table(func(index int, line map[string]string, head []string) {
|
m.Table(func(index int, line map[string]string, head []string) {
|
||||||
table = append(table, line)
|
switch table = append(table, line); cmp {
|
||||||
switch cmp {
|
|
||||||
case "int":
|
case "int":
|
||||||
number[index] = kit.Int64(line[key])
|
number[index] = kit.Int64(line[key])
|
||||||
case "int_r":
|
case "int_r":
|
||||||
@ -269,7 +240,7 @@ func (m *Message) Sort(key string, arg ...string) *Message {
|
|||||||
}
|
}
|
||||||
func (m *Message) Table(cbs ...func(index int, value map[string]string, head []string)) *Message {
|
func (m *Message) Table(cbs ...func(index int, value map[string]string, head []string)) *Message {
|
||||||
if len(cbs) > 0 && cbs[0] != nil {
|
if len(cbs) > 0 && cbs[0] != nil {
|
||||||
if len(m.meta[MSG_APPEND]) == 2 && m.meta[MSG_APPEND][0] == kit.MDB_KEY {
|
if m.FieldsIsDetail() {
|
||||||
line := map[string]string{}
|
line := map[string]string{}
|
||||||
for i, k := range m.meta[kit.MDB_KEY] {
|
for i, k := range m.meta[kit.MDB_KEY] {
|
||||||
line[k] = kit.Select("", m.meta[kit.MDB_VALUE], i)
|
line[k] = kit.Select("", m.meta[kit.MDB_VALUE], i)
|
||||||
@ -290,7 +261,6 @@ func (m *Message) Table(cbs ...func(index int, value map[string]string, head []s
|
|||||||
for _, k := range m.meta[MSG_APPEND] {
|
for _, k := range m.meta[MSG_APPEND] {
|
||||||
line[k] = kit.Select("", m.meta[k], i)
|
line[k] = kit.Select("", m.meta[k], i)
|
||||||
}
|
}
|
||||||
// 依次回调
|
|
||||||
cbs[0](i, line, m.meta[MSG_APPEND])
|
cbs[0](i, line, m.meta[MSG_APPEND])
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
@ -330,8 +300,7 @@ func (m *Message) Table(cbs ...func(index int, value map[string]string, head []s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 输出表头
|
// 输出表头
|
||||||
row := map[string]string{}
|
row, wor := map[string]string{}, []string{}
|
||||||
wor := []string{}
|
|
||||||
for _, k := range m.meta[MSG_APPEND] {
|
for _, k := range m.meta[MSG_APPEND] {
|
||||||
row[k], wor = k, append(wor, k+strings.Repeat(space, width[k]-kit.Width(k, len(space))))
|
row[k], wor = k, append(wor, k+strings.Repeat(space, width[k]-kit.Width(k, len(space))))
|
||||||
}
|
}
|
||||||
@ -341,8 +310,7 @@ func (m *Message) Table(cbs ...func(index int, value map[string]string, head []s
|
|||||||
|
|
||||||
// 输出数据
|
// 输出数据
|
||||||
for i := 0; i < depth; i++ {
|
for i := 0; i < depth; i++ {
|
||||||
row := map[string]string{}
|
row, wor := map[string]string{}, []string{}
|
||||||
wor := []string{}
|
|
||||||
for _, k := range m.meta[MSG_APPEND] {
|
for _, k := range m.meta[MSG_APPEND] {
|
||||||
data := ""
|
data := ""
|
||||||
if i < len(m.meta[k]) {
|
if i < len(m.meta[k]) {
|
||||||
@ -351,7 +319,6 @@ func (m *Message) Table(cbs ...func(index int, value map[string]string, head []s
|
|||||||
|
|
||||||
row[k], wor = data, append(wor, data+strings.Repeat(space, width[k]-kit.Width(data, len(space))))
|
row[k], wor = data, append(wor, data+strings.Repeat(space, width[k]-kit.Width(data, len(space))))
|
||||||
}
|
}
|
||||||
// 依次回调
|
|
||||||
if !cb(row, wor, i) {
|
if !cb(row, wor, i) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -375,18 +342,13 @@ func (m *Message) Optionv(key string, arg ...interface{}) interface{} {
|
|||||||
case nil:
|
case nil:
|
||||||
delete(m.meta, key)
|
delete(m.meta, key)
|
||||||
case string:
|
case string:
|
||||||
m.meta[key] = kit.Simple(arg)
|
m.meta[key] = kit.Simple(arg...)
|
||||||
case []string:
|
case []string:
|
||||||
m.meta[key] = str
|
|
||||||
delete(m.data, key)
|
delete(m.data, key)
|
||||||
|
m.meta[key] = str
|
||||||
default:
|
default:
|
||||||
m.data[key] = str
|
m.data[key] = str
|
||||||
}
|
}
|
||||||
if key == MSG_FIELDS {
|
|
||||||
for _, k := range kit.Split(kit.Join(m.meta[key])) {
|
|
||||||
delete(m.meta, k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for msg := m; msg != nil; msg = msg.message {
|
for msg := m; msg != nil; msg = msg.message {
|
||||||
@ -399,9 +361,6 @@ func (m *Message) Optionv(key string, arg ...interface{}) interface{} {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (m *Message) Options(key string, arg ...interface{}) bool {
|
|
||||||
return kit.Select("", kit.Simple(m.Optionv(key, arg...)), 0) != ""
|
|
||||||
}
|
|
||||||
func (m *Message) Option(key string, arg ...interface{}) string {
|
func (m *Message) Option(key string, arg ...interface{}) string {
|
||||||
return kit.Select("", kit.Simple(m.Optionv(key, arg...)), 0)
|
return kit.Select("", kit.Simple(m.Optionv(key, arg...)), 0)
|
||||||
}
|
}
|
||||||
@ -416,21 +375,7 @@ func (m *Message) Appendv(key string, arg ...interface{}) []string {
|
|||||||
return m.meta[key]
|
return m.meta[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
if key == "_index" {
|
if m.FieldsIsDetail() {
|
||||||
max := 0
|
|
||||||
for _, k := range m.meta[MSG_APPEND] {
|
|
||||||
if len(m.meta[k]) > max {
|
|
||||||
max = len(m.meta[k])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
index := []string{}
|
|
||||||
for i := 0; i < max; i++ {
|
|
||||||
index = append(index, kit.Format(i))
|
|
||||||
}
|
|
||||||
return index
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(m.meta[MSG_APPEND]) == 2 && m.meta[MSG_APPEND][0] == kit.MDB_KEY {
|
|
||||||
for i, k := range m.meta[kit.MDB_KEY] {
|
for i, k := range m.meta[kit.MDB_KEY] {
|
||||||
if k == key {
|
if k == key {
|
||||||
return []string{kit.Select("", m.meta[kit.MDB_VALUE], i)}
|
return []string{kit.Select("", m.meta[kit.MDB_VALUE], i)}
|
||||||
|
78
misc.go
78
misc.go
@ -29,41 +29,17 @@ func (m *Message) CSV(text string, head ...string) *Message {
|
|||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Parse(meta string, key string, arg ...string) *Message {
|
func (m *Message) Split(str string, field string, sp string, nl string) *Message {
|
||||||
list := []string{}
|
fields, indexs := kit.Split(field, sp, sp, sp), []int{}
|
||||||
for _, line := range kit.Split(strings.Join(arg, SP), NL) {
|
for i, l := range kit.Split(str, nl, nl, nl) {
|
||||||
ls := kit.Split(line)
|
|
||||||
for i := 0; i < len(ls); i++ {
|
|
||||||
if strings.HasPrefix(ls[i], "#") {
|
|
||||||
ls = ls[:i]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
list = append(list, ls...)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch data := kit.Parse(nil, "", list...); meta {
|
|
||||||
case MSG_OPTION:
|
|
||||||
m.Option(key, data)
|
|
||||||
case MSG_APPEND:
|
|
||||||
m.Append(key, data)
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
func (m *Message) Split(str string, field string, space string, enter string) *Message {
|
|
||||||
indexs := []int{}
|
|
||||||
fields := kit.Split(field, space, space, space)
|
|
||||||
for i, l := range kit.Split(str, enter, enter, enter) {
|
|
||||||
if strings.HasPrefix(l, "Binary") {
|
if strings.HasPrefix(l, "Binary") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.TrimSpace(l) == "" {
|
if strings.TrimSpace(l) == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i == 0 && (field == "" || field == "index") {
|
if i == 0 && (field == "" || field == "index") { // 表头行
|
||||||
// 表头行
|
if fields = kit.Split(l, sp, sp); field == "index" {
|
||||||
fields = kit.Split(l, space, space)
|
|
||||||
if field == "index" {
|
|
||||||
for _, v := range fields {
|
for _, v := range fields {
|
||||||
indexs = append(indexs, strings.Index(l, v))
|
indexs = append(indexs, strings.Index(l, v))
|
||||||
}
|
}
|
||||||
@ -71,41 +47,41 @@ func (m *Message) Split(str string, field string, space string, enter string) *M
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(indexs) > 0 {
|
if len(indexs) > 0 { // 按位切分
|
||||||
// 数据行
|
|
||||||
for i, v := range indexs {
|
for i, v := range indexs {
|
||||||
if i == len(indexs)-1 {
|
if i == len(indexs)-1 {
|
||||||
m.Push(kit.Select("some", fields, i), l[v:])
|
m.Push(kit.Select(SP, fields, i), l[v:])
|
||||||
} else {
|
} else {
|
||||||
m.Push(kit.Select("some", fields, i), l[v:indexs[i+1]])
|
m.Push(kit.Select(SP, fields, i), l[v:indexs[i+1]])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ls := kit.Split(l, space, space)
|
ls := kit.Split(l, sp, sp)
|
||||||
for i, v := range ls {
|
for i, v := range ls {
|
||||||
if i == len(fields)-1 {
|
if i == len(fields)-1 {
|
||||||
m.Push(kit.Select("some", fields, i), strings.Join(ls[i:], space))
|
m.Push(kit.Select(SP, fields, i), strings.Join(ls[i:], sp))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
m.Push(kit.Select("some", fields, i), v)
|
m.Push(kit.Select(SP, fields, i), v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) ShowPlugin(pod, ctx, cmd string, arg ...string) {
|
func (m *Message) FieldsIsDetail() bool {
|
||||||
m.Cmdy("web.space", pod, "context", ctx, "command", cmd)
|
if m.OptionFields() == "detail" {
|
||||||
m.Option(MSG_PROCESS, PROCESS_FIELD)
|
return true
|
||||||
m.Option(FIELD_PREFIX, arg)
|
}
|
||||||
|
if len(m.meta[MSG_APPEND]) == 2 && m.meta[MSG_APPEND][0] == kit.MDB_KEY && m.meta[MSG_APPEND][1] == kit.MDB_VALUE {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
func (m *Message) OptionUserWeb() *url.URL {
|
func (m *Message) OptionUserWeb() *url.URL {
|
||||||
return kit.ParseURL(m.Option(MSG_USERWEB))
|
return kit.ParseURL(m.Option(MSG_USERWEB))
|
||||||
}
|
}
|
||||||
func (m *Message) SetAppend(key ...string) {
|
|
||||||
m.Set(MSG_APPEND, key...)
|
|
||||||
}
|
|
||||||
func (m *Message) RenameAppend(from, to string) {
|
func (m *Message) RenameAppend(from, to string) {
|
||||||
for i, v := range m.meta[MSG_APPEND] {
|
for i, v := range m.meta[MSG_APPEND] {
|
||||||
if v == from {
|
if v == from {
|
||||||
@ -157,6 +133,8 @@ func (m *Message) cmd(arg ...interface{}) *Message {
|
|||||||
case Option:
|
case Option:
|
||||||
opts[val.Name] = val.Value
|
opts[val.Name] = val.Value
|
||||||
|
|
||||||
|
case string:
|
||||||
|
args = append(args, v)
|
||||||
default:
|
default:
|
||||||
if reflect.Func == reflect.TypeOf(val).Kind() {
|
if reflect.Func == reflect.TypeOf(val).Kind() {
|
||||||
cbs = val
|
cbs = val
|
||||||
@ -185,9 +163,7 @@ func (m *Message) cmd(arg ...interface{}) *Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 执行命令
|
// 执行命令
|
||||||
m.TryCatch(msg, true, func(msg *Message) {
|
m.TryCatch(msg, true, func(msg *Message) { m = ctx.cmd(msg, cmd, key, arg...) })
|
||||||
m = ctx.cmd(msg, cmd, key, arg...)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找命令
|
// 查找命令
|
||||||
@ -203,7 +179,7 @@ func (m *Message) cmd(arg ...interface{}) *Message {
|
|||||||
|
|
||||||
// 系统命令
|
// 系统命令
|
||||||
if m.Warn(!ok, ErrNotFound, list) {
|
if m.Warn(!ok, ErrNotFound, list) {
|
||||||
return m.Set(MSG_RESULT).Cmdy("cli.system", list)
|
return m.Set(MSG_RESULT).Cmdy("system", list)
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
@ -252,10 +228,12 @@ func (c *Context) _cmd(m *Message, cmd *Command, key string, k string, h *Action
|
|||||||
order = true
|
order = true
|
||||||
}
|
}
|
||||||
if order {
|
if order {
|
||||||
value = kit.Select(value, arg, i)
|
m.Option(name, kit.Select(value, arg, i))
|
||||||
|
} else {
|
||||||
|
if m.Option(name) == "" {
|
||||||
|
m.Option(name, value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Option(name, kit.Select(m.Option(name), value, !strings.HasPrefix(value, "@")))
|
|
||||||
}
|
}
|
||||||
if !order {
|
if !order {
|
||||||
for i := 0; i < len(arg)-1; i += 2 {
|
for i := 0; i < len(arg)-1; i += 2 {
|
||||||
|
@ -84,7 +84,7 @@ func _input_save(m *ice.Message, file string, lib ...string) {
|
|||||||
if f, p, e := kit.Create(file); m.Assert(e) {
|
if f, p, e := kit.Create(file); m.Assert(e) {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
n := 0
|
n := 0
|
||||||
m.Option(mdb.CACHE_LIMIT, -2)
|
m.Option(ice.CACHE_LIMIT, -2)
|
||||||
for _, lib := range lib {
|
for _, lib := range lib {
|
||||||
m.Richs(INPUT, "", lib, func(key string, value map[string]interface{}) {
|
m.Richs(INPUT, "", lib, func(key string, value map[string]interface{}) {
|
||||||
m.Grows(INPUT, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
m.Grows(INPUT, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||||
@ -174,7 +174,7 @@ var Index = &ice.Context{Name: INPUT, Help: "输入法",
|
|||||||
_input_load(m, kit.Select("usr/wubi-dict/person", m.Option(FILE)), m.Option(ZONE))
|
_input_load(m, kit.Select("usr/wubi-dict/person", m.Option(FILE)), m.Option(ZONE))
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
_input_find(m, arg[0], arg[1], m.Option(mdb.CACHE_LIMIT))
|
_input_find(m, arg[0], arg[1], m.Option(ice.CACHE_LIMIT))
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ func init() {
|
|||||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||||
EVENT: {Name: "event", Help: "事件", Action: map[string]*ice.Action{
|
EVENT: {Name: "event", Help: "事件", Action: map[string]*ice.Action{
|
||||||
P2P_CHAT_CREATE: {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) {
|
P2P_CHAT_CREATE: {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) {
|
||||||
if m.Options(OPEN_CHAT_ID) {
|
if m.Option(OPEN_CHAT_ID) != "" {
|
||||||
m.Cmdy(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Conf(APP, kit.Keym(kit.MDB_TEMPLATE, m.Option(kit.MDB_TYPE))))
|
m.Cmdy(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Conf(APP, kit.Keym(kit.MDB_TEMPLATE, m.Option(kit.MDB_TYPE))))
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
@ -27,7 +27,7 @@ func init() {
|
|||||||
CHAT_DISBAND: {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) {
|
CHAT_DISBAND: {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) {
|
||||||
}},
|
}},
|
||||||
ADD_BOT: {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) {
|
ADD_BOT: {Name: "", Help: "", Hand: func(m *ice.Message, arg ...string) {
|
||||||
if m.Options(OPEN_CHAT_ID) {
|
if m.Option(OPEN_CHAT_ID) != "" {
|
||||||
m.Cmdy(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Conf(APP, kit.Keym(kit.MDB_TEMPLATE, m.Option(kit.MDB_TYPE))))
|
m.Cmdy(SEND, m.Option(APP_ID), m.Option(OPEN_CHAT_ID), m.Conf(APP, kit.Keym(kit.MDB_TEMPLATE, m.Option(kit.MDB_TYPE))))
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
@ -93,10 +93,10 @@ func init() {
|
|||||||
m.Option(wiki.TITLE)+" "+m.Option(ice.CMD), m.Result())
|
m.Option(wiki.TITLE)+" "+m.Option(ice.CMD), m.Result())
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||||
if m.Options(OPEN_CHAT_ID) {
|
if m.Option(OPEN_CHAT_ID) == "" {
|
||||||
m.Cmdy(TALK, strings.TrimSpace(m.Option("text_without_at_bot")))
|
|
||||||
} else {
|
|
||||||
m.Cmdy(DUTY, m.Option(kit.MDB_TYPE), kit.Formats(m.Optionv(ice.MSG_USERDATA)))
|
m.Cmdy(DUTY, m.Option(kit.MDB_TYPE), kit.Formats(m.Optionv(ice.MSG_USERDATA)))
|
||||||
|
} else {
|
||||||
|
m.Cmdy(TALK, strings.TrimSpace(m.Option("text_without_at_bot")))
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
}})
|
}})
|
||||||
|
16
option.go
16
option.go
@ -22,11 +22,12 @@ func (m *Message) OptionFields(arg ...string) string {
|
|||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
m.Option(MSG_FIELDS, kit.Join(arg))
|
m.Option(MSG_FIELDS, kit.Join(arg))
|
||||||
}
|
}
|
||||||
return m.Option(MSG_FIELDS)
|
return kit.Join(kit.Simple(m.Optionv(MSG_FIELDS)))
|
||||||
}
|
}
|
||||||
func (m *Message) OptionPage(arg ...string) {
|
func (m *Message) OptionPage(arg ...string) {
|
||||||
m.Option(CACHE_LIMIT, kit.Select("10", arg, 0))
|
m.Option(CACHE_LIMIT, kit.Select("10", arg, 0))
|
||||||
m.Option(CACHE_OFFEND, kit.Select("0", arg, 1))
|
m.Option(CACHE_OFFEND, kit.Select("0", arg, 1))
|
||||||
|
m.Option(CACHE_FILTER, kit.Select("", arg, 2))
|
||||||
}
|
}
|
||||||
func (m *Message) OptionLoad(file string) *Message {
|
func (m *Message) OptionLoad(file string) *Message {
|
||||||
if f, e := os.Open(file); e == nil {
|
if f, e := os.Open(file); e == nil {
|
||||||
@ -80,12 +81,9 @@ func (m *Message) Fields(length int, fields ...string) string {
|
|||||||
func (m *Message) Upload(dir string) {
|
func (m *Message) Upload(dir string) {
|
||||||
up := kit.Simple(m.Optionv(MSG_UPLOAD))
|
up := kit.Simple(m.Optionv(MSG_UPLOAD))
|
||||||
if p := path.Join(dir, up[1]); m.Option(MSG_USERPOD) == "" {
|
if p := path.Join(dir, up[1]); m.Option(MSG_USERPOD) == "" {
|
||||||
// 本机文件
|
m.Cmdy("cache", "watch", up[0], p) // 本机文件
|
||||||
m.Cmdy("web.cache", "watch", up[0], p)
|
} else { // 下发文件
|
||||||
} else {
|
m.Cmdy("spide", DEV, SAVE, p, "GET", kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/cache", up[0])))
|
||||||
// 下拉文件
|
|
||||||
m.Cmdy("web.spide", DEV, SAVE, p, "GET",
|
|
||||||
kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/cache", up[0])))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (m *Message) Action(arg ...string) {
|
func (m *Message) Action(arg ...string) {
|
||||||
@ -109,7 +107,7 @@ func (m *Message) StatusTimeCountTotal(arg ...interface{}) {
|
|||||||
m.Status(kit.MDB_TIME, m.Time(), kit.MDB_COUNT, m.FormatSize(), kit.MDB_TOTAL, arg, kit.MDB_COST, m.FormatCost())
|
m.Status(kit.MDB_TIME, m.Time(), kit.MDB_COUNT, m.FormatSize(), kit.MDB_TOTAL, arg, kit.MDB_COST, m.FormatCost())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) Toast(text string, arg ...interface{}) { // [title [duration]]
|
func (m *Message) Toast(text string, arg ...interface{}) { // [title [duration [progress]]]
|
||||||
if len(arg) > 1 {
|
if len(arg) > 1 {
|
||||||
switch val := arg[1].(type) {
|
switch val := arg[1].(type) {
|
||||||
case string:
|
case string:
|
||||||
@ -120,7 +118,7 @@ func (m *Message) Toast(text string, arg ...interface{}) { // [title [duration]]
|
|||||||
}
|
}
|
||||||
|
|
||||||
if m.Option(MSG_USERPOD) == "" {
|
if m.Option(MSG_USERPOD) == "" {
|
||||||
m.Cmd("web.space", m.Option(MSG_DAEMON), "toast", "", text, arg)
|
m.Cmd("space", m.Option(MSG_DAEMON), "toast", "", text, arg)
|
||||||
} else {
|
} else {
|
||||||
m.Option(MSG_TOAST, kit.Simple(text, arg))
|
m.Option(MSG_TOAST, kit.Simple(text, arg))
|
||||||
}
|
}
|
||||||
|
85
render.go
85
render.go
@ -1,7 +1,6 @@
|
|||||||
package ice
|
package ice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -44,6 +43,37 @@ func Render(m *Message, cmd string, args ...interface{}) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Message) Render(cmd string, args ...interface{}) *Message {
|
||||||
|
m.Optionv(MSG_OUTPUT, cmd)
|
||||||
|
m.Optionv(MSG_ARGS, args)
|
||||||
|
|
||||||
|
switch cmd {
|
||||||
|
case RENDER_TEMPLATE: // text [data [type]]
|
||||||
|
if len(args) == 1 {
|
||||||
|
args = append(args, m)
|
||||||
|
}
|
||||||
|
if res, err := kit.Render(args[0].(string), args[1]); m.Assert(err) {
|
||||||
|
m.Echo(string(res))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
func (m *Message) RenderResult(args ...interface{}) *Message {
|
||||||
|
return m.Render(RENDER_RESULT, args...)
|
||||||
|
}
|
||||||
|
func (m *Message) RenderTemplate(args ...interface{}) *Message {
|
||||||
|
return m.Render(RENDER_TEMPLATE, args...)
|
||||||
|
}
|
||||||
|
func (m *Message) RenderRedirect(args ...interface{}) *Message {
|
||||||
|
return m.Render(RENDER_REDIRECT, args...)
|
||||||
|
}
|
||||||
|
func (m *Message) RenderDownload(args ...interface{}) *Message {
|
||||||
|
return m.Render(RENDER_DOWNLOAD, args...)
|
||||||
|
}
|
||||||
|
func (m *Message) RenderIndex(serve, repos string, file ...string) *Message {
|
||||||
|
return m.RenderDownload(path.Join(m.Conf(serve, kit.Keym(repos, kit.MDB_PATH)), kit.Select(m.Conf(serve, kit.Keym(repos, kit.MDB_INDEX)), path.Join(file...))))
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Message) IsCliUA() bool {
|
func (m *Message) IsCliUA() bool {
|
||||||
if m.Option(MSG_USERUA) == "" || !strings.HasPrefix(m.Option(MSG_USERUA), "Mozilla/5.0") {
|
if m.Option(MSG_USERUA) == "" || !strings.HasPrefix(m.Option(MSG_USERUA), "Mozilla/5.0") {
|
||||||
return true
|
return true
|
||||||
@ -98,13 +128,13 @@ func (m *Message) PushPodCmd(cmd string, arg ...string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Cmd("web.space").Table(func(index int, value map[string]string, head []string) {
|
m.Cmd("space").Table(func(index int, value map[string]string, head []string) {
|
||||||
switch value[kit.MDB_TYPE] {
|
switch value[kit.MDB_TYPE] {
|
||||||
case "worker", "server":
|
case "server", "worker":
|
||||||
if value[kit.MDB_NAME] == Info.HostName {
|
if value[kit.MDB_NAME] == Info.HostName {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
m.Cmd("web.space", value[kit.MDB_NAME], m.Prefix(cmd), arg).Table(func(index int, val map[string]string, head []string) {
|
m.Cmd("space", value[kit.MDB_NAME], m.Prefix(cmd), arg).Table(func(index int, val map[string]string, head []string) {
|
||||||
val[POD] = kit.Keys(value[kit.MDB_NAME], val[POD])
|
val[POD] = kit.Keys(value[kit.MDB_NAME], val[POD])
|
||||||
m.Push("", val, head)
|
m.Push("", val, head)
|
||||||
})
|
})
|
||||||
@ -117,11 +147,10 @@ func (m *Message) PushSearch(args ...interface{}) {
|
|||||||
switch k {
|
switch k {
|
||||||
case POD:
|
case POD:
|
||||||
m.Push(k, kit.Select("", data[k]))
|
m.Push(k, kit.Select("", data[k]))
|
||||||
// m.Push(k, kit.Select(m.Option(MSG_USERPOD), data[POD]))
|
|
||||||
case CTX:
|
case CTX:
|
||||||
m.Push(k, kit.Select(m.Prefix(), data[CTX]))
|
m.Push(k, kit.Select(m.Prefix(), data[k]))
|
||||||
case CMD:
|
case CMD:
|
||||||
m.Push(k, kit.Select(m.CommandKey(), data[CMD]))
|
m.Push(k, kit.Select(m.CommandKey(), data[k]))
|
||||||
case kit.MDB_TIME:
|
case kit.MDB_TIME:
|
||||||
m.Push(k, kit.Select(m.Time(), data[k]))
|
m.Push(k, kit.Select(m.Time(), data[k]))
|
||||||
default:
|
default:
|
||||||
@ -129,17 +158,6 @@ func (m *Message) PushSearch(args ...interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (m *Message) PushSearchWeb(cmd string, name string) {
|
|
||||||
msg := m.Spawn()
|
|
||||||
msg.Option(MSG_FIELDS, "type,name,text")
|
|
||||||
msg.Cmd("mdb.select", m.Prefix(cmd), "", kit.MDB_HASH).Table(func(index int, value map[string]string, head []string) {
|
|
||||||
text := kit.MergeURL(value[kit.MDB_TEXT], value[kit.MDB_NAME], name)
|
|
||||||
if value[kit.MDB_NAME] == "" {
|
|
||||||
text = kit.MergeURL(value[kit.MDB_TEXT] + url.QueryEscape(name))
|
|
||||||
}
|
|
||||||
m.PushSearch(CMD, cmd, kit.MDB_TYPE, kit.Select("", value[kit.MDB_TYPE]), kit.MDB_NAME, name, kit.MDB_TEXT, text)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Message) EchoDownload(arg ...interface{}) *Message { // [name] file
|
func (m *Message) EchoDownload(arg ...interface{}) *Message { // [name] file
|
||||||
return m.Echo(Render(m, RENDER_DOWNLOAD, arg...))
|
return m.Echo(Render(m, RENDER_DOWNLOAD, arg...))
|
||||||
@ -162,34 +180,3 @@ func (m *Message) EchoImages(src string, arg ...string) *Message { // src [size]
|
|||||||
func (m *Message) EchoVideos(src string, arg ...string) *Message { // src [size]
|
func (m *Message) EchoVideos(src string, arg ...string) *Message { // src [size]
|
||||||
return m.Echo(Render(m, RENDER_VIDEOS, src, arg))
|
return m.Echo(Render(m, RENDER_VIDEOS, src, arg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) Render(cmd string, args ...interface{}) *Message {
|
|
||||||
m.Optionv(MSG_OUTPUT, cmd)
|
|
||||||
m.Optionv(MSG_ARGS, args)
|
|
||||||
|
|
||||||
switch cmd {
|
|
||||||
case RENDER_TEMPLATE: // text [data [type]]
|
|
||||||
if len(args) == 1 {
|
|
||||||
args = append(args, m)
|
|
||||||
}
|
|
||||||
if res, err := kit.Render(args[0].(string), args[1]); m.Assert(err) {
|
|
||||||
m.Echo(string(res))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
func (m *Message) RenderResult(args ...interface{}) *Message {
|
|
||||||
return m.Render(RENDER_RESULT, args...)
|
|
||||||
}
|
|
||||||
func (m *Message) RenderTemplate(args ...interface{}) *Message {
|
|
||||||
return m.Render(RENDER_TEMPLATE, args...)
|
|
||||||
}
|
|
||||||
func (m *Message) RenderRedirect(args ...interface{}) *Message {
|
|
||||||
return m.Render(RENDER_REDIRECT, args...)
|
|
||||||
}
|
|
||||||
func (m *Message) RenderDownload(args ...interface{}) *Message {
|
|
||||||
return m.Render(RENDER_DOWNLOAD, args...)
|
|
||||||
}
|
|
||||||
func (m *Message) RenderIndex(serve, repos string, file ...string) *Message {
|
|
||||||
return m.RenderDownload(path.Join(m.Conf(serve, kit.Keym(repos, kit.MDB_PATH)), kit.Select(m.Conf(serve, kit.Keym(repos, kit.MDB_INDEX)), path.Join(file...))))
|
|
||||||
}
|
|
||||||
|
100
type.go
100
type.go
@ -65,9 +65,6 @@ type Context struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) ID() int32 {
|
func (c *Context) ID() int32 {
|
||||||
if c == nil {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return atomic.AddInt32(&c.id, 1)
|
return atomic.AddInt32(&c.id, 1)
|
||||||
}
|
}
|
||||||
func (c *Context) Cap(key string, arg ...interface{}) string {
|
func (c *Context) Cap(key string, arg ...interface{}) string {
|
||||||
@ -84,10 +81,6 @@ func (c *Context) Server() Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Register(s *Context, x Server, name ...string) *Context {
|
func (c *Context) Register(s *Context, x Server, name ...string) *Context {
|
||||||
if s.Merge(s); s.Name == "" {
|
|
||||||
s.Name = kit.Split(kit.Split(kit.FileLine(2, 3), ":")[0], "/")[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, n := range name {
|
for _, n := range name {
|
||||||
Name(n, s)
|
Name(n, s)
|
||||||
}
|
}
|
||||||
@ -99,6 +92,7 @@ func (c *Context) Register(s *Context, x Server, name ...string) *Context {
|
|||||||
s.root = c.root
|
s.root = c.root
|
||||||
s.context = c
|
s.context = c
|
||||||
s.server = x
|
s.server = x
|
||||||
|
s.Merge(s)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
func (c *Context) Merge(s *Context) *Context {
|
func (c *Context) Merge(s *Context) *Context {
|
||||||
@ -112,29 +106,24 @@ func (c *Context) Merge(s *Context) *Context {
|
|||||||
c.Commands[CTX_EXIT] = &Command{Hand: func(m *Message, c *Context, cmd string, arg ...string) { m.Save() }}
|
c.Commands[CTX_EXIT] = &Command{Hand: func(m *Message, c *Context, cmd string, arg ...string) { m.Save() }}
|
||||||
}
|
}
|
||||||
for k, v := range s.Commands {
|
for k, v := range s.Commands {
|
||||||
if o, ok := c.Commands[k]; ok && s != c {
|
if p, ok := c.Commands[k]; ok && s != c {
|
||||||
func() {
|
switch last, next := p.Hand, v.Hand; k {
|
||||||
switch last, next := o.Hand, v.Hand; k {
|
case CTX_INIT:
|
||||||
case CTX_INIT:
|
v.Hand = func(m *Message, c *Context, key string, arg ...string) {
|
||||||
v.Hand = func(m *Message, c *Context, key string, arg ...string) {
|
last(m, c, key, arg...)
|
||||||
last(m, c, key, arg...)
|
next(m, c, key, arg...)
|
||||||
next(m, c, key, arg...)
|
|
||||||
}
|
|
||||||
case CTX_EXIT:
|
|
||||||
v.Hand = func(m *Message, c *Context, key string, arg ...string) {
|
|
||||||
next(m, c, key, arg...)
|
|
||||||
last(m, c, key, arg...)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
case CTX_EXIT:
|
||||||
|
v.Hand = func(m *Message, c *Context, key string, arg ...string) {
|
||||||
|
next(m, c, key, arg...)
|
||||||
|
last(m, c, key, arg...)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Meta == nil {
|
if v.Meta == nil {
|
||||||
v.Meta = kit.Dict()
|
v.Meta = kit.Dict()
|
||||||
}
|
}
|
||||||
if p := kit.Format(v.Meta[kit.MDB_STYLE]); p == "" {
|
|
||||||
v.Meta[kit.MDB_STYLE] = k
|
|
||||||
}
|
|
||||||
if c.Commands[k] = v; v.List == nil {
|
if c.Commands[k] = v; v.List == nil {
|
||||||
v.List = c.split(v.Name)
|
v.List = c.split(v.Name)
|
||||||
}
|
}
|
||||||
@ -144,13 +133,9 @@ func (c *Context) Merge(s *Context) *Context {
|
|||||||
if len(help) == 1 || help[1] == "" {
|
if len(help) == 1 || help[1] == "" {
|
||||||
help = strings.SplitN(help[0], ":", 2)
|
help = strings.SplitN(help[0], ":", 2)
|
||||||
}
|
}
|
||||||
kit.Value(v.Meta, kit.Keys("_trans", k), help[0])
|
if kit.Value(v.Meta, kit.Keys("_trans", k), help[0]); len(help) > 1 {
|
||||||
if len(help) > 1 {
|
|
||||||
kit.Value(v.Meta, kit.Keys(kit.MDB_TITLE, k), help[1])
|
kit.Value(v.Meta, kit.Keys(kit.MDB_TITLE, k), help[1])
|
||||||
}
|
}
|
||||||
if a.Hand == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if a.List == nil {
|
if a.List == nil {
|
||||||
a.List = c.split(a.Name)
|
a.List = c.split(a.Name)
|
||||||
}
|
}
|
||||||
@ -198,28 +183,22 @@ func (c *Context) Begin(m *Message, arg ...string) *Context {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
func (c *Context) Start(m *Message, arg ...string) bool {
|
func (c *Context) Start(m *Message, arg ...string) bool {
|
||||||
wait := make(chan bool)
|
|
||||||
|
|
||||||
m.Hold(1)
|
m.Hold(1)
|
||||||
m.Go(func() {
|
m.Go(func() {
|
||||||
m.Log(LOG_START, c.Cap(CTX_FOLLOW))
|
defer m.Done(true)
|
||||||
|
|
||||||
c.Cap(CTX_STATUS, CTX_START)
|
c.Cap(CTX_STATUS, CTX_START)
|
||||||
wait <- true
|
m.Log(LOG_START, c.Cap(CTX_FOLLOW))
|
||||||
|
|
||||||
if c.start = m; c.server != nil {
|
if c.start = m; c.server != nil {
|
||||||
c.server.Start(m, arg...)
|
c.server.Start(m, arg...)
|
||||||
}
|
}
|
||||||
if m.Done(true); m.wait != nil {
|
|
||||||
m.wait <- true
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
<-wait
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (c *Context) Close(m *Message, arg ...string) bool {
|
func (c *Context) Close(m *Message, arg ...string) bool {
|
||||||
m.Log(LOG_CLOSE, c.Cap(CTX_FOLLOW))
|
|
||||||
c.Cap(CTX_STATUS, CTX_CLOSE)
|
c.Cap(CTX_STATUS, CTX_CLOSE)
|
||||||
|
m.Log(LOG_CLOSE, c.Cap(CTX_FOLLOW))
|
||||||
|
|
||||||
if c.server != nil {
|
if c.server != nil {
|
||||||
return c.server.Close(m, arg...)
|
return c.server.Close(m, arg...)
|
||||||
@ -231,7 +210,6 @@ type Message struct {
|
|||||||
time time.Time
|
time time.Time
|
||||||
code int
|
code int
|
||||||
Hand bool
|
Hand bool
|
||||||
wait chan bool
|
|
||||||
|
|
||||||
meta map[string][]string
|
meta map[string][]string
|
||||||
data map[string]interface{}
|
data map[string]interface{}
|
||||||
@ -281,11 +259,10 @@ func (m *Message) Source() *Context {
|
|||||||
func (m *Message) Spawn(arg ...interface{}) *Message {
|
func (m *Message) Spawn(arg ...interface{}) *Message {
|
||||||
msg := &Message{
|
msg := &Message{
|
||||||
time: time.Now(), code: int(m.target.root.ID()),
|
time: time.Now(), code: int(m.target.root.ID()),
|
||||||
meta: map[string][]string{},
|
meta: map[string][]string{}, data: map[string]interface{}{},
|
||||||
data: map[string]interface{}{},
|
|
||||||
|
|
||||||
message: m, root: m.root,
|
message: m, root: m.root,
|
||||||
source: m.target, target: m.target, _key: m._key,
|
source: m.target, target: m.target, _cmd: m._cmd, _key: m._key,
|
||||||
W: m.W, R: m.R, O: m.O, I: m.I,
|
W: m.W, R: m.R, O: m.O, I: m.I,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,24 +277,16 @@ func (m *Message) Spawn(arg ...interface{}) *Message {
|
|||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
func (m *Message) Start(key string, arg ...string) *Message {
|
func (m *Message) Start(key string, arg ...string) *Message {
|
||||||
m.Search(key+PT, func(p *Context, s *Context) {
|
m.Search(key+PT, func(p *Context, s *Context) { s.Start(m.Spawn(s), arg...) })
|
||||||
s.Start(m.Spawn(s), arg...)
|
|
||||||
})
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
func (m *Message) Starts(name string, help string, arg ...string) *Message {
|
|
||||||
m.wait = make(chan bool)
|
|
||||||
m.target.Spawn(m, name, help, arg...).Begin(m, arg...).Start(m, arg...)
|
|
||||||
<-m.wait
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Travel(cb interface{}) *Message {
|
func (m *Message) Travel(cb interface{}) *Message {
|
||||||
list := []*Context{m.root.target}
|
list := []*Context{m.root.target}
|
||||||
for i := 0; i < len(list); i++ {
|
for i := 0; i < len(list); i++ {
|
||||||
switch cb := cb.(type) {
|
switch cb := cb.(type) {
|
||||||
case func(*Context, *Context):
|
case func(*Context, *Context): // 遍历模块
|
||||||
// 遍历模块
|
|
||||||
cb(list[i].context, list[i])
|
cb(list[i].context, list[i])
|
||||||
|
|
||||||
case func(*Context, *Context, string, *Command):
|
case func(*Context, *Context, string, *Command):
|
||||||
ls := []string{}
|
ls := []string{}
|
||||||
for k := range list[i].Commands {
|
for k := range list[i].Commands {
|
||||||
@ -331,6 +300,7 @@ func (m *Message) Travel(cb interface{}) *Message {
|
|||||||
cb(list[i].context, list[i], k, list[i].Commands[k])
|
cb(list[i].context, list[i], k, list[i].Commands[k])
|
||||||
}
|
}
|
||||||
m.target = target
|
m.target = target
|
||||||
|
|
||||||
case func(*Context, *Context, string, *Config):
|
case func(*Context, *Context, string, *Config):
|
||||||
ls := []string{}
|
ls := []string{}
|
||||||
for k := range list[i].Configs {
|
for k := range list[i].Configs {
|
||||||
@ -338,9 +308,12 @@ func (m *Message) Travel(cb interface{}) *Message {
|
|||||||
}
|
}
|
||||||
sort.Strings(ls)
|
sort.Strings(ls)
|
||||||
|
|
||||||
|
target := m.target
|
||||||
for _, k := range ls { // 配置列表
|
for _, k := range ls { // 配置列表
|
||||||
|
m.target = list[i]
|
||||||
cb(list[i].context, list[i], k, list[i].Configs[k])
|
cb(list[i].context, list[i], k, list[i].Configs[k])
|
||||||
}
|
}
|
||||||
|
m.target = target
|
||||||
}
|
}
|
||||||
|
|
||||||
ls := []string{}
|
ls := []string{}
|
||||||
@ -369,9 +342,10 @@ func (m *Message) Search(key string, cb interface{}) *Message {
|
|||||||
} else if key == PT {
|
} else if key == PT {
|
||||||
p, key = m.target, ""
|
p, key = m.target, ""
|
||||||
} else if key == ".." {
|
} else if key == ".." {
|
||||||
if m.target.context != nil {
|
if m.target.context == nil {
|
||||||
p, key = m.target.context, ""
|
return m
|
||||||
}
|
}
|
||||||
|
p, key = m.target.context, ""
|
||||||
} else if strings.Contains(key, PT) {
|
} else if strings.Contains(key, PT) {
|
||||||
list := strings.Split(key, PT)
|
list := strings.Split(key, PT)
|
||||||
for _, p = range []*Context{m.target.root, m.target, m.source} {
|
for _, p = range []*Context{m.target.root, m.target, m.source} {
|
||||||
@ -390,6 +364,7 @@ func (m *Message) Search(key string, cb interface{}) *Message {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Warn(p == nil, ErrNotFound, key) {
|
if m.Warn(p == nil, ErrNotFound, key) {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
@ -398,9 +373,8 @@ func (m *Message) Search(key string, cb interface{}) *Message {
|
|||||||
p = m.target
|
p = m.target
|
||||||
}
|
}
|
||||||
|
|
||||||
// 遍历命令
|
|
||||||
switch cb := cb.(type) {
|
switch cb := cb.(type) {
|
||||||
case func(key string, cmd *Command):
|
case func(key string, cmd *Command): // 遍历命令
|
||||||
if key == "" {
|
if key == "" {
|
||||||
for k, v := range p.Commands {
|
for k, v := range p.Commands {
|
||||||
cb(k, v)
|
cb(k, v)
|
||||||
@ -417,21 +391,19 @@ func (m *Message) Search(key string, cb interface{}) *Message {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找命令
|
|
||||||
for _, p := range []*Context{p, m.target, m.source} {
|
for _, p := range []*Context{p, m.target, m.source} {
|
||||||
for s := p; s != nil; s = s.context {
|
for s := p; s != nil; s = s.context {
|
||||||
if cmd, ok := s.Commands[key]; ok {
|
if cmd, ok := s.Commands[key]; ok {
|
||||||
cb(s.context, s, key, cmd)
|
cb(s.context, s, key, cmd) // 查找命令
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case func(p *Context, s *Context, key string, conf *Config):
|
case func(p *Context, s *Context, key string, conf *Config):
|
||||||
// 查找配置
|
for _, p := range []*Context{p, m.target, m.source} {
|
||||||
for _, p := range []*Context{m.target, p, m.source} {
|
|
||||||
for s := p; s != nil; s = s.context {
|
for s := p; s != nil; s = s.context {
|
||||||
if cmd, ok := s.Configs[key]; ok {
|
if cmd, ok := s.Configs[key]; ok {
|
||||||
cb(s.context, s, key, cmd)
|
cb(s.context, s, key, cmd) // 查找配置
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -440,6 +412,8 @@ func (m *Message) Search(key string, cb interface{}) *Message {
|
|||||||
cb(p.context, p, key)
|
cb(p.context, p, key)
|
||||||
case func(p *Context, s *Context):
|
case func(p *Context, s *Context):
|
||||||
cb(p.context, p)
|
cb(p.context, p)
|
||||||
|
default:
|
||||||
|
m.Error(true, ErrNotImplement)
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user