mirror of
https://shylinux.com/x/icebergs
synced 2025-04-28 02:02:02 +08:00
opt mdb
This commit is contained in:
parent
90eeb3e258
commit
97cc535496
@ -126,7 +126,7 @@ func init() {
|
||||
m.Cmd(gdb.SIGNAL, gdb.KILL, value[PID])
|
||||
})
|
||||
}},
|
||||
}, mdb.HashStatusAction(mdb.FIELD, "time,hash,status,pid,cmd,dir,env")), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.StatusHashAction(mdb.FIELD, "time,hash,status,pid,cmd,dir,env")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || !strings.Contains(arg[0], ice.PS) {
|
||||
if mdb.HashSelect(m, kit.Slice(arg, 0, 1)...).Tables(func(value ice.Maps) {
|
||||
switch value[STATUS] {
|
||||
|
@ -35,6 +35,6 @@ func init() {
|
||||
}
|
||||
})
|
||||
}},
|
||||
}, mdb.HashStatusAction(mdb.FIELD, "time,hash,status,name,cmd"))},
|
||||
}, mdb.StatusHashAction(mdb.FIELD, "time,hash,status,name,cmd"))},
|
||||
})
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ func _hash_select(m *ice.Message, prefix, chain, field, value string) {
|
||||
value = RANDOMS
|
||||
}
|
||||
defer m.SortTimeR(TIME)
|
||||
defer RLock(m, prefix, chain)()
|
||||
fields := _hash_fields(m)
|
||||
defer RLock(m, prefix, chain)()
|
||||
Richs(m, prefix, chain, value, func(key string, value Map) { _mdb_select(m, m.OptionCB(""), key, value, fields, nil) })
|
||||
}
|
||||
func _hash_select_field(m *ice.Message, prefix, chain string, key string, field string) (value string) {
|
||||
@ -138,23 +138,13 @@ func HashAction(arg ...Any) ice.Actions {
|
||||
IMPORT: {Hand: func(m *ice.Message, arg ...string) { HashImport(m, arg) }},
|
||||
}
|
||||
}
|
||||
func HashStatusAction(arg ...Any) ice.Actions {
|
||||
func StatusHashAction(arg ...Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
PRUNES: &ice.Action{Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(PRUNES, m.PrefixKey(), "", HASH, STATUS, "error", STATUS, "close", STATUS, "stop", STATUS, "end", ice.OptionFields(HashField(m)))
|
||||
}},
|
||||
}, HashAction(arg...))
|
||||
}
|
||||
func HashStatusCloseAction(args ...Any) ice.Actions {
|
||||
return ice.MergeActions(HashStatusAction(args...), ice.Actions{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { HashSelectClose(m) }},
|
||||
})
|
||||
}
|
||||
func HashCloseAction(args ...Any) ice.Actions {
|
||||
return ice.MergeActions(HashAction(args...), ice.Actions{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { HashSelectClose(m) }},
|
||||
})
|
||||
}
|
||||
|
||||
func HashKey(m *ice.Message) string {
|
||||
if m.Option(HASH) != "" {
|
||||
@ -232,18 +222,6 @@ func HashSelectValue(m *ice.Message, cb Any) *ice.Message {
|
||||
})
|
||||
return m
|
||||
}
|
||||
func HashPrunesValue(m *ice.Message, field, value string) {
|
||||
m.Cmdy(PRUNES, m.PrefixKey(), "", HASH, field, value, ice.OptionFields(HashField(m)))
|
||||
}
|
||||
func HashSelectClose(m *ice.Message) *ice.Message {
|
||||
HashSelectValue(m, func(value ice.Map) {
|
||||
if c, ok := value[TARGET].(io.Closer); ok {
|
||||
c.Close()
|
||||
}
|
||||
delete(value, TARGET)
|
||||
})
|
||||
return m
|
||||
}
|
||||
func HashSelectUpdate(m *ice.Message, key string, cb Any) *ice.Message {
|
||||
defer Lock(m, m.PrefixKey(), "")()
|
||||
Richs(m, m.PrefixKey(), nil, key, func(key string, value Map) {
|
||||
@ -290,6 +268,18 @@ func HashTarget(m *ice.Message, h string, add Any) (p Any) {
|
||||
})
|
||||
return
|
||||
}
|
||||
func HashSelectClose(m *ice.Message) *ice.Message {
|
||||
HashSelectValue(m, func(value ice.Map) {
|
||||
if c, ok := value[TARGET].(io.Closer); ok {
|
||||
c.Close()
|
||||
}
|
||||
delete(value, TARGET)
|
||||
})
|
||||
return m
|
||||
}
|
||||
func HashPrunesValue(m *ice.Message, field, value string) {
|
||||
m.Cmdy(PRUNES, m.PrefixKey(), "", HASH, field, value, ice.OptionFields(HashField(m)))
|
||||
}
|
||||
|
||||
func Richs(m *ice.Message, prefix string, chain Any, raw Any, cb Any) (res Map) {
|
||||
cache := m.Confm(prefix, chain)
|
||||
|
@ -16,10 +16,9 @@ func _list_fields(m *ice.Message) []string {
|
||||
func _list_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
||||
list := map[string]int{}
|
||||
defer func() {
|
||||
delete(list, "")
|
||||
for k, i := range list {
|
||||
if k != "" {
|
||||
m.Push(field, k).Push(COUNT, i)
|
||||
}
|
||||
m.Push(field, k).Push(COUNT, i)
|
||||
}
|
||||
m.SortIntR(COUNT)
|
||||
}()
|
||||
@ -32,11 +31,7 @@ func _list_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
||||
func _list_insert(m *ice.Message, prefix, chain string, arg ...string) {
|
||||
m.Logs(INSERT, KEY, path.Join(prefix, chain), arg[0], arg[1])
|
||||
defer Lock(m, prefix, chain)()
|
||||
if m.Optionv(TARGET) != nil && m.Option(TARGET) != "" {
|
||||
m.Echo("%d", Grow(m, prefix, chain, kit.Dict(arg, TARGET, m.Optionv(TARGET))))
|
||||
} else {
|
||||
m.Echo("%d", Grow(m, prefix, chain, kit.Dict(arg)))
|
||||
}
|
||||
m.Echo("%d", Grow(m, prefix, chain, kit.Dict(arg, TARGET, m.Optionv(TARGET))))
|
||||
}
|
||||
func _list_modify(m *ice.Message, prefix, chain string, field, value string, arg ...string) {
|
||||
m.Logs(MODIFY, KEY, path.Join(prefix, chain), field, value, arg)
|
||||
@ -44,8 +39,8 @@ func _list_modify(m *ice.Message, prefix, chain string, field, value string, arg
|
||||
Grows(m, prefix, chain, field, value, func(index int, val ice.Map) { _mdb_modify(m, val, field, arg...) })
|
||||
}
|
||||
func _list_select(m *ice.Message, prefix, chain, field, value string) {
|
||||
defer RLock(m, prefix, chain)()
|
||||
fields := _list_fields(m)
|
||||
defer RLock(m, prefix, chain)()
|
||||
Grows(m, prefix, chain, kit.Select(m.Option(CACHE_FIELD), field), kit.Select(m.Option(CACHE_VALUE), value), func(value ice.Map) {
|
||||
_mdb_select(m, m.OptionCB(""), "", value, fields, nil)
|
||||
})
|
||||
@ -117,13 +112,18 @@ func ListAction(arg ...ice.Any) ice.Actions {
|
||||
DELETE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(DELETE, m.PrefixKey(), "", LIST, m.OptionSimple(ID), arg) }},
|
||||
MODIFY: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(MODIFY, m.PrefixKey(), "", LIST, m.OptionSimple(ID), arg) }},
|
||||
SELECT: {Name: "select id auto insert", Hand: func(m *ice.Message, arg ...string) { ListSelect(m, arg...) }},
|
||||
PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPage(m, m.Config(COUNT), kit.Slice(arg, 1)...) }},
|
||||
NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPageLimit(m, m.Config(COUNT), kit.Slice(arg, 1)...) }},
|
||||
PRUNES: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(PRUNES, m.PrefixKey(), "", LIST, arg) }},
|
||||
EXPORT: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(EXPORT, m.PrefixKey(), "", LIST, arg) }},
|
||||
IMPORT: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(IMPORT, m.PrefixKey(), "", LIST, arg) }},
|
||||
}
|
||||
}
|
||||
func PageListAction(arg ...ice.Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
SELECT: {Name: "select id auto insert page", Hand: func(m *ice.Message, arg ...string) { ListSelect(m, arg...) }},
|
||||
PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPage(m, m.Config(COUNT), kit.Slice(arg, 1)...) }},
|
||||
NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPageLimit(m, m.Config(COUNT), kit.Slice(arg, 1)...) }},
|
||||
}, ListAction(arg...))
|
||||
}
|
||||
func ListField(m *ice.Message) string { return kit.Select(LIST_FIELD, m.Config(FIELD)) }
|
||||
func ListSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
OptionPage(m, kit.Slice(arg, 1)...)
|
||||
@ -152,12 +152,9 @@ func PrevPage(m *ice.Message, total string, arg ...string) {
|
||||
}
|
||||
func NextPage(m *ice.Message, total string, arg ...string) {
|
||||
limit, offend := kit.Select("10", arg, 0), kit.Select("0", arg, 1)
|
||||
offends := kit.Int(offend) + kit.Int(limit)
|
||||
if total != "0" && (offends <= -kit.Int(total) || offends >= kit.Int(total)) {
|
||||
if offends := kit.Int(offend) + kit.Int(limit); total != "0" && (offends <= -kit.Int(total) || offends >= kit.Int(total)) {
|
||||
m.ProcessHold("已经是最后一页啦!")
|
||||
return
|
||||
}
|
||||
if offends == 0 {
|
||||
} else if offends == 0 {
|
||||
m.ProcessRewrite("offend", "")
|
||||
} else {
|
||||
m.ProcessRewrite("offend", offends)
|
||||
|
@ -19,6 +19,10 @@ func _file_name(m *ice.Message, arg ...string) string {
|
||||
}
|
||||
return path.Join(ice.USR_LOCAL_EXPORT, path.Join(arg[:2]...), arg[2])
|
||||
}
|
||||
func _mdb_getmeta(m *ice.Message, prefix, chain, key string) string {
|
||||
defer RLock(m, prefix, chain)()
|
||||
return m.Conf(prefix, kit.Keys(chain, kit.Keym(key)))
|
||||
}
|
||||
func _mdb_modify(m *ice.Message, value ice.Map, field string, arg ...string) {
|
||||
value = kit.GetMeta(value)
|
||||
kit.Fetch(arg, func(k, v string) {
|
||||
@ -255,9 +259,9 @@ func AutoConfig(args ...ice.Any) *ice.Action {
|
||||
if cs := m.Target().Commands; cs[m.CommandKey()] == nil {
|
||||
return
|
||||
} else if inputs := []ice.Any{}; cs[m.CommandKey()].Actions[INSERT] != nil {
|
||||
kit.Fetch(kit.Filters(kit.Split(ListField(m)), TIME, ID), func(k string) { inputs = append(inputs, k) })
|
||||
kit.Fetch(kit.Filters(kit.Simple(m.Config(SHORT), kit.Split(ListField(m))), "", TIME, ID), func(k string) { inputs = append(inputs, k) })
|
||||
if cs[m.CommandKey()].Meta[INSERT] == nil {
|
||||
m.Design(INSERT, "添加", append(kit.List(kit.Select(ZONE, m.Config(SHORT))), inputs...)...)
|
||||
m.Design(INSERT, "添加", inputs...)
|
||||
}
|
||||
} else if cs[m.CommandKey()].Actions[CREATE] != nil {
|
||||
kit.Fetch(kit.Filters(kit.Split(HashField(m)), TIME, HASH), func(k string) { inputs = append(inputs, k) })
|
||||
|
@ -14,7 +14,7 @@ func _zone_fields(m *ice.Message) []string {
|
||||
return kit.Split(kit.Select(ZONE_FIELD, m.OptionFields()))
|
||||
}
|
||||
func _zone_inputs(m *ice.Message, prefix, chain, zone string, field, value string) {
|
||||
if field == m.Conf(prefix, kit.Keys(chain, kit.Keym(SHORT))) {
|
||||
if field == _mdb_getmeta(m, prefix, chain, SHORT) {
|
||||
_hash_inputs(m, prefix, chain, field, value)
|
||||
return
|
||||
}
|
||||
@ -25,7 +25,7 @@ func _zone_inputs(m *ice.Message, prefix, chain, zone string, field, value strin
|
||||
func _zone_insert(m *ice.Message, prefix, chain, zone string, arg ...string) {
|
||||
h := _hash_select_field(m, prefix, chain, zone, HASH)
|
||||
if h == "" {
|
||||
h = _hash_insert(m, prefix, chain, m.Conf(prefix, kit.Keys(chain, kit.Keym(SHORT))), zone)
|
||||
h = _hash_insert(m, prefix, chain, _mdb_getmeta(m, prefix, chain, SHORT), zone)
|
||||
}
|
||||
m.Assert(h != "")
|
||||
defer Lock(m, prefix, chain)()
|
||||
@ -59,6 +59,7 @@ func _zone_export(m *ice.Message, prefix, chain, file string) {
|
||||
f, p, e := miss.CreateFile(kit.Keys(file, CSV))
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
m.Echo(p)
|
||||
w := csv.NewWriter(f)
|
||||
defer w.Flush()
|
||||
fields := _zone_fields(m)
|
||||
@ -66,14 +67,11 @@ func _zone_export(m *ice.Message, prefix, chain, file string) {
|
||||
fields = append(fields, EXTRA)
|
||||
}
|
||||
w.Write(fields)
|
||||
defer Lock(m, prefix, chain)()
|
||||
keys := []string{}
|
||||
func() {
|
||||
defer RLock(m, prefix, chain)()
|
||||
Richs(m, prefix, chain, FOREACH, func(key string, val ice.Map) { keys = append(keys, key) })
|
||||
}()
|
||||
Richs(m, prefix, chain, FOREACH, func(key string, val ice.Map) { keys = append(keys, key) })
|
||||
kit.Sort(keys)
|
||||
count := 0
|
||||
defer Lock(m, prefix, chain)()
|
||||
for _, key := range keys {
|
||||
Richs(m, prefix, chain, key, func(key string, val ice.Map) {
|
||||
val = kit.GetMeta(val)
|
||||
@ -92,7 +90,6 @@ func _zone_export(m *ice.Message, prefix, chain, file string) {
|
||||
}
|
||||
m.Logs(EXPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, count)
|
||||
m.Conf(prefix, kit.Keys(chain, HASH), "")
|
||||
m.Echo(p).StatusTime(LINK, "/share/local/"+p)
|
||||
}
|
||||
func _zone_import(m *ice.Message, prefix, chain, file string) {
|
||||
f, e := miss.OpenFile(kit.Keys(file, CSV))
|
||||
@ -100,10 +97,10 @@ func _zone_import(m *ice.Message, prefix, chain, file string) {
|
||||
defer f.Close()
|
||||
r := csv.NewReader(f)
|
||||
head, _ := r.Read()
|
||||
count := 0
|
||||
list := ice.Maps{}
|
||||
zkey := kit.Select(head[0], m.OptionFields())
|
||||
defer Lock(m, prefix, chain)()
|
||||
list := ice.Maps{}
|
||||
count := 0
|
||||
for {
|
||||
line, e := r.Read()
|
||||
if e != nil {
|
||||
@ -133,7 +130,7 @@ func _zone_import(m *ice.Message, prefix, chain, file string) {
|
||||
}()
|
||||
count++
|
||||
}
|
||||
m.Logs(IMPORT, KEY, path.Join(prefix, chain), COUNT, count)
|
||||
m.Logs(IMPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, count)
|
||||
m.Echo("%d", count)
|
||||
}
|
||||
|
||||
@ -145,7 +142,7 @@ const ZONE = "zone"
|
||||
func ZoneAction(args ...ice.Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: AutoConfig(append([]ice.Any{SHORT, ZONE}, args)...),
|
||||
INPUTS: {Hand: func(m *ice.Message, arg ...string) { ZoneInputs(m, arg) }},
|
||||
CREATE: {Name: "create zone", Hand: func(m *ice.Message, arg ...string) { ZoneCreate(m, arg) }},
|
||||
CREATE: {Hand: func(m *ice.Message, arg ...string) { ZoneCreate(m, arg) }},
|
||||
REMOVE: {Hand: func(m *ice.Message, arg ...string) { ZoneRemove(m, arg) }},
|
||||
INSERT: {Hand: func(m *ice.Message, arg ...string) { ZoneInsert(m, arg) }},
|
||||
MODIFY: {Hand: func(m *ice.Message, arg ...string) { ZoneModify(m, arg) }},
|
||||
|
@ -72,6 +72,6 @@ func init() {
|
||||
DIAL: {Name: "dial type name port=9010 host=", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
|
||||
_client_dial(m, arg...)
|
||||
}},
|
||||
}, mdb.HashStatusAction(mdb.FIELD, "time,hash,status,type,name,host,port,error,nread,nwrite"))},
|
||||
}, mdb.StatusHashAction(mdb.FIELD, "time,hash,status,type,name,host,port,error,nread,nwrite"))},
|
||||
})
|
||||
}
|
||||
|
@ -68,6 +68,6 @@ func init() {
|
||||
LISTEN: {Name: "listen type name port=9030 host=", Help: "监听", Hand: func(m *ice.Message, arg ...string) {
|
||||
_server_listen(m, arg...)
|
||||
}},
|
||||
}, mdb.HashStatusCloseAction(mdb.FIELD, "time,hash,status,type,name,host,port,error,nconn"))},
|
||||
}, mdb.StatusHashAction(mdb.FIELD, "time,hash,status,type,name,host,port,error,nconn"))},
|
||||
})
|
||||
}
|
||||
|
@ -78,6 +78,6 @@ func init() {
|
||||
kit.Format("http://%s:%s", m.Option(tcp.HOST), m.Option(tcp.PORT)))
|
||||
m.Cmd(SPACE, tcp.DIAL, m.OptionSimple(ice.DEV))
|
||||
}},
|
||||
}, mdb.HashCloseAction(mdb.SHORT, "host,port", mdb.FIELD, "time,hash,host,port", mdb.ACTION, SPACE))},
|
||||
}, mdb.HashAction(mdb.SHORT, "host,port", mdb.FIELD, "time,hash,host,port", mdb.ACTION, SPACE))},
|
||||
})
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ func init() {
|
||||
}
|
||||
}},
|
||||
DOMAIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_space_domain(m)) }},
|
||||
}, mdb.HashCloseAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text",
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text",
|
||||
REDIAL, kit.Dict("a", 3000, "b", 1000, "c", 1000), TIMEOUT, kit.Dict("c", "180s"),
|
||||
BUFFER, kit.Dict("r", ice.MOD_BUFS, "w", ice.MOD_BUFS),
|
||||
), ctx.CmdAction(), DreamAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -9,7 +9,9 @@ import (
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
"demo-hash": {Actions: ice.MergeActions(mdb.HashAction(), ctx.CmdAction())},
|
||||
"demo-status-hash": {Actions: ice.MergeActions(mdb.StatusHashAction(), ctx.CmdAction())},
|
||||
"demo-list": {Actions: ice.MergeActions(mdb.ListAction(), ctx.CmdAction())},
|
||||
"demo-page-list": {Actions: ice.MergeActions(mdb.PageListAction(), ctx.CmdAction())},
|
||||
"demo-zone": {Actions: ice.MergeActions(mdb.ZoneAction(), ctx.CmdAction())},
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user