forked from x/icebergs
opt some
This commit is contained in:
parent
7b1103fc85
commit
7c53a6df44
@ -54,6 +54,21 @@ func _favor_insert(m *ice.Message, favor, kind, name, text string, extra ...stri
|
|||||||
m.Log_INSERT("favor", favor, "index", index, "name", name, "text", text)
|
m.Log_INSERT("favor", favor, "index", index, "name", name, "text", text)
|
||||||
m.Echo("%d", index)
|
m.Echo("%d", index)
|
||||||
}
|
}
|
||||||
|
func _favor_modify(m *ice.Message, favor, id, pro, set, old string) {
|
||||||
|
m.Richs(FAVOR, nil, favor, func(key string, val map[string]interface{}) {
|
||||||
|
switch pro {
|
||||||
|
case FAVOR, kit.MDB_ID, kit.MDB_TIME:
|
||||||
|
m.Warn(true, "deny modify %v", pro)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
||||||
|
// 修改信息
|
||||||
|
m.Log_MODIFY(FAVOR, favor, kit.MDB_ID, id, kit.MDB_KEY, pro, kit.MDB_VALUE, set, "old", old)
|
||||||
|
kit.Value(value, pro, set)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func FavorInsert(m *ice.Message, favor, kind, name, text string, extra ...string) {
|
func FavorInsert(m *ice.Message, favor, kind, name, text string, extra ...string) {
|
||||||
_favor_insert(m, favor, kind, name, text, extra...)
|
_favor_insert(m, favor, kind, name, text, extra...)
|
||||||
@ -73,7 +88,11 @@ func init() {
|
|||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.WEB_FAVOR: {Name: "favor favor=auto id=auto auto", Help: "收藏夹", Meta: kit.Dict(
|
ice.WEB_FAVOR: {Name: "favor favor=auto id=auto auto", Help: "收藏夹", Meta: kit.Dict(
|
||||||
"exports", []string{"hot", "favor"}, "detail", []string{"编辑", "收藏", "收录", "导出", "删除"},
|
"exports", []string{"hot", "favor"}, "detail", []string{"编辑", "收藏", "收录", "导出", "删除"},
|
||||||
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
), Action: map[string]*ice.Action{
|
||||||
|
kit.MDB_MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_favor_modify(m, m.Option(FAVOR), m.Option(kit.MDB_ID), arg[0], arg[1], kit.Select("", arg, 2))
|
||||||
|
}},
|
||||||
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) > 1 && arg[0] == "action" {
|
if len(arg) > 1 && arg[0] == "action" {
|
||||||
favor, id := m.Option("favor"), m.Option("id")
|
favor, id := m.Option("favor"), m.Option("id")
|
||||||
switch arg[2] {
|
switch arg[2] {
|
||||||
@ -84,20 +103,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch arg[1] {
|
switch arg[1] {
|
||||||
case "modify", "编辑":
|
|
||||||
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, value map[string]interface{}) {
|
|
||||||
if id == "" {
|
|
||||||
m.Log(ice.LOG_MODIFY, "favor: %s value: %v->%v", key, kit.Value(value, kit.Keys("meta", arg[2])), arg[3])
|
|
||||||
m.Echo("%s->%s", kit.Value(value, kit.Keys("meta", arg[2])), arg[3])
|
|
||||||
kit.Value(value, kit.Keys("meta", arg[2]), arg[3])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "id", id, func(index int, value map[string]interface{}) {
|
|
||||||
m.Log(ice.LOG_MODIFY, "favor: %s index: %d value: %v->%v", key, index, value[arg[2]], arg[3])
|
|
||||||
m.Echo("%s->%s", value[arg[2]], arg[3])
|
|
||||||
kit.Value(value, arg[2], arg[3])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
case "commit", "收录":
|
case "commit", "收录":
|
||||||
m.Echo("list: ")
|
m.Echo("list: ")
|
||||||
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, value map[string]interface{}) {
|
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, value map[string]interface{}) {
|
||||||
@ -114,10 +119,6 @@ func init() {
|
|||||||
m.Cmdy(ice.MDB_EXPORT, ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_LIST, favor)
|
m.Cmdy(ice.MDB_EXPORT, ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_LIST, favor)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case "delete", "删除":
|
|
||||||
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, value map[string]interface{}) {
|
|
||||||
m.Cmdy(ice.MDB_DELETE, ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_DICT)
|
|
||||||
})
|
|
||||||
case "import", "导入":
|
case "import", "导入":
|
||||||
if favor == "" {
|
if favor == "" {
|
||||||
m.Cmdy(ice.MDB_IMPORT, ice.WEB_FAVOR, kit.MDB_HASH, kit.MDB_HASH, "favor")
|
m.Cmdy(ice.MDB_IMPORT, ice.WEB_FAVOR, kit.MDB_HASH, kit.MDB_HASH, "favor")
|
||||||
@ -231,6 +232,7 @@ func init() {
|
|||||||
arg = append(arg, "")
|
arg = append(arg, "")
|
||||||
}
|
}
|
||||||
_favor_insert(m, favor, arg[1], arg[2], arg[3], arg[4:]...)
|
_favor_insert(m, favor, arg[1], arg[2], arg[3], arg[4:]...)
|
||||||
|
return
|
||||||
|
|
||||||
// 分发数据
|
// 分发数据
|
||||||
if p := kit.Select(m.Conf(ice.WEB_FAVOR, "meta.proxy"), m.Option("you")); p != "" {
|
if p := kit.Select(m.Conf(ice.WEB_FAVOR, "meta.proxy"), m.Option("you")); p != "" {
|
||||||
|
@ -20,25 +20,32 @@ const (
|
|||||||
|
|
||||||
func _bench_list(m *ice.Message, zone string, id string, field ...interface{}) {
|
func _bench_list(m *ice.Message, zone string, id string, field ...interface{}) {
|
||||||
m.Richs(BENCH, nil, kit.Select(kit.MDB_FOREACH, zone), func(key string, val map[string]interface{}) {
|
m.Richs(BENCH, nil, kit.Select(kit.MDB_FOREACH, zone), func(key string, val map[string]interface{}) {
|
||||||
if zone = kit.Format(kit.Value(val, "meta.zone")); id == "" {
|
val = val[kit.MDB_META].(map[string]interface{})
|
||||||
|
if zone = kit.Format(kit.Value(val, kit.MDB_ZONE)); id == "" {
|
||||||
m.Grows(BENCH, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
m.Grows(BENCH, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||||
m.Push(kit.MDB_ZONE, zone)
|
// 查看信息
|
||||||
m.Push("操作", `<input type="button" value="运行">`)
|
m.Push("操作", `<input type="button" value="运行">`)
|
||||||
m.Push(zone, value, field...)
|
m.Push(zone, value, []string{
|
||||||
|
kit.MDB_ZONE, kit.MDB_ID, kit.MDB_TYPE,
|
||||||
|
kit.MDB_NAME, NCONN, NREQS, kit.MDB_TEXT,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.Grows(BENCH, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
m.Grows(BENCH, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
||||||
|
// 查看信息
|
||||||
m.Push("detail", value)
|
m.Push("detail", value)
|
||||||
|
m.Push(kit.MDB_KEY, "操作")
|
||||||
|
m.Push(kit.MDB_VALUE, `<input type="button" value="运行">`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func _bench_show(m *ice.Message, nconn, nreq int64, list []*http.Request) {
|
func _bench_show(m *ice.Message, nconn, nreq int64, list []*http.Request) {
|
||||||
m.Info(NCONN, nconn, NREQS, nreq)
|
nout, e := os.OpenFile("/dev/null", os.O_WRONLY, 0660)
|
||||||
nout, e := os.OpenFile("/dev/null", os.O_WRONLY, 0777)
|
|
||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
|
|
||||||
var body int64
|
var body int64
|
||||||
|
m.Logs(NCONN, nconn, NREQS, nreq)
|
||||||
s, e := bench.HTTP(nconn, nreq, list, func(req *http.Request, res *http.Response) {
|
s, e := bench.HTTP(nconn, nreq, list, func(req *http.Request, res *http.Response) {
|
||||||
n, _ := io.Copy(nout, res.Body)
|
n, _ := io.Copy(nout, res.Body)
|
||||||
atomic.AddInt64(&body, n)
|
atomic.AddInt64(&body, n)
|
||||||
@ -48,16 +55,26 @@ func _bench_show(m *ice.Message, nconn, nreq int64, list []*http.Request) {
|
|||||||
m.Echo(s.Show())
|
m.Echo(s.Show())
|
||||||
m.Echo("body: %d\n", body)
|
m.Echo("body: %d\n", body)
|
||||||
}
|
}
|
||||||
func _bench_create(m *ice.Message, zone string, arg ...string) {
|
func _bench_modify(m *ice.Message, zone, id, pro, set, old string) {
|
||||||
if m.Richs(BENCH, nil, zone, nil) == nil {
|
m.Richs(BENCH, nil, zone, func(key string, val map[string]interface{}) {
|
||||||
m.Rich(BENCH, nil, kit.Data(kit.MDB_ZONE, zone, arg))
|
switch pro {
|
||||||
m.Log_CREATE(kit.MDB_ZONE, zone)
|
case kit.MDB_ZONE, kit.MDB_ID, kit.MDB_TIME:
|
||||||
}
|
m.Warn(true, "deny modify %v", pro)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Grows(BENCH, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
||||||
|
// 修改信息
|
||||||
|
m.Log_MODIFY(kit.MDB_ZONE, zone, kit.MDB_ID, id, kit.MDB_KEY, pro, kit.MDB_VALUE, set, "old", old)
|
||||||
|
kit.Value(value, pro, set)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
func _bench_insert(m *ice.Message, zone, kind, name, text string, nconn, nreqs string, arg ...string) {
|
func _bench_insert(m *ice.Message, zone, kind, name, text string, nconn, nreqs string, arg ...string) {
|
||||||
m.Richs(BENCH, nil, zone, func(key string, value map[string]interface{}) {
|
m.Richs(BENCH, nil, zone, func(key string, value map[string]interface{}) {
|
||||||
id := m.Grow(BENCH, kit.Keys(kit.MDB_HASH, key), kit.Dict(
|
id := m.Grow(BENCH, kit.Keys(kit.MDB_HASH, key), kit.Dict(
|
||||||
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
||||||
|
// 添加信息
|
||||||
NCONN, nconn, NREQS, nreqs,
|
NCONN, nconn, NREQS, nreqs,
|
||||||
kit.MDB_EXTRA, kit.Dict(arg),
|
kit.MDB_EXTRA, kit.Dict(arg),
|
||||||
))
|
))
|
||||||
@ -65,18 +82,13 @@ func _bench_insert(m *ice.Message, zone, kind, name, text string, nconn, nreqs s
|
|||||||
m.Echo("%d", id)
|
m.Echo("%d", id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func _bench_modify(m *ice.Message, zone, id, pro, set, old string) {
|
func _bench_create(m *ice.Message, zone string, arg ...string) {
|
||||||
m.Richs(BENCH, nil, kit.Select(kit.MDB_FOREACH, zone), func(key string, val map[string]interface{}) {
|
if m.Richs(BENCH, nil, zone, nil) == nil {
|
||||||
m.Grows(BENCH, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
m.Rich(BENCH, nil, kit.Data(kit.MDB_ZONE, zone,
|
||||||
switch pro {
|
// 添加信息
|
||||||
case kit.MDB_ZONE, kit.MDB_ID, kit.MDB_TIME:
|
arg))
|
||||||
m.Info("not allow %v", key)
|
m.Log_CREATE(kit.MDB_ZONE, zone)
|
||||||
default:
|
}
|
||||||
m.Log_MODIFY(kit.MDB_ZONE, zone, kit.MDB_ID, id, kit.MDB_KEY, pro, kit.MDB_VALUE, set, "old", old)
|
|
||||||
kit.Value(value, pro, set)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -86,7 +98,26 @@ func init() {
|
|||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
BENCH: {Name: "bench zone=auto id=auto auto", Help: "性能压测", Action: map[string]*ice.Action{
|
BENCH: {Name: "bench zone=auto id=auto auto", Help: "性能压测", Action: map[string]*ice.Action{
|
||||||
|
kit.MDB_CREATE: {Name: "create zone", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_bench_create(m, arg[0])
|
||||||
|
}},
|
||||||
|
kit.MDB_INSERT: {Name: "insert zone type name text nconn nreqs", Help: "插入", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_bench_insert(m, arg[0], arg[1], arg[2],
|
||||||
|
kit.Select("http://localhost:9020/code/bench?cmd="+arg[2], arg, 3),
|
||||||
|
kit.Select("3", arg, 4), kit.Select("10", arg, 5))
|
||||||
|
}},
|
||||||
|
kit.MDB_MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_bench_modify(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg[0], arg[1], kit.Select("", arg, 2))
|
||||||
|
}},
|
||||||
kit.MDB_SHOW: {Name: "show", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
kit.MDB_SHOW: {Name: "show", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Richs(BENCH, nil, m.Option(kit.MDB_ZONE), func(key string, val map[string]interface{}) {
|
||||||
|
m.Grows(BENCH, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, m.Option(kit.MDB_ID), func(index int, value map[string]interface{}) {
|
||||||
|
m.Option(kit.MDB_TEXT, value[kit.MDB_TEXT])
|
||||||
|
m.Option(NCONN, value[NCONN])
|
||||||
|
m.Option(NREQS, value[NREQS])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
list := []*http.Request{}
|
list := []*http.Request{}
|
||||||
target := kit.Select(m.Option(kit.MDB_TEXT))
|
target := kit.Select(m.Option(kit.MDB_TEXT))
|
||||||
for _, v := range strings.Split(target, ",") {
|
for _, v := range strings.Split(target, ",") {
|
||||||
@ -108,17 +139,6 @@ func init() {
|
|||||||
m.Echo("%s \n", target)
|
m.Echo("%s \n", target)
|
||||||
_bench_show(m, kit.Int64(kit.Select(m.Option(NCONN))), kit.Int64(kit.Select(m.Option(NREQS))), list)
|
_bench_show(m, kit.Int64(kit.Select(m.Option(NCONN))), kit.Int64(kit.Select(m.Option(NREQS))), list)
|
||||||
}},
|
}},
|
||||||
kit.MDB_MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_bench_modify(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg[0], arg[1], "")
|
|
||||||
}},
|
|
||||||
kit.MDB_INSERT: {Name: "insert zone type name text nconn nreqs", Help: "插入", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_bench_insert(m, arg[0], arg[1], arg[2],
|
|
||||||
kit.Select("http://localhost:9020/code/bench?cmd="+arg[2], arg, 3),
|
|
||||||
kit.Select("3", arg, 4), kit.Select("10", arg, 5))
|
|
||||||
}},
|
|
||||||
kit.MDB_CREATE: {Name: "create zone", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_bench_create(m, arg[0])
|
|
||||||
}},
|
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
_bench_list(m, kit.Select(kit.MDB_FOREACH, arg, 0), kit.Select("", arg, 1))
|
_bench_list(m, kit.Select(kit.MDB_FOREACH, arg, 0), kit.Select("", arg, 1))
|
||||||
}},
|
}},
|
||||||
|
@ -22,18 +22,19 @@ func _pprof_list(m *ice.Message, zone string, id string, field ...interface{}) {
|
|||||||
if zone = kit.Format(kit.Value(val, kit.MDB_ZONE)); id == "" {
|
if zone = kit.Format(kit.Value(val, kit.MDB_ZONE)); id == "" {
|
||||||
m.Grows(PPROF, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
m.Grows(PPROF, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||||
// 查看信息
|
// 查看信息
|
||||||
m.Push(kit.MDB_ZONE, zone)
|
|
||||||
m.Push(BINNARY, val[BINNARY])
|
|
||||||
m.Push(SERVICE, val[SERVICE])
|
|
||||||
m.Push(SECONDS, val[SECONDS])
|
|
||||||
m.Push("操作", `<input type="button" value="运行">`)
|
m.Push("操作", `<input type="button" value="运行">`)
|
||||||
m.Push(zone, value, []string{kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT})
|
m.Push(zone, value, []string{
|
||||||
|
kit.MDB_ZONE, kit.MDB_ID, kit.MDB_TYPE,
|
||||||
|
kit.MDB_NAME, kit.MDB_TEXT, SECONDS, BINNARY, SERVICE,
|
||||||
|
}, val)
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.Grows(PPROF, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
m.Grows(PPROF, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
||||||
// 查看信息
|
// 查看信息
|
||||||
m.Push("detail", value)
|
m.Push("detail", value)
|
||||||
|
m.Push(kit.MDB_KEY, "操作")
|
||||||
|
m.Push(kit.MDB_VALUE, `<input type="button" value="运行">`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
36
meta.go
36
meta.go
@ -52,7 +52,6 @@ func (m *Message) Set(key string, arg ...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:
|
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
if key == "detail" {
|
if key == "detail" {
|
||||||
// 格式转换
|
// 格式转换
|
||||||
@ -70,18 +69,35 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa
|
|||||||
sort.Strings(list)
|
sort.Strings(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 追加数据
|
var val map[string]interface{}
|
||||||
|
if len(arg) > 1 {
|
||||||
|
val, _ = arg[1].(map[string]interface{})
|
||||||
|
}
|
||||||
|
|
||||||
for _, k := range list {
|
for _, k := range list {
|
||||||
switch key {
|
// 查找数据
|
||||||
case "detail":
|
var v interface{}
|
||||||
m.Add(MSG_APPEND, "key", k)
|
switch k {
|
||||||
m.Add(MSG_APPEND, "value", kit.Format(value[k]))
|
case kit.MDB_KEY, kit.MDB_ZONE:
|
||||||
|
v = key
|
||||||
default:
|
default:
|
||||||
if k == "key" {
|
if v = kit.Value(value, k); v == nil {
|
||||||
m.Add(MSG_APPEND, k, key)
|
v = kit.Value(value, kit.Keys(kit.MDB_EXTRA, k))
|
||||||
} else {
|
|
||||||
m.Add(MSG_APPEND, k, kit.Format(kit.Value(value, k)))
|
|
||||||
}
|
}
|
||||||
|
if v == nil && val != nil {
|
||||||
|
if v = kit.Value(val, k); v == nil {
|
||||||
|
v = kit.Value(val, kit.Keys(kit.MDB_EXTRA, k))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 追加数据
|
||||||
|
switch v := kit.Format(v); key {
|
||||||
|
case "detail":
|
||||||
|
m.Add(MSG_APPEND, kit.MDB_KEY, k)
|
||||||
|
m.Add(MSG_APPEND, kit.MDB_VALUE, v)
|
||||||
|
default:
|
||||||
|
m.Add(MSG_APPEND, k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
|
Loading…
x
Reference in New Issue
Block a user