1
0
forked from x/icebergs
This commit is contained in:
harveyshao 2021-07-12 10:35:47 +08:00
parent c5b79bbac9
commit c9dfef8c55
9 changed files with 42 additions and 23 deletions

View File

@ -71,6 +71,7 @@ const (
DIR = "dir"
ENV = "env"
CMD = "cmd"
API = "api"
ARG = "arg"
RUN = "run"
RES = "res"
@ -80,6 +81,7 @@ const (
ERROR = "error"
BUILD = "build"
SPAWN = "spawn"
CHECK = "check"
BENCH = "bench"
PPROF = "pprof"

View File

@ -352,7 +352,7 @@ func _zone_import(m *ice.Message, prefix, chain, file string) {
count := 0
list := map[string]string{}
zkey := m.Option(FIELDS)
zkey := kit.Select(head[0], m.Option(FIELDS))
for {
line, e := r.Read()

View File

@ -59,7 +59,8 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
default:
for _, k := range []string{
"_option", "_handle", "_output", "",
"sessid", "domain", "river", "storm", "cmds", "fields",
"cmds", "fields", "sessid", "domain",
"river", "storm",
} {
msg.Set(k)
}

View File

@ -128,6 +128,9 @@ func _spide_body(m *ice.Message, method string, arg ...string) (io.Reader, map[s
body, head[ContentType] = _spide_part(m, arg...)
case SPIDE_DATA:
if len(arg) == 1 {
arg = append(arg, "{}")
}
body, arg = bytes.NewBufferString(arg[1]), arg[2:]
case SPIDE_FILE:

View File

@ -91,6 +91,7 @@ const ( // MSG
MSG_PROCESS = "_process"
MSG_CMDS = "cmds"
MSG_FIELDS = "fields"
MSG_SESSID = "sessid"
MSG_DOMAIN = "domain"
MSG_OPTS = "_option"

View File

@ -53,7 +53,7 @@ func init() {
m.Cmdy(mdb.INPUTS, m.Prefix(TARGET), "", mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option("fields", "time,hash,type,name,text")
m.Fields(len(arg) == 0, "time,hash,type,name,text")
m.Cmdy(mdb.SELECT, m.Prefix(TARGET), "", mdb.HASH, "", kit.Select(kit.MDB_FOREACH, arg, 0))
if len(arg) == 0 {
m.PushAction("备课", "学习", "测试", "删除")

View File

@ -114,7 +114,7 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa
}
default:
if m.Option("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.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 key != kit.MDB_KEY || key != kit.MDB_VALUE {
m.Add(MSG_APPEND, kit.MDB_KEY, key)
m.Add(MSG_APPEND, kit.MDB_VALUE, kit.Format(value))
@ -184,6 +184,9 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message {
return m
}
func (m *Message) Sort(key string, arg ...string) *Message {
if m.Option(MSG_FIELDS) == "detail" {
return m
}
// 排序方法
cmp := "str"
if len(arg) > 0 && arg[0] != "" {
@ -465,7 +468,7 @@ func (m *Message) Optionv(key string, arg ...interface{}) interface{} {
default:
m.data[key] = str
}
if key == "fields" {
if key == MSG_FIELDS {
for _, k := range kit.Split(strings.Join(m.meta[key], ",")) {
delete(m.meta, k)
}

13
misc.go
View File

@ -15,6 +15,9 @@ import (
func (m *Message) Prefix(arg ...string) string {
return kit.Keys(m.Cap(CTX_FOLLOW), arg)
}
func (m *Message) PrefixKey(arg ...string) string {
return kit.Keys(m.Cap(CTX_FOLLOW), m._key, arg)
}
func (m *Message) Save(arg ...string) *Message {
if len(arg) == 0 {
for k := range m.target.Configs {
@ -85,7 +88,7 @@ func (m *Message) PushPodCmd(cmd string, arg ...string) {
}
func (m *Message) PushSearch(args ...interface{}) {
data := kit.Dict(args...)
for _, k := range kit.Split(m.Option("fields")) {
for _, k := range kit.Split(m.Option(MSG_FIELDS)) {
switch k {
case kit.SSH_POD:
// m.Push(k, kit.Select(m.Option(MSG_USERPOD), data[kit.SSH_POD]))
@ -102,7 +105,7 @@ func (m *Message) PushSearch(args ...interface{}) {
}
func (m *Message) PushSearchWeb(cmd string, name string) {
msg := m.Spawn()
msg.Option("fields", "type,name,text")
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] == "" {
@ -264,7 +267,7 @@ type Option struct {
Value interface{}
}
func OptionFields(str string) Option { return Option{"fields", str} }
func OptionFields(str string) Option { return Option{MSG_FIELDS, str} }
func OptionHash(str string) Option { return Option{kit.MDB_HASH, str} }
type Sort struct {
@ -302,7 +305,7 @@ func (m *Message) GoToast(title string, cb func(toast func(string, int, int))) {
}
func (m *Message) Fields(condition bool, fields string) string {
return m.Option("fields", kit.Select(kit.Select("detail", fields, condition), m.Option("fields")))
return m.Option(MSG_FIELDS, kit.Select(kit.Select("detail", fields, condition), m.Option(MSG_FIELDS)))
}
func (m *Message) Action(arg ...string) {
m.Option(MSG_ACTION, kit.Format(arg))
@ -362,7 +365,7 @@ func (m *Message) Upload(dir string) {
}
}
func (m *Message) OptionFields(str string) { m.Option("fields", str) }
func (m *Message) OptionFields(str string) { m.Option(MSG_FIELDS, str) }
func (m *Message) OptionLoad(file string) *Message {
if f, e := os.Open(file); e == nil {
defer f.Close()

32
type.go
View File

@ -111,7 +111,7 @@ func (c *Context) _hand(m *Message, cmd *Command, key string, k string, h *Actio
return m
}
func (c *Context) cmd(m *Message, cmd *Command, key string, arg ...string) *Message {
if m._cmd = cmd; cmd == nil {
if m._key, m._cmd = key, cmd; cmd == nil {
return m
}
@ -182,7 +182,7 @@ func (c *Context) Merge(s *Context) *Context {
c.Commands[k] = v
if v.List == nil {
v.List = c._split(v.Name)
v.List = c._split(k, v, v.Name)
}
if v.Meta == nil {
v.Meta = kit.Dict()
@ -203,7 +203,7 @@ func (c *Context) Merge(s *Context) *Context {
continue
}
if a.List == nil {
a.List = c._split(a.Name)
a.List = c._split(k, nil, a.Name)
}
if len(a.List) > 0 {
v.Meta[k] = a.List
@ -226,17 +226,17 @@ func (c *Context) Merge(s *Context) *Context {
}
return c
}
func (c *Context) _split(name string) []interface{} {
func (c *Context) _split(key string, cmd *Command, name string) []interface{} {
button, list := false, []interface{}{}
for _, v := range kit.Split(kit.Select("key", name), " ", " ")[1:] {
if v == "page" {
switch v {
case "page":
list = append(list, kit.List(kit.MDB_INPUT, "text", "name", "limit")...)
list = append(list, kit.List(kit.MDB_INPUT, "text", "name", "offend")...)
list = append(list, kit.List(kit.MDB_INPUT, "button", "name", "prev")...)
list = append(list, kit.List(kit.MDB_INPUT, "button", "name", "next")...)
continue
}
if v == "auto" {
case "auto":
list = append(list, kit.List(kit.MDB_INPUT, "button", "name", "查看", "value", "auto")...)
list = append(list, kit.List(kit.MDB_INPUT, "button", "name", "返回")...)
button = true
@ -342,6 +342,7 @@ type Message struct {
time time.Time
code int
Hand bool
wait chan bool
meta map[string][]string
data map[string]interface{}
@ -352,13 +353,13 @@ type Message struct {
source *Context
target *Context
_cmd *Command
_key string
cb func(*Message) *Message
W http.ResponseWriter
R *http.Request
O io.Writer
I io.Reader
wait chan bool
cb func(*Message) *Message
W http.ResponseWriter
R *http.Request
O io.Writer
I io.Reader
}
func (m *Message) Time(args ...interface{}) string {
@ -684,6 +685,11 @@ func (m *Message) cmd(arg ...interface{}) *Message {
case func(int, map[string]string, []string):
defer func() { m.Table(val) }()
case map[string]string:
for k, v := range val {
opts[k] = v
}
case *Option:
opts[val.Name] = val.Value
case Option: