1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2022-01-09 13:41:40 +08:00
parent a2219676ff
commit 1fff54b9bb
25 changed files with 190 additions and 151 deletions

View File

@ -38,7 +38,7 @@ func _daemon_exec(m *ice.Message, cmd *exec.Cmd) {
m.Cmd(mdb.MODIFY, DAEMON, "", mdb.HASH, mdb.HASH, h, STATUS, ERROR, ERROR, e)
}
} else {
m.Cost(kit.MDB_CODE, cmd.ProcessState.ExitCode(), ctx.ARGS, cmd.Args)
m.Cost(CODE, cmd.ProcessState.ExitCode(), ctx.ARGS, cmd.Args)
m.Cmd(mdb.MODIFY, DAEMON, "", mdb.HASH, mdb.HASH, h, STATUS, STOP)
}
@ -85,6 +85,8 @@ const (
RESTART = "restart"
RELOAD = "reload"
STOP = "stop"
CODE = "code"
BACK = "back"
OPEN = "open"
CLOSE = "close"

View File

@ -143,7 +143,7 @@ func init() {
m.Option(FG, kit.Select(BLUE, arg, 1))
if m.IsCliUA() {
_qrcode_cli(m, kit.Select(m.Conf("share", kit.Keym(kit.MDB_DOMAIN)), arg, 0))
_qrcode_cli(m, kit.Select(m.Conf("share", kit.Keym("domain")), arg, 0))
} else {
_qrcode_web(m, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))
}

View File

@ -70,14 +70,14 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
// 执行命令
if e := cmd.Run(); !m.Warn(e, ice.ErrNotFound, cmd.Args) {
m.Cost(kit.MDB_CODE, cmd.ProcessState.ExitCode(), ctx.ARGS, cmd.Args)
m.Cost(CODE, cmd.ProcessState.ExitCode(), ctx.ARGS, cmd.Args)
}
m.Push(mdb.TIME, m.Time())
m.Push(kit.MDB_CODE, int(cmd.ProcessState.ExitCode()))
m.Push(CODE, int(cmd.ProcessState.ExitCode()))
}
func IsSuccess(m *ice.Message) bool {
return m.Append(kit.MDB_CODE) == "0" || m.Append(kit.MDB_CODE) == ""
return m.Append(CODE) == "0" || m.Append(CODE) == ""
}
const (

View File

@ -55,6 +55,7 @@ const (
INDEX = kit.MDB_INDEX
VALUE = kit.MDB_VALUE
EXTRA = kit.MDB_EXTRA
ALIAS = kit.MDB_ALIAS
EXPIRE = kit.MDB_EXPIRE
STATUS = kit.MDB_STATUS
STREAM = kit.MDB_STREAM

View File

@ -137,7 +137,7 @@ func ZoneAction(args ...interface{}) map[string]*ice.Action {
}},
INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
arg[0] = strings.TrimPrefix(arg[0], "extra.")
arg[0] = kit.Select(arg[0], m.Config(kit.Keys(kit.MDB_ALIAS, arg[0])))
arg[0] = kit.Select(arg[0], m.Config(kit.Keys(ALIAS, arg[0])))
switch arg[0] {
case ice.POD:
m.Cmdy("route")

View File

@ -124,6 +124,16 @@ const (
BRANCH = "branch"
REPOS = "repos"
)
const (
HTML = "html"
CSS = "css"
JS = "js"
GO = "go"
SH = "sh"
CSV = "csv"
JSON = "json"
)
const (
PATH = "path"
FILE = "file"
@ -136,10 +146,9 @@ func init() {
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
CAT: {Name: CAT, Help: "文件", Value: kit.Data(
SOURCE, kit.Dict(
"sh", ice.TRUE, "go", ice.TRUE, "js", ice.TRUE,
"shy", ice.TRUE, "json", ice.TRUE, "csv", ice.TRUE,
HTML, ice.TRUE, CSS, ice.TRUE, JS, ice.TRUE, GO, ice.TRUE, SH, ice.TRUE, CSV, ice.TRUE, JSON, ice.TRUE,
"md", ice.TRUE, "shy", ice.TRUE, "makefile", ice.TRUE, "license", ice.TRUE,
"conf", ice.TRUE, "yaml", ice.TRUE, "yml", ice.TRUE,
"makefile", ice.TRUE, "license", ice.TRUE, "md", ice.TRUE,
),
)},
}, Commands: map[string]*ice.Command{

58
conf.go
View File

@ -8,13 +8,6 @@ const (
PT = "."
FS = ","
NL = "\n"
OF = " of "
PWD = "./"
SH = "sh"
GO = "go"
JS = "js"
OK = "ok"
TRUE = "true"
@ -22,6 +15,7 @@ const (
SUCCESS = "success"
FAILURE = "failure"
PROCESS = "process"
OF = " of "
INIT = "init"
LOAD = "load"
@ -71,10 +65,10 @@ const ( // REPOS
CONTEXTS = "contexts"
INSTALL = "install"
RELEASE = "release"
PUBLISH = "publish"
REQUIRE = "require"
DISPLAY = "display"
PUBLISH = "publish"
RELEASE = "release"
)
const ( // DIR
SRC = "src"
@ -83,15 +77,25 @@ const ( // DIR
VAR = "var"
USR = "usr"
PWD = "./"
HTML = "html"
CSS = "css"
JS = "js"
GO = "go"
SH = "sh"
CSV = "csv"
JSON = "json"
USR_VOLCANOS = "usr/volcanos"
USR_LEARNING = "usr/learning"
USR_ICEBERGS = "usr/icebergs"
USR_TOOLKITS = "usr/toolkits"
USR_INTSHELL = "usr/intshell"
USR_RELEASE = "usr/release"
USR_INSTALL = "usr/install"
USR_RELEASE = "usr/release"
USR_PUBLISH = "usr/publish"
PLUGIN_INPUT = "/plugin/input"
PLUGIN_STORY = "/plugin/story"
PLUGIN_LOCAL = "/plugin/local"
@ -134,6 +138,7 @@ const ( // DIR
SRC_RELEASE = "src/release"
SRC_MAIN_GO = "src/main.go"
SRC_MAIN_SHY = "src/main.shy"
SRC_MAIN_SVG = "src/main.svg"
SRC_VERSION_GO = "src/version.go"
SRC_BINPACK_GO = "src/binpack.go"
MAKEFILE = "Makefile"
@ -146,6 +151,12 @@ const ( // MSG
MSG_APPEND = "append"
MSG_RESULT = "result"
MSG_CMDS = "cmds"
MSG_FIELDS = "fields"
MSG_SESSID = "sessid"
MSG_DOMAIN = "domain"
MSG_OPTS = "_option"
MSG_ALIAS = "_alias"
MSG_SCRIPT = "_script"
MSG_SOURCE = "_source"
@ -162,12 +173,6 @@ const ( // MSG
MSG_DISPLAY = "_display"
MSG_PROCESS = "_process"
MSG_CMDS = "cmds"
MSG_FIELDS = "fields"
MSG_SESSID = "sessid"
MSG_DOMAIN = "domain"
MSG_OPTS = "_option"
MSG_USERIP = "user.ip"
MSG_USERUA = "user.ua"
MSG_USERWEB = "user.web"
@ -212,8 +217,8 @@ const ( // RENDER
)
const ( // PROCESS
PROCESS_LOCATION = "_location"
PROCESS_REWRITE = "_rewrite"
PROCESS_REFRESH = "_refresh"
PROCESS_REWRITE = "_rewrite"
PROCESS_DISPLAY = "_display"
PROCESS_FIELD = "_field"
PROCESS_INNER = "_inner"
@ -298,6 +303,25 @@ const (
MDB = "mdb"
)
const (
CONFIG = "config"
COMMAND = "command"
ACTION = "action"
STYLE = "style"
INDEX = "index"
ARGS = "args"
)
const (
SERVE = "serve"
SPACE = "space"
SPIDE = "spide"
CACHE = "cache"
)
const (
KEY = "key"
VALUE = "value"
HASH = "hash"
TIME = "time"
TYPE = "type"
NAME = "name"
TEXT = "text"
)

View File

@ -81,9 +81,9 @@ func _action_share(m *ice.Message, arg ...string) {
break // 分享超时
}
if arg[0] = msg.Append(mdb.NAME); len(arg) == 1 {
m.Push("title", msg.Append(kit.MDB_TITLE))
m.Push("index", msg.Append(mdb.NAME))
m.Push("args", msg.Append(mdb.TEXT))
m.Push("title", msg.Append("title"))
m.Push(ctx.INDEX, msg.Append(mdb.NAME))
m.Push(ctx.ARGS, msg.Append(mdb.TEXT))
break // 命令列表
}

View File

@ -62,7 +62,7 @@ func init() {
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
ASSET: {Name: ASSET, Help: "资产", Value: kit.Data(
mdb.SHORT, ACCOUNT, mdb.FIELD, "time,id,type,amount,name,text",
kit.MDB_ALIAS, kit.Dict(FROM, ACCOUNT, TO, ACCOUNT),
mdb.ALIAS, kit.Dict(FROM, ACCOUNT, TO, ACCOUNT),
)},
}, Commands: map[string]*ice.Command{
ASSET: {Name: "asset account id auto spend trans bonus", Help: "资产", Meta: kit.Dict(

View File

@ -17,7 +17,7 @@ func init() {
ice.DisplayLocal(""),
), Action: ice.MergeAction(map[string]*ice.Action{
nfs.SAVE: {Name: "save", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
_wiki_save(m, DRAW, arg[0], m.Option(kit.MDB_CONTENT))
_wiki_save(m, DRAW, arg[0], m.Option("content"))
}},
}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if !_wiki_list(m, DRAW, kit.Select(ice.PWD, arg, 0)) {

View File

@ -61,7 +61,7 @@ func _field_show(m *ice.Message, name, text string, arg ...string) {
}
switch arg[i] {
case kit.MDB_CONTENT:
case "content":
meta[arg[i]] = arg[i+1]
case ARGS:
@ -69,7 +69,7 @@ func _field_show(m *ice.Message, name, text string, arg ...string) {
count := 0
kit.Fetch(meta[INPUTS], func(index int, value map[string]interface{}) {
if value[mdb.TYPE] != kit.MDB_BUTTON {
if value[mdb.TYPE] != "button" {
count++
}
})

View File

@ -15,7 +15,7 @@ func _word_show(m *ice.Message, name string, arg ...string) {
m.Option(TITLE, map[string]int{})
m.Option(MENU, kit.Dict(mdb.LIST, []interface{}{}))
m.Option(ice.MSG_ALIAS, m.Confv(WORD, kit.Keym(kit.MDB_ALIAS)))
m.Option(ice.MSG_ALIAS, m.Confv(WORD, kit.Keym(mdb.ALIAS)))
m.Option(nfs.DIR_ROOT, _wiki_path(m, WORD))
m.Cmdy(ssh.SOURCE, name)
}
@ -25,7 +25,7 @@ const WORD = "word"
func init() {
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
WORD: {Name: WORD, Help: "语言文字", Value: kit.Data(
nfs.PATH, "", REGEXP, ".*\\.shy", kit.MDB_ALIAS, kit.Dict(
nfs.PATH, "", REGEXP, ".*\\.shy", mdb.ALIAS, kit.Dict(
NAVMENU, kit.List(TITLE, NAVMENU),
PREMENU, kit.List(TITLE, PREMENU),
CHAPTER, kit.List(TITLE, CHAPTER),

View File

@ -25,7 +25,6 @@ func (m *Message) Config(key string, arg ...interface{}) string {
m.Conf(m.PrefixKey(), kit.Keym(key), arg[0])
}
return m.Conf(m.PrefixKey(), kit.Keym(key))
// return kit.Format(m.Configv(key, arg...))
}
func (m *Message) Configv(key string, arg ...interface{}) interface{} {
if len(arg) > 0 {
@ -52,7 +51,7 @@ func (m *Message) Save(arg ...string) *Message {
for i, k := range arg {
arg[i] = m.Prefix(k)
}
return m.Cmd("config", SAVE, m.Prefix("json"), arg)
return m.Cmd(CONFIG, SAVE, m.Prefix(JSON), arg)
}
func (m *Message) Load(arg ...string) *Message {
if len(arg) == 0 {
@ -63,7 +62,7 @@ func (m *Message) Load(arg ...string) *Message {
for i, k := range arg {
arg[i] = m.Prefix(k)
}
return m.Cmd("config", LOAD, m.Prefix("json"), arg)
return m.Cmd(CONFIG, LOAD, m.Prefix(JSON), arg)
}
func (m *Message) Richs(prefix string, chain interface{}, raw interface{}, cb interface{}) (res map[string]interface{}) {
@ -113,7 +112,7 @@ func (m *Message) Grows(prefix string, chain interface{}, match string, value st
limit := kit.Int(m.Option(CACHE_LIMIT))
if begin := kit.Int(m.Option(CACHE_BEGIN)); begin != 0 && limit > 0 {
count := kit.Int(m.Option(CACHE_COUNT, kit.Int(kit.Value(cache, kit.Keym(kit.MDB_COUNT)))))
count := kit.Int(m.Option(CACHE_COUNT, kit.Int(kit.Value(cache, kit.Keym("count")))))
if begin > 0 {
m.Option(CACHE_OFFEND, count-begin-limit)
} else {

14
exec.go
View File

@ -87,7 +87,7 @@ func (m *Message) Done(ok bool) bool {
func (m *Message) Call(sync bool, cb func(*Message) *Message) *Message {
wait := make(chan bool, 2)
p := kit.Select("10s", m.Option(kit.MDB_TIMEOUT))
p := kit.Select("10s", m.Option("timeout"))
t := time.AfterFunc(kit.Duration(p), func() {
m.Warn(true, ErrTimeout, m.Detailv())
m.Back(nil)
@ -136,11 +136,11 @@ func (m *Message) Watch(key string, arg ...string) *Message {
if len(arg) == 0 {
arg = append(arg, m.Prefix(AUTO))
}
m.Cmd("event", "action", "listen", "event", key, CMD, kit.Join(arg, SP))
m.Cmd("event", ACTION, "listen", "event", key, CMD, kit.Join(arg, SP))
return m
}
func (m *Message) Event(key string, arg ...string) *Message {
m.Cmd("event", "action", "action", "event", key, arg)
m.Cmd("event", ACTION, "action", "event", key, arg)
return m
}
func (m *Message) Right(arg ...interface{}) bool {
@ -152,15 +152,15 @@ func (m *Message) Space(arg interface{}) []string {
if arg == nil || arg == "" || kit.Format(arg) == m.Conf("runtime", "node.name") {
return nil
}
return []string{"space", kit.Format(arg)}
return []string{SPACE, kit.Format(arg)}
}
func (m *Message) PodCmd(arg ...interface{}) bool {
if pod := m.Option(POD); pod != "" {
if m.Option(POD, ""); m.Option(MSG_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))
msg := m.Cmd(CACHE, "upload")
m.Option(MSG_UPLOAD, msg.Append(HASH), msg.Append(NAME), msg.Append("size"))
}
m.Cmdy(append(kit.List("space", pod), arg...))
m.Cmdy(append(kit.List(SPACE, pod), arg...))
return true
}
return false

View File

@ -107,7 +107,7 @@ func Run(arg ...string) string {
Index.root, Pulse.root = Index, Pulse
switch Index.Merge(Index).Begin(Pulse.Spawn(), arg...); kit.Select("", arg, 0) {
case "serve", "space":
case SERVE, SPACE:
if log.LogDisable = false; Index.Start(Pulse, arg...) {
Pulse.TryCatch(Pulse, true, func(Pulse *Message) { Index.wg.Wait() })
os.Exit(kit.Int(Pulse.Option(EXIT)))

60
meta.go
View File

@ -15,16 +15,16 @@ func (m *Message) Set(key string, arg ...string) *Message {
case MSG_OPTION, MSG_APPEND:
if m.FieldsIsDetail() {
if len(arg) > 0 {
for i := 0; i < len(m.meta[kit.MDB_KEY]); i++ {
if m.meta[kit.MDB_KEY][i] == arg[0] {
m.meta[kit.MDB_KEY][i] = ""
m.meta[kit.MDB_VALUE][i] = ""
for i := 0; i < len(m.meta[KEY]); i++ {
if m.meta[KEY][i] == arg[0] {
m.meta[KEY][i] = ""
m.meta[VALUE][i] = ""
}
}
return m
}
delete(m.meta, kit.MDB_KEY)
delete(m.meta, kit.MDB_VALUE)
delete(m.meta, KEY)
delete(m.meta, VALUE)
return m
}
if len(arg) > 0 {
@ -43,18 +43,18 @@ func (m *Message) Set(key string, arg ...string) *Message {
delete(m.meta, k)
}
if m.FieldsIsDetail() {
for i := 0; i < len(m.meta[kit.MDB_KEY]); i++ {
if m.meta[kit.MDB_KEY][i] == key {
for i := 0; i < len(m.meta[KEY]); i++ {
if m.meta[KEY][i] == key {
if len(arg) > 0 {
m.meta[kit.MDB_VALUE][i] = arg[0]
m.meta[VALUE][i] = arg[0]
return m
}
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_VALUE][i] = m.meta[kit.MDB_VALUE][i+1]
for ; i < len(m.meta[KEY])-1; i++ {
m.meta[KEY][i] = m.meta[KEY][i+1]
m.meta[VALUE][i] = m.meta[VALUE][i+1]
}
m.meta[kit.MDB_KEY] = kit.Slice(m.meta[kit.MDB_KEY], 0, -1)
m.meta[kit.MDB_VALUE] = kit.Slice(m.meta[kit.MDB_VALUE], 0, -1)
m.meta[KEY] = kit.Slice(m.meta[KEY], 0, -1)
m.meta[VALUE] = kit.Slice(m.meta[VALUE], 0, -1)
break
}
}
@ -115,7 +115,7 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa
// 查找数据
var v interface{}
switch k {
case kit.MDB_KEY, kit.MDB_HASH:
case KEY, HASH:
if key != "" && key != "detail" {
v = key
break
@ -134,8 +134,8 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa
// 追加数据
switch v := kit.Format(v); key {
case "detail":
m.Add(MSG_APPEND, kit.MDB_KEY, k)
m.Add(MSG_APPEND, kit.MDB_VALUE, v)
m.Add(MSG_APPEND, KEY, k)
m.Add(MSG_APPEND, VALUE, v)
default:
m.Add(MSG_APPEND, k, v)
}
@ -158,9 +158,9 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa
default:
if m.FieldsIsDetail() {
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))
if key != KEY || key != VALUE {
m.Add(MSG_APPEND, KEY, key)
m.Add(MSG_APPEND, VALUE, kit.Format(value))
break
}
}
@ -200,7 +200,7 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message {
return m
}
func (m *Message) Sort(key string, arg ...string) *Message {
if m.FieldsIsDetail() && key != kit.MDB_KEY {
if m.FieldsIsDetail() && key != KEY {
return m
}
// 排序方法
@ -276,10 +276,10 @@ func (m *Message) Table(cbs ...func(index int, value map[string]string, head []s
return m
}
line := map[string]string{}
for i, k := range m.meta[kit.MDB_KEY] {
line[k] = kit.Select("", m.meta[kit.MDB_VALUE], i)
for i, k := range m.meta[KEY] {
line[k] = kit.Select("", m.meta[VALUE], i)
}
cbs[0](0, line, m.meta[kit.MDB_KEY])
cbs[0](0, line, m.meta[KEY])
return m
}
@ -401,18 +401,18 @@ func (m *Message) Appendv(key string, arg ...interface{}) []string {
return m.meta[key]
}
if m.FieldsIsDetail() && key != kit.MDB_KEY {
for i, k := range m.meta[kit.MDB_KEY] {
if m.FieldsIsDetail() && key != KEY {
for i, k := range m.meta[KEY] {
if k == key {
if len(arg) > 0 {
m.meta[kit.MDB_VALUE][i] = kit.Format(arg[0])
m.meta[VALUE][i] = kit.Format(arg[0])
}
return []string{kit.Select("", m.meta[kit.MDB_VALUE], i)}
return []string{kit.Select("", m.meta[VALUE], i)}
}
}
if len(arg) > 0 {
m.Add(MSG_APPEND, kit.MDB_KEY, key)
m.Add(MSG_APPEND, kit.MDB_VALUE, kit.Format(arg[0]))
m.Add(MSG_APPEND, KEY, key)
m.Add(MSG_APPEND, VALUE, kit.Format(arg[0]))
return []string{kit.Format(arg[0])}
}
return nil

42
misc.go
View File

@ -88,7 +88,7 @@ func (m *Message) FieldsIsDetail() bool {
if m.OptionFields() == "detail" {
return true
}
if len(m.meta[MSG_APPEND]) == 2 && m.meta[MSG_APPEND][0] == kit.MDB_KEY && m.meta[MSG_APPEND][1] == kit.MDB_VALUE {
if len(m.meta[MSG_APPEND]) == 2 && m.meta[MSG_APPEND][0] == KEY && m.meta[MSG_APPEND][1] == VALUE {
return true
}
return false
@ -105,12 +105,12 @@ func (m *Message) OptionCB(key string, cb ...interface{}) interface{} {
func (m *Message) OptionUserWeb() *url.URL {
return kit.ParseURL(m.Option(MSG_USERWEB))
}
func (m *Message) SetAppend(arg ...string) *Message {
return m.Set(MSG_APPEND, arg...)
}
func (m *Message) SetResult(arg ...string) *Message {
return m.Set(MSG_RESULT, arg...)
}
func (m *Message) SetAppend(arg ...string) *Message {
return m.Set(MSG_APPEND, arg...)
}
func (m *Message) RenameAppend(from, to string) *Message {
for i, v := range m.meta[MSG_APPEND] {
if v == from {
@ -124,7 +124,7 @@ func (m *Message) RenameAppend(from, to string) *Message {
func (m *Message) AppendSimple(key ...string) (res []string) {
if len(key) == 0 {
if m.FieldsIsDetail() {
key = append(key, m.Appendv(kit.MDB_KEY)...)
key = append(key, m.Appendv(KEY)...)
} else {
key = append(key, m.Appendv(MSG_APPEND)...)
}
@ -261,8 +261,8 @@ func (c *Context) _cmd(m *Message, cmd *Command, key string, sub string, h *Acti
if m._sub = sub; len(h.List) > 0 && sub != "search" {
order := false
for i, v := range h.List {
name := kit.Format(kit.Value(v, kit.MDB_NAME))
value := kit.Format(kit.Value(v, kit.MDB_VALUE))
name := kit.Format(kit.Value(v, NAME))
value := kit.Format(kit.Value(v, VALUE))
if i == 0 && len(arg) > 0 && arg[0] != name {
order = true
@ -298,23 +298,23 @@ func (c *Context) split(name string) (list []interface{}) {
for i := 1; i < len(ls); i++ {
switch ls[i] {
case "run":
item = kit.Dict(kit.MDB_TYPE, BUTTON, kit.MDB_NAME, "run")
item = kit.Dict(TYPE, BUTTON, NAME, "run")
list = append(list, item)
case "text":
item = kit.Dict(kit.MDB_TYPE, TEXTAREA, kit.MDB_NAME, "text")
item = kit.Dict(TYPE, TEXTAREA, NAME, "text")
list = append(list, item)
case "auto":
list = append(list, kit.List(kit.MDB_TYPE, BUTTON, kit.MDB_NAME, "list", kit.MDB_ACTION, AUTO)...)
list = append(list, kit.List(kit.MDB_TYPE, BUTTON, kit.MDB_NAME, "back")...)
list = append(list, kit.List(TYPE, BUTTON, NAME, "list", ACTION, AUTO)...)
list = append(list, kit.List(TYPE, BUTTON, NAME, "back")...)
button = true
case "page":
list = append(list, kit.List(kit.MDB_TYPE, TEXT, kit.MDB_NAME, "limit")...)
list = append(list, kit.List(kit.MDB_TYPE, TEXT, kit.MDB_NAME, "offend")...)
list = append(list, kit.List(kit.MDB_TYPE, BUTTON, kit.MDB_NAME, "prev")...)
list = append(list, kit.List(kit.MDB_TYPE, BUTTON, kit.MDB_NAME, "next")...)
list = append(list, kit.List(TYPE, TEXT, NAME, "limit")...)
list = append(list, kit.List(TYPE, TEXT, NAME, "offend")...)
list = append(list, kit.List(TYPE, BUTTON, NAME, "prev")...)
list = append(list, kit.List(TYPE, BUTTON, NAME, "next")...)
case ":":
if item[kit.MDB_TYPE] = kit.Select("", ls, i+1); item[kit.MDB_TYPE] == BUTTON {
if item[TYPE] = kit.Select("", ls, i+1); item[TYPE] == BUTTON {
button = true
}
i++
@ -326,18 +326,18 @@ func (c *Context) split(name string) (list []interface{}) {
} else {
item["values"] = vs
}
item[kit.MDB_VALUE] = vs[0]
item[kit.MDB_TYPE] = SELECT
item[VALUE] = vs[0]
item[TYPE] = SELECT
} else {
item[kit.MDB_VALUE] = value
item[VALUE] = value
}
i++
case "@":
item[kit.MDB_ACTION] = kit.Select("", ls, i+1)
item[ACTION] = kit.Select("", ls, i+1)
i++
default:
item = kit.Dict(kit.MDB_TYPE, kit.Select(TEXT, BUTTON, button), kit.MDB_NAME, ls[i])
item = kit.Dict(TYPE, kit.Select(TEXT, BUTTON, button), NAME, ls[i])
list = append(list, item)
}
}

View File

@ -19,7 +19,7 @@ func init() {
}
name += "的" + kit.Select("应用列表", arg, 2)
text, link, list := kit.Select("", arg, 3), kit.MergeURL2(m.Conf(web.SHARE, kit.Keym(kit.MDB_DOMAIN)), "/chat/lark/sso"), []string{}
text, link, list := kit.Select("", arg, 3), kit.MergeURL2(m.Conf(web.SHARE, kit.Keym("domain")), "/chat/lark/sso"), []string{}
if len(arg) == 0 {
m.Cmd("web.chat./river").Table(func(index int, val map[string]string, head []string) {
m.Cmd("web.chat./river", val[mdb.HASH], chat.STORM).Table(func(index int, value map[string]string, head []string) {

View File

@ -3,6 +3,7 @@ package lark
import (
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
@ -20,9 +21,9 @@ func init() {
appid := m.Cmd(APP).Append(APPID)
home := m.MergeURL2("/chat/lark/sso")
if m.Option(kit.MDB_CODE) != "" { // 登录成功
if m.Option(cli.CODE) != "" { // 登录成功
msg := m.Cmd(web.SPIDE, LARK, "/open-apis/authen/v1/access_token", "grant_type", "authorization_code",
kit.MDB_CODE, m.Option(kit.MDB_CODE), "app_access_token", m.Cmdx(APP, TOKEN, appid))
cli.CODE, m.Option(cli.CODE), "app_access_token", m.Cmdx(APP, TOKEN, appid))
// 更新用户
m.Option(aaa.USERNAME, msg.Append("data.open_id"))
@ -36,13 +37,13 @@ func init() {
)
// 创建会话
web.RenderCookie(m, aaa.SessCreate(m, m.Option(aaa.USERNAME)), web.CookieName(m.Option(kit.MDB_BACK)))
m.RenderRedirect(kit.Select(home, m.Option(kit.MDB_BACK)))
web.RenderCookie(m, aaa.SessCreate(m, m.Option(aaa.USERNAME)), web.CookieName(m.Option(cli.BACK)))
m.RenderRedirect(kit.Select(home, m.Option(cli.BACK)))
return
}
if back := m.R.Header.Get("Referer"); back != "" {
home = kit.MergeURL(home, kit.MDB_BACK, back)
home = kit.MergeURL(home, cli.BACK, back)
}
// 登录页面
m.RenderRedirect(kit.MergeURL2(m.Cmd(web.SPIDE, LARK).Append("client.url"), "/open-apis/authen/v1/index"),

View File

@ -6,6 +6,7 @@ import (
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web"
@ -40,7 +41,7 @@ func init() {
}},
aaa.SESS: {Name: "sess code", Help: "会话", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(web.SPIDE, MP, web.SPIDE_GET, "/sns/jscode2session?grant_type=authorization_code",
"js_code", m.Option(kit.MDB_CODE), APPID, m.Config(APPID), "secret", m.Config(APPMM))
"js_code", m.Option(cli.CODE), APPID, m.Config(APPID), "secret", m.Config(APPMM))
// 用户登录
m.Option(ice.MSG_USERZONE, MP)

View File

@ -1,17 +1,19 @@
package pi
import (
"shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/core/chat"
"shylinux.com/x/toolkits"
"os"
"path"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/core/chat"
kit "shylinux.com/x/toolkits"
)
var Index = &ice.Context{Name: "pi", Help: "开发板",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
"pi": {Name: "pi", Help: "pi", Value: kit.Data(kit.MDB_SHORT, "name")},
"pi": {Name: "pi", Help: "pi", Value: kit.Data(mdb.SHORT, "name")},
},
Commands: map[string]*ice.Command{
"GPIO": {Name: "GPIO", Help: "GPIO", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {

View File

@ -25,7 +25,7 @@ func init() {
if arg[0] = strings.TrimSpace(arg[0]); strings.HasPrefix(arg[0], "ice ") {
switch list := kit.Split(arg[0]); list[1] {
case "add": // ice add 想你 shwq [person [9999]]
m.Cmd("web.code.input.wubi", mdb.INSERT, mdb.TEXT, list[2], kit.MDB_CODE, list[3],
m.Cmd("web.code.input.wubi", mdb.INSERT, mdb.TEXT, list[2], cli.CODE, list[3],
mdb.ZONE, kit.Select("person", list, 4), mdb.VALUE, kit.Select("999999", list, 5),
)
arg[0] = list[3]

View File

@ -15,7 +15,7 @@ type Option struct {
Value interface{}
}
func OptionHash(arg string) Option { return Option{kit.MDB_HASH, arg} }
func OptionHash(arg string) Option { return Option{HASH, arg} }
func OptionFields(arg ...string) Option { return Option{MSG_FIELDS, kit.Join(arg)} }
func (m *Message) OptionFields(arg ...string) string {
@ -59,20 +59,20 @@ func (m *Message) OptionSimple(key ...string) (res []string) {
}
func (m *Message) OptionTemplate() string {
res := []string{`class="story"`}
for _, key := range kit.Split(kit.MDB_STYLE) {
for _, key := range kit.Split(STYLE) {
if m.Option(key) != "" {
res = append(res, kit.Format(`s="%s"`, key, m.Option(key)))
}
}
for _, key := range kit.Split("type,name,text") {
if key == "text" && m.Option("type") == "spark" {
if key == TEXT && m.Option(TYPE) == "spark" {
continue
}
if m.Option(key) != "" {
res = append(res, kit.Format(`data-%s="%s"`, key, m.Option(key)))
}
}
kit.Fetch(m.Optionv(kit.MDB_EXTRA), func(key string, value string) {
kit.Fetch(m.Optionv("extra"), func(key string, value string) {
if value != "" {
res = append(res, kit.Format(`data-%s="%s"`, key, value))
}
@ -86,14 +86,14 @@ func (m *Message) Fields(length int, fields ...string) string {
func (m *Message) Upload(dir string) {
up := kit.Simple(m.Optionv(MSG_UPLOAD))
if len(up) < 2 {
msg := m.Cmd("cache", "upload")
up = kit.Simple(msg.Append(kit.MDB_HASH), msg.Append(kit.MDB_NAME), msg.Append(kit.MDB_SIZE))
msg := m.Cmd(CACHE, "upload")
up = kit.Simple(msg.Append(HASH), msg.Append(NAME), msg.Append("size"))
}
if p := path.Join(dir, up[1]); m.Option(MSG_USERPOD) == "" {
m.Cmdy("cache", "watch", up[0], p) // 本机文件
m.Cmdy(CACHE, "watch", up[0], p) // 本机文件
} else { // 下发文件
m.Cmdy("spide", DEV, SAVE, p, "GET", m.MergeURL2(path.Join("/share/cache", up[0])))
m.Cmdy(SPIDE, DEV, SAVE, p, "GET", m.MergeURL2(path.Join("/share/cache", up[0])))
}
}
func (m *Message) Action(arg ...interface{}) {
@ -110,22 +110,22 @@ func (m *Message) Status(arg ...interface{}) {
list := kit.List()
args := kit.Simple(arg)
for i := 0; i < len(args)-1; i += 2 {
list = append(list, kit.Dict(kit.MDB_NAME, args[i], kit.MDB_VALUE, args[i+1]))
list = append(list, kit.Dict(NAME, args[i], VALUE, args[i+1]))
}
m.Option(MSG_STATUS, kit.Format(list))
}
func (m *Message) StatusTime(arg ...interface{}) {
m.Status(kit.MDB_TIME, m.Time(), arg, kit.MDB_COST, m.FormatCost())
m.Status(TIME, m.Time(), arg, kit.MDB_COST, m.FormatCost())
}
func (m *Message) StatusTimeCount(arg ...interface{}) {
m.Status(kit.MDB_TIME, m.Time(), kit.MDB_COUNT, kit.Split(m.FormatSize())[0], arg, kit.MDB_COST, m.FormatCost())
m.Status(TIME, m.Time(), kit.MDB_COUNT, kit.Split(m.FormatSize())[0], arg, kit.MDB_COST, m.FormatCost())
}
func (m *Message) StatusTimeCountTotal(arg ...interface{}) {
m.Status(kit.MDB_TIME, m.Time(), kit.MDB_COUNT, kit.Split(m.FormatSize())[0], kit.MDB_TOTAL, arg, kit.MDB_COST, m.FormatCost())
m.Status(TIME, m.Time(), kit.MDB_COUNT, kit.Split(m.FormatSize())[0], kit.MDB_TOTAL, arg, kit.MDB_COST, m.FormatCost())
}
func (m *Message) Confirm(text string) string {
return m.Cmdx("space", m.Option(MSG_DAEMON), "confirm", text)
return m.Cmdx(SPACE, m.Option(MSG_DAEMON), "confirm", text)
}
func (m *Message) ToastSuccess(arg ...interface{}) {
m.Toast(SUCCESS, arg...)
@ -144,9 +144,9 @@ func (m *Message) Toast(text string, arg ...interface{}) { // [title [duration [
}
func (m *Message) PushNotice(arg ...interface{}) {
if m.Option(MSG_USERPOD) == "" {
m.Cmd("space", m.Option(MSG_DAEMON), arg)
m.Cmd(SPACE, m.Option(MSG_DAEMON), arg)
} else {
m.Cmd("web.spide", "dev", m.MergeURL2("/share/toast/"), kit.Format(kit.Dict("pod", m.Option(MSG_DAEMON), "cmds", kit.Simple(arg...))))
m.Cmd(SPIDE, DEV, m.MergeURL2("/share/toast/"), kit.Format(kit.Dict(POD, m.Option(MSG_DAEMON), "cmds", kit.Simple(arg...))))
}
}
func (m *Message) PushNoticeGrow(arg ...interface{}) {
@ -204,7 +204,7 @@ func (m *Message) ProcessCommand(cmd string, val []string, arg ...string) {
return
}
m.Cmdy("command", cmd)
m.Cmdy(COMMAND, cmd)
m.ProcessField(cmd, RUN)
m.Push(ARG, kit.Format(val))
}

View File

@ -18,7 +18,7 @@ func Render(m *Message, cmd string, args ...interface{}) string {
switch arg := kit.Simple(args...); cmd {
case RENDER_ANCHOR: // [name] link
p := kit.Select(arg[0], arg, 1)
if !strings.HasPrefix(p, "http") {
if !strings.HasPrefix(p, HTTP) {
p = m.MergeURL2(p)
}
return kit.Format(`<a href="%s" target="_blank">%s</a>`, p, arg[0])
@ -76,15 +76,15 @@ 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...))))
return m.RenderDownload(path.Join(m.Conf(serve, kit.Keym(repos, "path")), kit.Select(m.Conf(serve, kit.Keym(repos, INDEX)), path.Join(file...))))
}
func (m *Message) RenderCmd(index string, args ...interface{}) {
list := index
if index != "" {
msg := m.Cmd("command", index)
msg := m.Cmd(COMMAND, index)
list = kit.Format(kit.List(kit.Dict(
kit.MDB_INDEX, index, kit.MDB_ARGS, kit.Simple(args),
msg.AppendSimple(kit.MDB_NAME, kit.MDB_HELP),
INDEX, index, ARGS, kit.Simple(args),
msg.AppendSimple(NAME, "help"),
"feature", kit.UnMarshal(msg.Append("meta")),
"inputs", kit.UnMarshal(msg.Append("list")),
)))
@ -110,17 +110,17 @@ func (m *Message) IsCliUA() bool {
}
func (m *Message) PushAnchor(arg ...interface{}) { // [name] link
if !m.IsCliUA() {
m.Push(kit.MDB_LINK, Render(m, RENDER_ANCHOR, arg...))
m.Push("link", Render(m, RENDER_ANCHOR, arg...))
}
}
func (m *Message) PushButton(arg ...interface{}) { // name...
if !m.IsCliUA() {
m.Push(kit.MDB_ACTION, Render(m, RENDER_BUTTON, arg...))
m.Push(ACTION, Render(m, RENDER_BUTTON, arg...))
}
}
func (m *Message) PushScript(arg ...string) { // [type] text...
if !m.IsCliUA() {
m.Push(kit.MDB_SCRIPT, Render(m, RENDER_SCRIPT, arg))
m.Push("script", Render(m, RENDER_SCRIPT, arg))
}
}
func (m *Message) PushQRCode(key string, src string, arg ...string) { // key src [size]
@ -150,7 +150,7 @@ func (m *Message) PushDownload(key string, arg ...interface{}) { // [name] file
}
func (m *Message) PushAction(list ...interface{}) {
m.Set(MSG_APPEND, "action")
m.Set(MSG_APPEND, ACTION)
m.Table(func(index int, value map[string]string, head []string) {
m.PushButton(list...)
})
@ -162,14 +162,14 @@ func (m *Message) PushPodCmd(cmd string, arg ...string) {
})
}
m.Cmd("space").Table(func(index int, value map[string]string, head []string) {
switch value[kit.MDB_TYPE] {
m.Cmd(SPACE).Table(func(index int, value map[string]string, head []string) {
switch value[TYPE] {
case "server", "worker":
if value[kit.MDB_NAME] == Info.HostName {
if value[NAME] == Info.HostName {
break
}
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])
m.Cmd(SPACE, value[NAME], m.Prefix(cmd), arg).Table(func(index int, val map[string]string, head []string) {
val[POD] = kit.Keys(value[NAME], val[POD])
m.Push("", val, head)
})
}
@ -185,7 +185,7 @@ func (m *Message) PushSearch(args ...interface{}) {
m.Push(k, kit.Select(m.Prefix(), data[k]))
case CMD:
m.Push(k, kit.Select(m.CommandKey(), data[k]))
case kit.MDB_TIME:
case TIME:
m.Push(k, kit.Select(m.Time(), data[k]))
default:
m.Push(k, kit.Select("", data[k]))
@ -243,7 +243,7 @@ func (m *Message) Display(file string, arg ...interface{}) *Message {
}
func DisplayBase(file string, arg ...string) map[string]string {
return map[string]string{DISPLAY: file, kit.MDB_STYLE: kit.Join(arg, SP)}
return map[string]string{DISPLAY: file, STYLE: kit.Join(arg, SP)}
}
func DisplayLocal(file string, arg ...string) map[string]string {
if file == "" {

18
type.go
View File

@ -154,7 +154,7 @@ func (c *Context) Merge(s *Context) *Context {
help = strings.SplitN(help[0], ":", 2)
}
if kit.Value(cmd.Meta, kit.Keys("_trans", strings.TrimPrefix(k, "_")), help[0]); len(help) > 1 {
kit.Value(cmd.Meta, kit.Keys(kit.MDB_TITLE, k), help[1])
kit.Value(cmd.Meta, kit.Keys("title", k), help[1])
}
if a.Hand == nil {
continue // alias cmd
@ -374,7 +374,7 @@ func (m *Message) Search(key string, cb interface{}) *Message {
// 查找模块
p := m.target.root
if key = strings.TrimPrefix(key, "ice."); key == "." {
if key = strings.TrimPrefix(key, "ice."); key == PT {
p, key = m.target, ""
} else if key == ".." {
p, key = m.target.context, ""
@ -460,17 +460,17 @@ func (m *Message) Search(key string, cb interface{}) *Message {
return m
}
func (m *Message) Cmdy(arg ...interface{}) *Message {
return m.Copy(m.cmd(arg...))
}
func (m *Message) Cmdx(arg ...interface{}) string {
return kit.Select("", m.cmd(arg...).meta[MSG_RESULT], 0)
func (m *Message) Cmd(arg ...interface{}) *Message {
return m.cmd(arg...)
}
func (m *Message) Cmds(arg ...interface{}) *Message {
return m.Go(func() { m.cmd(arg...) })
}
func (m *Message) Cmd(arg ...interface{}) *Message {
return m.cmd(arg...)
func (m *Message) Cmdx(arg ...interface{}) string {
return kit.Select("", m.cmd(arg...).meta[MSG_RESULT], 0)
}
func (m *Message) Cmdy(arg ...interface{}) *Message {
return m.Copy(m.cmd(arg...))
}
func (m *Message) Confi(key string, sub string) int {