forked from x/icebergs
add mdb.search
This commit is contained in:
parent
ac26f735df
commit
fb008449c7
@ -2,34 +2,29 @@ package aaa
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
// "github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
ROLE = "role"
|
||||
USER = "user"
|
||||
SESS = "sess"
|
||||
)
|
||||
const (
|
||||
USERROLE = "userrole"
|
||||
USERNICK = "usernick"
|
||||
USERNAME = "username"
|
||||
PASSWORD = "password"
|
||||
USERROLE = "userrole"
|
||||
USERNODE = "usernode"
|
||||
USERNICK = "usernick"
|
||||
|
||||
SESSID = "sessid"
|
||||
)
|
||||
|
||||
var Index = &ice.Context{Name: "aaa", Help: "认证模块", Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Rich(ROLE, nil, kit.Dict(kit.MDB_NAME, TECH, Black, kit.Dict(), White, kit.Dict()))
|
||||
m.Rich(ROLE, nil, kit.Dict(kit.MDB_NAME, VOID, White, kit.Dict(), Black, kit.Dict()))
|
||||
m.Rich(ROLE, nil, kit.Dict(kit.MDB_NAME, TECH, Black, kit.Dict(), White, kit.Dict()))
|
||||
m.Load()
|
||||
m.Cmd("mdb.search", "create", "user", "user", "aaa")
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Save(ROLE, USER, SESS)
|
||||
m.Save(USER, SESS, ROLE)
|
||||
}},
|
||||
}}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, ROLE, USER, SESS) }
|
||||
func init() { ice.Index.Register(Index, nil, USER, SESS, ROLE) }
|
||||
|
@ -90,6 +90,9 @@ func _role_white(m *ice.Message, userrole, chain string, status bool) {
|
||||
func RoleRight(m *ice.Message, userrole string, keys ...string) bool {
|
||||
return _role_right(m, userrole, kit.Split(kit.Keys(keys), ".")...)
|
||||
}
|
||||
|
||||
const ROLE = "role"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
|
@ -2,6 +2,7 @@ package aaa
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
@ -19,15 +20,15 @@ func _sess_auth(m *ice.Message, sessid string, username string, userrole string)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
value["username"] = username
|
||||
m.Log_AUTH(SESSID, sessid, USERNAME, username, USERROLE, userrole)
|
||||
value[USERNAME] = username
|
||||
})
|
||||
}
|
||||
func _sess_check(m *ice.Message, sessid string) {
|
||||
m.Richs(SESS, nil, sessid, func(value map[string]interface{}) {
|
||||
m.Log_AUTH(
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, value[USERROLE]),
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, value[USERNAME]),
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, value[USERROLE]),
|
||||
)
|
||||
})
|
||||
}
|
||||
@ -49,6 +50,9 @@ func SessCreate(m *ice.Message, username, userrole string) string {
|
||||
_sess_auth(m, _sess_create(m, username), username, userrole)
|
||||
return m.Result()
|
||||
}
|
||||
|
||||
const SESS = "sess"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
@ -57,9 +61,9 @@ func init() {
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
SESS: {Name: "sess check|login", Help: "会话", Action: map[string]*ice.Action{
|
||||
kit.MDB_CREATE: {Name: "create [username]", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_sess_create(m, arg[0])
|
||||
SESS: {Name: "sess", Help: "会话", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create [username]", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_sess_create(m, kit.Select("", arg, 0))
|
||||
}},
|
||||
"check": {Name: "check sessid", Help: "校验", Hand: func(m *ice.Message, arg ...string) {
|
||||
_sess_check(m, arg[0])
|
||||
@ -67,9 +71,7 @@ func init() {
|
||||
"auth": {Name: "auth sessid username [userrole]", Help: "授权", Hand: func(m *ice.Message, arg ...string) {
|
||||
_sess_auth(m, arg[0], arg[1], kit.Select("", arg, 2))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_sess_list(m)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { _sess_list(m) }},
|
||||
},
|
||||
}, nil)
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/gdb"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
"strings"
|
||||
@ -26,7 +27,6 @@ func _user_login(m *ice.Message, name, word string) (ok bool) {
|
||||
return ok
|
||||
}
|
||||
func _user_create(m *ice.Message, name, word string) {
|
||||
// 创建用户
|
||||
m.Rich(USER, nil, kit.Dict(
|
||||
USERNAME, name, PASSWORD, word,
|
||||
USERNICK, name, USERNODE, cli.NodeName,
|
||||
@ -34,6 +34,21 @@ func _user_create(m *ice.Message, name, word string) {
|
||||
m.Log_CREATE(USERNAME, name)
|
||||
m.Event(gdb.USER_CREATE, name)
|
||||
}
|
||||
func _user_search(m *ice.Message, kind, name, text string, arg ...string) {
|
||||
m.Richs(USER, nil, kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
||||
if name != val[USERNAME] {
|
||||
return
|
||||
}
|
||||
m.Push("pod", m.Option("pod"))
|
||||
m.Push("ctx", "aaa")
|
||||
m.Push("cmd", USER)
|
||||
m.Push(key, val, []string{kit.MDB_TIME})
|
||||
m.Push(kit.MDB_SIZE, kit.Format(""))
|
||||
m.Push(kit.MDB_TYPE, kit.Format(UserRole(m, val[USERNAME])))
|
||||
m.Push(kit.MDB_NAME, kit.Format(val[USERNAME]))
|
||||
m.Push(kit.MDB_TEXT, kit.Format(val[USERNODE]))
|
||||
})
|
||||
}
|
||||
|
||||
func UserRoot(m *ice.Message) {
|
||||
cli.PassWord = kit.Hashs("uniq")
|
||||
@ -54,22 +69,26 @@ func UserLogin(m *ice.Message, username, password string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const USER = "user"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
USER: {Name: "user", Help: "用户", Value: kit.Data(kit.MDB_SHORT, USERNAME)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
USER: {Name: "user first|login", Help: "用户", Action: map[string]*ice.Action{
|
||||
kit.MDB_CREATE: {Name: "create username [password]", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
USER: {Name: "user", Help: "用户", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create username [password]", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_user_create(m, arg[0], kit.Select("", arg, 1))
|
||||
}},
|
||||
"login": {Name: "login username password", Help: "login", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.SEARCH: {Name: "search type name text arg...", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
_user_search(m, arg[0], arg[1], kit.Select("", arg, 2))
|
||||
}},
|
||||
"login": {Name: "login username password", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
_user_login(m, arg[0], arg[1])
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_user_list(m)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { _user_list(m) }},
|
||||
},
|
||||
}, nil)
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/ctx"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
"os"
|
||||
"os/user"
|
||||
@ -12,25 +12,22 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RUNTIME = "runtime"
|
||||
SYSTEM = "system"
|
||||
DAEMON = "daemon"
|
||||
PYTHON = "python"
|
||||
)
|
||||
|
||||
var UserName = ""
|
||||
var PassWord = ""
|
||||
var HostName = ""
|
||||
var PathName = ""
|
||||
var NodeName = ""
|
||||
var NodeType = ""
|
||||
|
||||
func NodeType(m *ice.Message, kind, name string) {
|
||||
func NodeInfo(m *ice.Message, kind, name string) {
|
||||
m.Conf(RUNTIME, "node.type", kind)
|
||||
m.Conf(RUNTIME, "node.name", name)
|
||||
NodeName = name
|
||||
NodeType = kind
|
||||
}
|
||||
|
||||
const RUNTIME = "runtime"
|
||||
|
||||
var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
Configs: map[string]*ice.Config{
|
||||
RUNTIME: {Name: "runtime", Help: "运行环境", Value: kit.Dict()},
|
||||
@ -50,10 +47,6 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
m.Conf(RUNTIME, "host.GOOS", runtime.GOOS)
|
||||
m.Conf(RUNTIME, "host.pid", os.Getpid())
|
||||
|
||||
n := kit.Int(kit.Select("20", m.Conf(RUNTIME, "host.GOMAXPROCS")))
|
||||
m.Logs("host", "gomaxprocs", n)
|
||||
runtime.GOMAXPROCS(n)
|
||||
|
||||
// 启动信息
|
||||
if user, e := user.Current(); e == nil {
|
||||
m.Conf(RUNTIME, "boot.username", path.Base(kit.Select(user.Name, os.Getenv("USER"))))
|
||||
@ -69,6 +62,9 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
name = ls[len(ls)-1]
|
||||
m.Conf(RUNTIME, "boot.pathname", name)
|
||||
}
|
||||
UserName = m.Conf(RUNTIME, "boot.username")
|
||||
HostName = m.Conf(RUNTIME, "boot.hostname")
|
||||
PathName = m.Conf(RUNTIME, "boot.pathname")
|
||||
|
||||
// 启动记录
|
||||
count := m.Confi(RUNTIME, "boot.count") + 1
|
||||
@ -76,14 +72,12 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
|
||||
// 节点信息
|
||||
m.Conf(RUNTIME, "node.time", m.Time())
|
||||
m.Conf(RUNTIME, "node.type", "worker")
|
||||
m.Conf(RUNTIME, "node.name", m.Conf(RUNTIME, "boot.pathname"))
|
||||
NodeInfo(m, "worker", m.Conf(RUNTIME, "boot.pathname"))
|
||||
m.Info("runtime %v", kit.Formats(m.Confv(RUNTIME)))
|
||||
|
||||
UserName = m.Conf(RUNTIME, "boot.username")
|
||||
HostName = m.Conf(RUNTIME, "boot.hostname")
|
||||
PathName = m.Conf(RUNTIME, "boot.pathname")
|
||||
NodeName = m.Conf(RUNTIME, "node.nodename")
|
||||
n := kit.Int(kit.Select("20", m.Conf(RUNTIME, "host.GOMAXPROCS")))
|
||||
m.Logs("host", "gomaxprocs", n)
|
||||
runtime.GOMAXPROCS(n)
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Save(RUNTIME, SYSTEM)
|
||||
@ -92,9 +86,9 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
RUNTIME: {Name: "runtime", Help: "运行环境", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch kit.Select("", arg, 0) {
|
||||
case "hostname":
|
||||
HostName = arg[1]
|
||||
m.Conf(RUNTIME, "boot.hostname", arg[1])
|
||||
m.Echo(m.Conf(RUNTIME, "boot.hostname"))
|
||||
HostName = arg[1]
|
||||
m.Echo(HostName)
|
||||
default:
|
||||
m.Cmdy(ctx.CONFIG, RUNTIME, arg)
|
||||
}
|
||||
|
@ -36,15 +36,13 @@ func _daemon_show(m *ice.Message, cmd *exec.Cmd, out, err string) {
|
||||
kit.MDB_TYPE, "shell", kit.MDB_NAME, cmd.Process.Pid, kit.MDB_TEXT, strings.Join(cmd.Args, " "),
|
||||
kit.MDB_EXTRA, kit.Dict(
|
||||
kit.MDB_STATUS, StatusStart,
|
||||
CMD_STDOUT, out,
|
||||
CMD_STDERR, err,
|
||||
CMD_STDOUT, out, CMD_STDERR, err,
|
||||
),
|
||||
))
|
||||
m.Log_EXPORT(kit.MDB_META, DAEMON, kit.MDB_KEY, h, kit.MDB_PID, cmd.Process.Pid)
|
||||
m.Echo("%d", cmd.Process.Pid)
|
||||
|
||||
m.Gos(m, func(m *ice.Message) {
|
||||
defer m.Cost("%v exit: %v", cmd.Args, 0)
|
||||
if e := cmd.Wait(); e != nil {
|
||||
m.Warn(e != nil, "%v wait: %s", cmd.Args, e)
|
||||
m.Richs(DAEMON, nil, h, func(key string, value map[string]interface{}) {
|
||||
@ -52,6 +50,7 @@ func _daemon_show(m *ice.Message, cmd *exec.Cmd, out, err string) {
|
||||
kit.Value(value, kit.Keys(kit.MDB_EXTRA, kit.MDB_ERROR), e)
|
||||
})
|
||||
} else {
|
||||
m.Cost("%v exit: %v", cmd.Args, cmd.ProcessState.ExitCode())
|
||||
m.Richs(DAEMON, nil, h, func(key string, value map[string]interface{}) {
|
||||
kit.Value(value, kit.Keys(kit.MDB_EXTRA, kit.MDB_STATUS), StatusClose)
|
||||
})
|
||||
@ -59,10 +58,8 @@ func _daemon_show(m *ice.Message, cmd *exec.Cmd, out, err string) {
|
||||
})
|
||||
}
|
||||
|
||||
func Daemon(m *ice.Message, key string, arg ...string) {
|
||||
cmd := exec.Command(key, arg...)
|
||||
_daemon_show(m, cmd, m.Option(CMD_STDOUT), m.Option(CMD_STDERR))
|
||||
}
|
||||
const DAEMON = "daemon"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
|
@ -1,12 +1,12 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"fmt"
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const PYTHON = "python"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
@ -22,7 +22,7 @@ func init() {
|
||||
}},
|
||||
"qrcode": {Name: "qrcode text color", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
prefix := []string{SYSTEM, m.Conf(PYTHON, kit.Keys(kit.MDB_META, PYTHON))}
|
||||
m.Cmdy(prefix, "-c", fmt.Sprintf(m.Conf(PYTHON, "meta.qrcode"),
|
||||
m.Cmdy(prefix, "-c", kit.Format(m.Conf(PYTHON, "meta.qrcode"),
|
||||
kit.Select("hello world", arg, 0), kit.Select("blue", arg, 1)))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
@ -1,8 +1,8 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
"bytes"
|
||||
"fmt"
|
||||
@ -18,8 +18,8 @@ const (
|
||||
CMD_DIR = "cmd_dir"
|
||||
CMD_ENV = "cmd_env"
|
||||
|
||||
CMD_ERR = "cmd_err"
|
||||
CMD_OUT = "cmd_out"
|
||||
CMD_ERR = "cmd_err"
|
||||
CMD_CODE = "cmd_code"
|
||||
)
|
||||
|
||||
@ -43,10 +43,8 @@ func _system_show(m *ice.Message, cmd *exec.Cmd) {
|
||||
m.Echo(out.String())
|
||||
}
|
||||
|
||||
func System(m *ice.Message, key string, arg ...string) {
|
||||
cmd := exec.Command(key, arg...)
|
||||
_system_show(m, cmd)
|
||||
}
|
||||
const SYSTEM = "system"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
|
@ -14,19 +14,16 @@ func _command_list(m *ice.Message, all bool, name string) {
|
||||
p = ice.Pulse
|
||||
}
|
||||
|
||||
if strings.Contains(name, ".") {
|
||||
if name != "" {
|
||||
p.Search(name, func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||
m.Push("key", s.Cap(ice.CTX_FOLLOW))
|
||||
m.Push("name", kit.Format(cmd.Name))
|
||||
m.Push("help", kit.Simple(cmd.Help)[0])
|
||||
if name != "" {
|
||||
m.Push("meta", kit.Format(cmd.Meta))
|
||||
if len(cmd.List) == 0 {
|
||||
_command_make(m, cmd)
|
||||
}
|
||||
m.Push("list", kit.Format(cmd.List))
|
||||
m.Push("meta", kit.Format(cmd.Meta))
|
||||
if len(cmd.List) == 0 {
|
||||
_command_make(m, cmd)
|
||||
}
|
||||
|
||||
m.Push("list", kit.Format(cmd.List))
|
||||
})
|
||||
return
|
||||
}
|
||||
@ -35,9 +32,6 @@ func _command_list(m *ice.Message, all bool, name string) {
|
||||
p.Travel(func(p *ice.Context, s *ice.Context) {
|
||||
list := []string{}
|
||||
for k := range s.Commands {
|
||||
if name != "" && k != name {
|
||||
continue
|
||||
}
|
||||
if k[0] == '/' || k[0] == '_' {
|
||||
// 内部命令
|
||||
continue
|
||||
@ -51,13 +45,11 @@ func _command_list(m *ice.Message, all bool, name string) {
|
||||
m.Push("key", s.Cap(ice.CTX_FOLLOW))
|
||||
m.Push("name", kit.Format(v.Name))
|
||||
m.Push("help", kit.Simple(v.Help)[0])
|
||||
if name != "" {
|
||||
m.Push("meta", kit.Format(v.Meta))
|
||||
if len(v.List) == 0 {
|
||||
_command_make(m, v)
|
||||
}
|
||||
m.Push("list", kit.Format(v.List))
|
||||
m.Push("meta", kit.Format(v.Meta))
|
||||
if len(v.List) == 0 {
|
||||
_command_make(m, v)
|
||||
}
|
||||
m.Push("list", kit.Format(v.List))
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -72,29 +64,30 @@ func _command_make(m *ice.Message, cmd *ice.Command) {
|
||||
|
||||
button := false
|
||||
for i, v := range list {
|
||||
if i > 0 {
|
||||
switch ls := kit.Split(v, ":="); ls[0] {
|
||||
case "[", "]":
|
||||
case "auto":
|
||||
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "查看", "value", "auto")...)
|
||||
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "返回", "value", "Last")...)
|
||||
button = true
|
||||
default:
|
||||
kind, value := "text", ""
|
||||
if len(ls) == 3 {
|
||||
kind, value = ls[1], ls[2]
|
||||
} else if len(ls) == 2 {
|
||||
if strings.Contains(v, "=") {
|
||||
value = ls[1]
|
||||
} else {
|
||||
kind = ls[1]
|
||||
}
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
switch ls := kit.Split(v, ":="); ls[0] {
|
||||
case "[", "]":
|
||||
case "auto":
|
||||
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "查看", "value", "auto")...)
|
||||
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "返回", "value", "Last")...)
|
||||
button = true
|
||||
default:
|
||||
kind, value := "text", ""
|
||||
if len(ls) == 3 {
|
||||
kind, value = ls[1], ls[2]
|
||||
} else if len(ls) == 2 {
|
||||
if strings.Contains(v, "=") {
|
||||
value = ls[1]
|
||||
} else {
|
||||
kind = ls[1]
|
||||
}
|
||||
if kind == "button" {
|
||||
button = true
|
||||
}
|
||||
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, kind, "name", ls[0], "value", value)...)
|
||||
}
|
||||
if kind == "button" {
|
||||
button = true
|
||||
}
|
||||
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, kind, "name", ls[0], "value", value)...)
|
||||
}
|
||||
}
|
||||
if len(cmd.List) == 0 {
|
||||
@ -102,10 +95,12 @@ func _command_make(m *ice.Message, cmd *ice.Command) {
|
||||
}
|
||||
if !button {
|
||||
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "查看")...)
|
||||
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "返回", "value", "Last")...)
|
||||
cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "返回")...)
|
||||
}
|
||||
}
|
||||
|
||||
const COMMAND = "command"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Commands: map[string]*ice.Command{
|
||||
|
@ -16,15 +16,14 @@ func _config_list(m *ice.Message, all bool) {
|
||||
p = ice.Pulse
|
||||
}
|
||||
p.Travel(func(p *ice.Context, s *ice.Context, key string, conf *ice.Config) {
|
||||
m.Push("key", key)
|
||||
m.Push("name", conf.Name)
|
||||
m.Push("value", kit.Format(conf.Value))
|
||||
m.Push(kit.MDB_KEY, key)
|
||||
m.Push(kit.MDB_NAME, conf.Name)
|
||||
m.Push(kit.MDB_VALUE, kit.Format(conf.Value))
|
||||
})
|
||||
|
||||
}
|
||||
func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
msg := m.Spawn(m.Source())
|
||||
// 保存配置
|
||||
name = path.Join(msg.Conf(CONFIG, "meta.path"), name)
|
||||
if f, p, e := kit.Create(name); m.Assert(e) {
|
||||
data := map[string]interface{}{}
|
||||
@ -33,7 +32,7 @@ func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
}
|
||||
if s, e := json.MarshalIndent(data, "", " "); m.Assert(e) {
|
||||
if n, e := f.Write(s); m.Assert(e) {
|
||||
m.Log("info", "save %d %s", n, p)
|
||||
m.Log_EXPORT(CONFIG, name, kit.MDB_FILE, p, kit.MDB_SIZE, n)
|
||||
}
|
||||
}
|
||||
m.Echo(p)
|
||||
@ -41,7 +40,6 @@ func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
}
|
||||
func _config_load(m *ice.Message, name string, arg ...string) {
|
||||
msg := m.Spawn(m.Source())
|
||||
// 加载配置
|
||||
name = path.Join(msg.Conf(CONFIG, "meta.path"), name)
|
||||
if f, e := os.Open(name); e == nil {
|
||||
data := map[string]interface{}{}
|
||||
@ -49,7 +47,7 @@ func _config_load(m *ice.Message, name string, arg ...string) {
|
||||
|
||||
for k, v := range data {
|
||||
msg.Search(k, func(p *ice.Context, s *ice.Context, key string) {
|
||||
m.Log("info", "load %s.%s %v", s.Name, key, kit.Format(v))
|
||||
m.Log_IMPORT(CONFIG, kit.Keys(s.Name, key), kit.MDB_FILE, name)
|
||||
s.Configs[key].Value = v
|
||||
})
|
||||
}
|
||||
@ -80,10 +78,12 @@ func _config_grow(m *ice.Message, name string, key string, arg ...string) {
|
||||
m.Grow(name, key, kit.Dict(arg))
|
||||
}
|
||||
|
||||
const CONFIG = "config"
|
||||
const (
|
||||
CONTEXT = "context"
|
||||
COMMAND = "command"
|
||||
CONFIG = "config"
|
||||
SAVE = "save"
|
||||
LOAD = "load"
|
||||
RICH = "rich"
|
||||
GROW = "grow"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -92,24 +92,25 @@ func init() {
|
||||
CONFIG: {Name: "config", Help: "配置", Value: kit.Data("path", "var/conf")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
CONFIG: {Name: "config [all] [chain [key [arg...]]]", Help: "配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
CONFIG: {Name: "config [all] [chain [key [arg...]]]", Help: "配置", Action: map[string]*ice.Action{
|
||||
SAVE: {Name: "save", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
||||
_config_save(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
LOAD: {Name: "load", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
_config_load(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
RICH: {Name: "rich", Help: "富有", Hand: func(m *ice.Message, arg ...string) {
|
||||
_config_rich(m, arg[0], arg[1], arg[2:]...)
|
||||
}},
|
||||
GROW: {Name: "grow", Help: "成长", Hand: func(m *ice.Message, arg ...string) {
|
||||
_config_grow(m, arg[0], arg[1], arg[2:]...)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if all, arg := _parse_arg_all(m, arg...); len(arg) == 0 {
|
||||
_config_list(m, all)
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "save":
|
||||
_config_save(m, arg[1], arg[2:]...)
|
||||
case "load":
|
||||
_config_load(m, arg[1], arg[2:]...)
|
||||
case "grow":
|
||||
_config_grow(m, arg[1], arg[2], arg[3:]...)
|
||||
case "rich":
|
||||
_config_rich(m, arg[1], arg[2], arg[3:]...)
|
||||
default:
|
||||
_config_make(m, arg[0], arg[1:]...)
|
||||
}
|
||||
_config_make(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
},
|
||||
}, nil)
|
||||
|
@ -24,13 +24,15 @@ func _context_list(m *ice.Message, all bool) {
|
||||
} else {
|
||||
m.Push("ups", "shy")
|
||||
}
|
||||
m.Push("name", s.Name)
|
||||
m.Push(kit.MDB_NAME, s.Name)
|
||||
m.Push(ice.CTX_STATUS, s.Cap(ice.CTX_STATUS))
|
||||
m.Push(ice.CTX_STREAM, s.Cap(ice.CTX_STREAM))
|
||||
m.Push("help", s.Help)
|
||||
})
|
||||
}
|
||||
|
||||
const CONTEXT = "context"
|
||||
|
||||
var Index = &ice.Context{Name: "ctx", Help: "配置模块",
|
||||
Commands: map[string]*ice.Command{
|
||||
CONTEXT: {Name: "context [all] [name [command|config arg...]]", Help: "模块", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
@ -45,9 +47,9 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
|
||||
m.Search(arg[0]+".", func(p *ice.Context, s *ice.Context, key string) {
|
||||
msg := m.Spawn(s)
|
||||
switch arg[1] {
|
||||
case "command":
|
||||
case COMMAND:
|
||||
msg.Cmdy(COMMAND, arg[0], arg[2:])
|
||||
case "config":
|
||||
case CONFIG:
|
||||
msg.Cmdy(CONFIG, arg[2:])
|
||||
}
|
||||
m.Copy(msg)
|
||||
|
@ -71,16 +71,6 @@ func (f *Frame) Close(m *ice.Message, arg ...string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
const (
|
||||
SIGNAL = "signal"
|
||||
TIMER = "timer"
|
||||
EVENT = "event"
|
||||
)
|
||||
|
||||
const (
|
||||
LISTEN = "listen"
|
||||
ACTION = "action"
|
||||
)
|
||||
const (
|
||||
SYSTEM_INIT = "system.init"
|
||||
|
||||
@ -96,6 +86,16 @@ const (
|
||||
MISS_CREATE = "miss.create"
|
||||
MIND_CREATE = "mind.create"
|
||||
)
|
||||
const (
|
||||
LISTEN = "listen"
|
||||
ACTION = "action"
|
||||
)
|
||||
const (
|
||||
SIGNAL = "signal"
|
||||
TIMER = "timer"
|
||||
EVENT = "event"
|
||||
DEBUG = "debug"
|
||||
)
|
||||
|
||||
var Index = &ice.Context{Name: "gdb", Help: "事件模块",
|
||||
Configs: map[string]*ice.Config{
|
||||
@ -125,8 +125,8 @@ var Index = &ice.Context{Name: "gdb", Help: "事件模块",
|
||||
if f, ok := m.Target().Server().(*Frame); ok {
|
||||
// 注册信号
|
||||
f.s = make(chan os.Signal, ice.MOD_CHAN)
|
||||
m.Richs(SIGNAL, nil, "*", func(key string, value string) {
|
||||
m.Logs(LISTEN, key, "cmd", value)
|
||||
m.Richs(SIGNAL, nil, kit.MDB_FOREACH, func(key string, value string) {
|
||||
m.Logs(LISTEN, key, value)
|
||||
signal.Notify(f.s, syscall.Signal(kit.Int(key)))
|
||||
})
|
||||
// 启动心跳
|
||||
@ -160,6 +160,19 @@ var Index = &ice.Context{Name: "gdb", Help: "事件模块",
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
|
||||
EVENT: {Name: "event", Help: "触发器", Action: map[string]*ice.Action{
|
||||
LISTEN: {Name: "listen event cmd...", Help: "监听事件", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Grow(EVENT, arg[0], kit.Dict("cmd", arg[1:]))
|
||||
m.Logs(LISTEN, arg[0], arg[1:])
|
||||
}},
|
||||
ACTION: {Name: "action event arg...", Help: "触发事件", Hand: func(m *ice.Message, arg ...string) {
|
||||
if f, ok := m.Target().Server().(*Frame); ok {
|
||||
m.Logs(ACTION, arg[0], arg[1:])
|
||||
f.d <- arg
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
|
||||
DEBUG: {Name: "debug", Help: "调试器", Action: map[string]*ice.Action{
|
||||
LISTEN: {Name: "listen event cmd...", Help: "监听事件", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Grow(EVENT, arg[0], kit.Dict("cmd", arg[1:]))
|
||||
m.Logs(LISTEN, arg[0], "cmd", arg[1:])
|
||||
@ -171,9 +184,7 @@ var Index = &ice.Context{Name: "gdb", Help: "事件模块",
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
|
||||
"void": {Name: "void", Help: "空命令", Action: map[string]*ice.Action{}},
|
||||
},
|
||||
}
|
||||
|
||||
func init() { ice.Index.Register(Index, &Frame{}) }
|
||||
func init() { ice.Index.Register(Index, &Frame{}, SIGNAL, TIMER, EVENT, DEBUG) }
|
||||
|
@ -32,9 +32,11 @@ func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
|
||||
}
|
||||
func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||
for {
|
||||
if l, ok := <-f.p; !ok {
|
||||
break
|
||||
} else {
|
||||
select {
|
||||
case l, ok := <-f.p:
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
// 日志文件
|
||||
file := kit.Select("bench", m.Conf("show", kit.Keys(l.l, "file")))
|
||||
// 日志格式
|
||||
|
@ -2,7 +2,6 @@ package mdb
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/toolkits"
|
||||
"github.com/shylinux/toolkits/task"
|
||||
|
||||
@ -12,10 +11,14 @@ import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
func _story_catch(m *ice.Message, kind, file string) {
|
||||
m.Cmdy("web.story", "catch", CSV, file)
|
||||
}
|
||||
|
||||
func _list_import(m *ice.Message, prefix, key, file string) {
|
||||
f, e := os.Open(file)
|
||||
m.Assert(e)
|
||||
defer m.Cmdy(web.STORY, web.CATCH, CSV, file)
|
||||
defer _story_catch(m, CSV, file)
|
||||
defer f.Close()
|
||||
|
||||
r := csv.NewReader(f)
|
||||
@ -46,7 +49,7 @@ func _list_import(m *ice.Message, prefix, key, file string) {
|
||||
func _list_export(m *ice.Message, prefix, key, file string) {
|
||||
f, p, e := kit.Create(kit.Keys(file, CSV))
|
||||
m.Assert(e)
|
||||
defer m.Cmdy(web.STORY, web.CATCH, CSV, p)
|
||||
defer _story_catch(m, CSV, p)
|
||||
defer f.Close()
|
||||
|
||||
w := csv.NewWriter(f)
|
||||
@ -120,7 +123,7 @@ func _hash_search(m *ice.Message, prefix, key, field, value string) {
|
||||
func _hash_import(m *ice.Message, prefix, key, file string) {
|
||||
f, e := os.Open(file)
|
||||
m.Assert(e)
|
||||
defer m.Cmdy(web.STORY, web.CATCH, JSON, file)
|
||||
defer _story_catch(m, JSON, file)
|
||||
defer f.Close()
|
||||
|
||||
list := map[string]interface{}{}
|
||||
@ -138,7 +141,7 @@ func _hash_import(m *ice.Message, prefix, key, file string) {
|
||||
func _hash_export(m *ice.Message, prefix, key, file string) {
|
||||
f, p, e := kit.Create(kit.Keys(file, JSON))
|
||||
m.Assert(e)
|
||||
defer m.Cmdy(web.STORY, web.CATCH, JSON, p)
|
||||
defer _story_catch(m, JSON, p)
|
||||
defer f.Close()
|
||||
|
||||
en := json.NewEncoder(f)
|
||||
@ -149,7 +152,7 @@ func _hash_export(m *ice.Message, prefix, key, file string) {
|
||||
func _dict_import(m *ice.Message, prefix, key, file string) {
|
||||
f, e := os.Open(file)
|
||||
m.Assert(e)
|
||||
m.Cmdy(web.STORY, web.CATCH, JSON, file)
|
||||
defer _story_catch(m, JSON, file)
|
||||
defer f.Close()
|
||||
|
||||
data := map[string]interface{}{}
|
||||
@ -167,7 +170,7 @@ func _dict_import(m *ice.Message, prefix, key, file string) {
|
||||
func _dict_export(m *ice.Message, prefix, key, file string) {
|
||||
f, p, e := kit.Create(kit.Keys(file, JSON))
|
||||
m.Assert(e)
|
||||
defer m.Cmdy(web.STORY, web.CATCH, JSON, p)
|
||||
defer _story_catch(m, JSON, p)
|
||||
defer f.Close()
|
||||
|
||||
en := json.NewEncoder(f)
|
||||
@ -187,10 +190,20 @@ const (
|
||||
LIST = "list"
|
||||
)
|
||||
const (
|
||||
CREATE = "create"
|
||||
RENAME = "rename"
|
||||
REMOVE = "remove"
|
||||
COMMIT = "commit"
|
||||
IMPORT = "import"
|
||||
EXPORT = "export"
|
||||
|
||||
INSERT = "insert"
|
||||
DELETE = "delete"
|
||||
SELECT = "select"
|
||||
SEARCH = "search"
|
||||
MODIFY = "modify"
|
||||
|
||||
PARSER = "parser"
|
||||
ADVISE = "advise"
|
||||
)
|
||||
|
||||
var Index = &ice.Context{Name: "mdb", Help: "数据模块",
|
||||
@ -225,17 +238,9 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
|
||||
_list_select(m, arg[0], arg[1], kit.Select("10", arg, 3), kit.Select("0", arg, 4), kit.Select("", arg, 5), kit.Select("", arg, 6))
|
||||
}
|
||||
}},
|
||||
SEARCH: {Name: "search conf key type key value", Help: "数据查询", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[2] {
|
||||
case LIST:
|
||||
_list_search(m, arg[0], arg[1], arg[3], arg[4])
|
||||
case HASH:
|
||||
_hash_search(m, arg[0], arg[1], arg[3], arg[4])
|
||||
}
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
ice.Index.Register(Index, nil, IMPORT, EXPORT, SELECT, SEARCH)
|
||||
ice.Index.Register(Index, nil, IMPORT, EXPORT, SELECT, SEARCH, RENDER)
|
||||
}
|
||||
|
26
base/mdb/render.go
Normal file
26
base/mdb/render.go
Normal file
@ -0,0 +1,26 @@
|
||||
package mdb
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const RENDER = "render"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
RENDER: {Name: "render", Help: "渲染引擎", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TYPE)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
RENDER: {Name: "search type name text arg...", Help: "渲染引擎", Action: map[string]*ice.Action{
|
||||
CREATE: {Name: "create type name [text]", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Rich(RENDER, nil, kit.Dict(kit.MDB_TYPE, arg[0], kit.MDB_NAME, arg[1], kit.MDB_TEXT, kit.Select("", arg, 2)))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs(RENDER, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), RENDER, arg[0], arg[1], kit.Select("", arg, 2))
|
||||
})
|
||||
}},
|
||||
}}, nil)
|
||||
}
|
178
base/mdb/search.go
Normal file
178
base/mdb/search.go
Normal file
@ -0,0 +1,178 @@
|
||||
package mdb
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/toolkits"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const SEARCH = "search"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
SEARCH: {Name: "search", Help: "搜索引擎", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TYPE)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
SEARCH: {Name: "search word type...", Help: "搜索引擎", Action: map[string]*ice.Action{
|
||||
CREATE: {Name: "create type name [text]", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Rich(SEARCH, nil, kit.Dict(kit.MDB_TYPE, arg[0], kit.MDB_NAME, arg[1], kit.MDB_TEXT, kit.Select("", arg, 2)))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
||||
if strings.Contains(arg[0], ";") {
|
||||
arg = strings.Split(arg[0], ";")
|
||||
}
|
||||
if len(arg) > 2 {
|
||||
for _, k := range strings.Split(arg[2], ",") {
|
||||
m.Richs(SEARCH, nil, k, func(key string, value map[string]interface{}) {
|
||||
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, value[kit.MDB_TYPE], arg[0], kit.Select("", arg, 1))
|
||||
})
|
||||
}
|
||||
} else {
|
||||
m.Richs(SEARCH, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, value[kit.MDB_TYPE], arg[0], kit.Select("", arg, 1))
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
if len(arg) < 2 {
|
||||
m.Cmdy("web.label", arg)
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "add":
|
||||
if m.Richs(cmd, nil, arg[1], nil) == nil {
|
||||
m.Rich(cmd, nil, kit.Data(kit.MDB_NAME, arg[1]))
|
||||
}
|
||||
m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) {
|
||||
m.Grow(cmd, kit.Keys(kit.MDB_HASH, key), kit.Dict(
|
||||
kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3:],
|
||||
))
|
||||
})
|
||||
case "get":
|
||||
wg := &sync.WaitGroup{}
|
||||
m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) {
|
||||
wg.Add(1)
|
||||
m.Gos(m, func(m *ice.Message) {
|
||||
m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
m.Cmdy(value[kit.MDB_TEXT], arg[2:])
|
||||
})
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
wg.Wait()
|
||||
case "set":
|
||||
if arg[1] != "" {
|
||||
m.Cmdy("web.space", arg[1], "web.chat.search", "set", "", arg[2:])
|
||||
break
|
||||
}
|
||||
|
||||
m.Richs(cmd, nil, arg[2], func(key string, value map[string]interface{}) {
|
||||
m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
m.Cmdy(value[kit.MDB_TEXT], "set", arg[3:])
|
||||
})
|
||||
})
|
||||
default:
|
||||
if len(arg) < 4 {
|
||||
m.Richs(cmd, nil, kit.Select(kit.MDB_FOREACH, arg, 2), func(key string, val map[string]interface{}) {
|
||||
if len(arg) < 3 {
|
||||
m.Push(key, val[kit.MDB_META], []string{kit.MDB_TIME, kit.MDB_NAME, kit.MDB_COUNT})
|
||||
return
|
||||
}
|
||||
m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
m.Push("", value, []string{kit.MDB_TIME})
|
||||
m.Push("group", arg[2])
|
||||
m.Push("", value, []string{kit.MDB_NAME, kit.MDB_TEXT})
|
||||
})
|
||||
})
|
||||
break
|
||||
}
|
||||
m.Option("pod", "")
|
||||
m.Cmdy("web.label", arg[0], arg[1], "web.chat.search", "get", arg[2:])
|
||||
m.Sort("time", "time_r")
|
||||
}
|
||||
}},
|
||||
"commend": {Name: "commend label pod engine work auto", Help: "推荐引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) < 2 {
|
||||
m.Cmdy("web.label", arg)
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "add":
|
||||
if m.Richs(cmd, nil, arg[1], nil) == nil {
|
||||
m.Rich(cmd, nil, kit.Data(kit.MDB_NAME, arg[1]))
|
||||
}
|
||||
m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) {
|
||||
m.Grow(cmd, kit.Keys(kit.MDB_HASH, key), kit.Dict(
|
||||
kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3:],
|
||||
))
|
||||
})
|
||||
case "get":
|
||||
wg := &sync.WaitGroup{}
|
||||
m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) {
|
||||
wg.Add(1)
|
||||
m.Gos(m, func(m *ice.Message) {
|
||||
m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
m.Cmdy(value[kit.MDB_TEXT], arg[2:])
|
||||
})
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
m.Sort("time", "time_r")
|
||||
wg.Wait()
|
||||
case "set":
|
||||
if arg[1] != "" {
|
||||
m.Cmdy("web.space", arg[1], "web.chat.commend", "set", "", arg[2:])
|
||||
break
|
||||
}
|
||||
|
||||
if m.Richs(cmd, "meta.user", m.Option(ice.MSG_USERNAME), nil) == nil {
|
||||
m.Rich(cmd, "meta.user", kit.Dict(
|
||||
kit.MDB_NAME, m.Option(ice.MSG_USERNAME),
|
||||
))
|
||||
}
|
||||
switch m.Option("_action") {
|
||||
case "喜欢":
|
||||
m.Richs(cmd, "meta.user", m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
|
||||
m.Grow(cmd, kit.Keys("meta.user", kit.MDB_HASH, key, "like"), kit.Dict(
|
||||
kit.MDB_EXTRA, kit.Dict("engine", arg[2], "favor", arg[3], "id", arg[4]),
|
||||
kit.MDB_TYPE, arg[5], kit.MDB_NAME, arg[6], kit.MDB_TEXT, arg[7],
|
||||
))
|
||||
})
|
||||
case "讨厌":
|
||||
m.Richs(cmd, "meta.user", m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
|
||||
m.Grow(cmd, kit.Keys("meta.user", kit.MDB_HASH, key, "hate"), kit.Dict(
|
||||
kit.MDB_EXTRA, kit.Dict("engine", arg[2], "favor", arg[3], "id", arg[4]),
|
||||
kit.MDB_TYPE, arg[5], kit.MDB_NAME, arg[6], kit.MDB_TEXT, arg[7],
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
m.Richs(cmd, nil, arg[2], func(key string, value map[string]interface{}) {
|
||||
m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
m.Cmdy(value[kit.MDB_TEXT], "set", arg[3:])
|
||||
})
|
||||
})
|
||||
default:
|
||||
if len(arg) == 2 {
|
||||
m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value)
|
||||
})
|
||||
break
|
||||
}
|
||||
if len(arg) == 3 {
|
||||
m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value)
|
||||
})
|
||||
break
|
||||
}
|
||||
m.Cmdy("web.label", arg[0], arg[1], "web.chat.commend", "get", arg[2:])
|
||||
// m.Cmdy("web.chat.commend", "get", arg[2:])
|
||||
}
|
||||
}},
|
||||
}}, nil)
|
||||
}
|
@ -18,10 +18,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
FILE = "file"
|
||||
)
|
||||
|
||||
func _file_list(m *ice.Message, root string, name string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) {
|
||||
if fs, e := ioutil.ReadDir(path.Join(root, name)); e != nil {
|
||||
if f, e := os.Open(path.Join(root, name)); e == nil {
|
||||
@ -157,7 +153,7 @@ func _file_save(m *ice.Message, name string, text ...string) {
|
||||
defer f.Close()
|
||||
for _, v := range text {
|
||||
if n, e := f.WriteString(v); m.Assert(e) {
|
||||
m.Log_IMPORT(kit.MDB_FILE, p, kit.MDB_SIZE, n)
|
||||
m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_SIZE, n)
|
||||
}
|
||||
}
|
||||
m.Echo(p)
|
||||
@ -177,11 +173,11 @@ func _file_copy(m *ice.Message, name string, from ...string) {
|
||||
}
|
||||
}
|
||||
func _file_link(m *ice.Message, name string, from string) {
|
||||
m.Cmd("nfs.trash", name)
|
||||
_file_trash(m, name)
|
||||
os.MkdirAll(path.Dir(name), 0760)
|
||||
os.Link(from, name)
|
||||
}
|
||||
func _file_trash(m *ice.Message, name string, from ...string) {
|
||||
func _file_trash(m *ice.Message, name string) {
|
||||
if s, e := os.Stat(name); e == nil {
|
||||
if s.IsDir() {
|
||||
name := path.Base(name) + ".tar.gz"
|
||||
@ -192,15 +188,40 @@ func _file_trash(m *ice.Message, name string, from ...string) {
|
||||
defer f.Close()
|
||||
|
||||
h := kit.Hashs(f)
|
||||
p := path.Join(m.Conf("trash", "meta.path"), h[:2], h)
|
||||
p := path.Join(m.Conf(TRASH, "meta.path"), h[:2], h)
|
||||
os.MkdirAll(path.Dir(p), 0777)
|
||||
os.Rename(name, p)
|
||||
|
||||
m.Cmd("web.favor", "trash", "bin", name, p)
|
||||
m.Cmd("web.favor", TRASH, "bin", name, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func _file_search(m *ice.Message, kind, name, text string, arg ...string) {
|
||||
if kind == FILE {
|
||||
msg := m.Spawn()
|
||||
rg, e := regexp.Compile("")
|
||||
m.Assert(e)
|
||||
_file_list(msg, "./", "", 0, true, "both", rg, []string{"path", "time", "size"})
|
||||
msg.Table(func(index int, value map[string]string, head []string) {
|
||||
if !strings.Contains(value["path"], name) {
|
||||
return
|
||||
}
|
||||
m.Push("pod", "")
|
||||
m.Push("ctx", "nfs")
|
||||
m.Push("cmd", FILE)
|
||||
m.Push(kit.MDB_TIME, value["time"])
|
||||
m.Push(kit.MDB_SIZE, value["size"])
|
||||
m.Push(kit.MDB_TYPE, FILE)
|
||||
m.Push(kit.MDB_NAME, value["path"])
|
||||
m.Push(kit.MDB_TEXT, "")
|
||||
})
|
||||
}
|
||||
}
|
||||
func _file_render(m *ice.Message, kind, name, text string, arg ...string) {
|
||||
_file_show(m, name)
|
||||
}
|
||||
|
||||
const (
|
||||
DIR = "dir"
|
||||
CAT = "cat"
|
||||
@ -208,6 +229,8 @@ const (
|
||||
COPY = "copy"
|
||||
LINK = "link"
|
||||
TRASH = "trash"
|
||||
|
||||
FILE = "file"
|
||||
)
|
||||
|
||||
var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
||||
@ -215,6 +238,21 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
||||
TRASH: {Name: "trash", Help: "删除", Value: kit.Data("path", "var/trash")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd("mdb.search", "create", "file", "file", "nfs")
|
||||
m.Cmd("mdb.render", "create", "file", "file", "nfs")
|
||||
}},
|
||||
|
||||
FILE: {Name: "file", Help: "文件", Action: map[string]*ice.Action{
|
||||
"search": {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
_file_search(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||
}},
|
||||
"render": {Name: "render type name text", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||
_file_render(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}},
|
||||
|
||||
DIR: {Name: "dir path field...", Help: "目录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
rg, _ := regexp.Compile(m.Option("dir_reg"))
|
||||
_file_list(m, kit.Select("./", m.Option("dir_root")), kit.Select("", arg, 0),
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
@ -31,7 +32,7 @@ type Frame struct {
|
||||
}
|
||||
|
||||
func Render(msg *ice.Message, cmd string, args ...interface{}) {
|
||||
defer func() { msg.Log_EXPORT(kit.MDB_RENDER, cmd, kit.MDB_TEXT, args) }()
|
||||
defer func() { msg.Log_EXPORT(mdb.RENDER, cmd, kit.MDB_TEXT, args) }()
|
||||
|
||||
switch arg := kit.Simple(args...); cmd {
|
||||
case ice.RENDER_OUTPUT:
|
||||
@ -272,7 +273,6 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||
f.target = m.Target()
|
||||
aaa.UserRoot(m)
|
||||
default:
|
||||
|
||||
if s, e := os.Open(arg[0]); !m.Warn(e != nil, "%s", e) {
|
||||
defer s.Close()
|
||||
|
||||
|
@ -12,12 +12,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Frame struct{}
|
||||
|
||||
const (
|
||||
GETPORT = "getport"
|
||||
)
|
||||
|
||||
func _ip_list(m *ice.Message, ifname string) {
|
||||
if ifs, e := net.Interfaces(); m.Assert(e) {
|
||||
for _, v := range ifs {
|
||||
@ -58,18 +52,20 @@ func _ip_islocal(m *ice.Message, ip string) (ok bool) {
|
||||
})
|
||||
return ok
|
||||
}
|
||||
func _tcp_port(m *ice.Message) string {
|
||||
current := kit.Int(m.Conf(GETPORT, "meta.current"))
|
||||
end := kit.Int(m.Conf(GETPORT, "meta.end"))
|
||||
func _port_list(m *ice.Message) string {
|
||||
return ""
|
||||
}
|
||||
func _port_get(m *ice.Message) string {
|
||||
current := kit.Int(m.Conf(PORT, "meta.current"))
|
||||
end := kit.Int(m.Conf(PORT, "meta.end"))
|
||||
if current >= end {
|
||||
current = kit.Int(m.Conf(GETPORT, "meta.begin"))
|
||||
current = kit.Int(m.Conf(PORT, "meta.begin"))
|
||||
}
|
||||
for i := current; i < end; i++ {
|
||||
if m.Cmd(cli.SYSTEM, "lsof", "-i", kit.Format(":%d", i)).Append(cli.CMD_CODE) != "0" {
|
||||
m.Conf(GETPORT, "meta.current", i)
|
||||
m.Log_CREATE(GETPORT, i)
|
||||
m.Conf(PORT, "meta.current", i)
|
||||
m.Log_CREATE(PORT, i)
|
||||
return kit.Format("%d", i)
|
||||
break
|
||||
}
|
||||
}
|
||||
return ""
|
||||
@ -78,52 +74,33 @@ func _tcp_port(m *ice.Message) string {
|
||||
func IPIsLocal(m *ice.Message, ip string) bool {
|
||||
return _ip_islocal(m, ip)
|
||||
}
|
||||
func TCPPort(m *ice.Message) string {
|
||||
return _tcp_port(m)
|
||||
}
|
||||
|
||||
const (
|
||||
IP = "ip"
|
||||
PORT = "port"
|
||||
)
|
||||
|
||||
var Index = &ice.Context{Name: "tcp", Help: "通信模块",
|
||||
Caches: map[string]*ice.Cache{},
|
||||
Configs: map[string]*ice.Config{
|
||||
GETPORT: &ice.Config{Name: "getport", Help: "分配端口", Value: kit.Data(
|
||||
PORT: &ice.Config{Name: "port", Help: "端口", Value: kit.Data(
|
||||
"begin", 10000, "current", 10000, "end", 20000,
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(GETPORT) }},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(PORT) }},
|
||||
|
||||
"ifconfig": {Name: "ifconfig [name]", Help: "网络配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
IP: {Name: "ip", Help: "地址", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_ip_list(m, "")
|
||||
}},
|
||||
GETPORT: {Name: "getport", Help: "分配端口", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Echo(_tcp_port(m))
|
||||
PORT: {Name: "port", Help: "端口", Action: map[string]*ice.Action{
|
||||
"get": {Name: "get", Help: "分配端口", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_port_get(m))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_port_list(m)
|
||||
}},
|
||||
|
||||
"ip": {Name: "ifconfig [name]", Help: "网络配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if addr, e := net.InterfaceAddrs(); m.Assert(e) {
|
||||
for _, v := range addr {
|
||||
m.Info("%v", v)
|
||||
}
|
||||
}
|
||||
}},
|
||||
"netstat": {Name: "netstat [name]", Help: "网络配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, "netstat", "-lanp")
|
||||
}},
|
||||
|
||||
"check": {Name: "check addr", Help: "server", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if strings.Contains(arg[0], ".") {
|
||||
switch list := strings.Split(arg[0], ":"); list[0] {
|
||||
case "127.0.0.1":
|
||||
m.Echo("local")
|
||||
}
|
||||
} else {
|
||||
switch list := strings.Split(arg[0], "]:"); strings.TrimPrefix(list[0], "[") {
|
||||
case "::1":
|
||||
m.Echo("local")
|
||||
}
|
||||
}
|
||||
}},
|
||||
"server": {Name: "server [tcp4|tcp6|udp4|udp6] addr", Help: "server", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
proto := "tcp4"
|
||||
switch arg[0] {
|
||||
@ -202,4 +179,4 @@ var Index = &ice.Context{Name: "tcp", Help: "通信模块",
|
||||
},
|
||||
}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil) }
|
||||
func init() { ice.Index.Register(Index, nil, IP, PORT) }
|
||||
|
@ -1,8 +1,9 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/nfs"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -66,34 +67,27 @@ func _cache_save(m *ice.Message, method, kind, name, text string, arg ...string)
|
||||
// 添加记录
|
||||
m.Grow(CACHE, nil, kit.Dict(
|
||||
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
||||
kit.MDB_SIZE, size, "data", h,
|
||||
kit.MDB_SIZE, size, kit.MDB_DATA, h,
|
||||
))
|
||||
|
||||
// 返回结果
|
||||
m.Push("time", m.Time())
|
||||
m.Push("type", kind)
|
||||
m.Push("name", name)
|
||||
m.Push("text", text)
|
||||
m.Push("size", size)
|
||||
m.Push("data", h)
|
||||
m.Push(kit.MDB_TIME, m.Time())
|
||||
m.Push(kit.MDB_TYPE, kind)
|
||||
m.Push(kit.MDB_NAME, name)
|
||||
m.Push(kit.MDB_TEXT, text)
|
||||
m.Push(kit.MDB_SIZE, size)
|
||||
m.Push(kit.MDB_DATA, h)
|
||||
}
|
||||
func _cache_watch(m *ice.Message, key, file string) {
|
||||
if m.Richs(CACHE, nil, key, func(key string, value map[string]interface{}) {
|
||||
if value["file"] == "" {
|
||||
if f, _, e := kit.Create(file); m.Assert(e) {
|
||||
defer f.Close()
|
||||
f.WriteString(kit.Format(value["text"]))
|
||||
}
|
||||
m.Cmdy(nfs.SAVE, file, value["text"])
|
||||
} else {
|
||||
os.MkdirAll(path.Dir(file), 0777)
|
||||
os.Remove(file)
|
||||
os.Link(kit.Format(value["file"]), file)
|
||||
m.Cmdy(nfs.LINK, file, value[kit.MDB_FILE])
|
||||
}
|
||||
}) == nil {
|
||||
m.Cmdy(SPIDE, "dev", "cache", "/cache/"+key)
|
||||
os.MkdirAll(path.Dir(file), 0777)
|
||||
os.Remove(file)
|
||||
os.Link(m.Append("file"), file)
|
||||
m.Cmdy(nfs.LINK, file, m.Append(kit.MDB_FILE))
|
||||
}
|
||||
m.Echo(file)
|
||||
}
|
||||
@ -101,8 +95,8 @@ func _cache_watch(m *ice.Message, key, file string) {
|
||||
func _cache_catch(m *ice.Message, arg ...string) []string {
|
||||
if r, ok := m.Optionv("response").(*http.Response); ok {
|
||||
return _cache_download(m, r, arg...)
|
||||
// } else if m.R != nil {
|
||||
// return _cache_upload(m, arg...)
|
||||
} else if r, ok := m.Optionv("request").(*http.Request); ok {
|
||||
return _cache_upload(m, r, arg...)
|
||||
}
|
||||
|
||||
if f, e := os.Open(arg[2]); m.Assert(e) {
|
||||
@ -123,8 +117,8 @@ func _cache_catch(m *ice.Message, arg ...string) []string {
|
||||
}
|
||||
return arg
|
||||
}
|
||||
func _cache_upload(m *ice.Message, arg ...string) []string {
|
||||
if f, h, e := m.R.FormFile(kit.Select("upload", arg, 1)); e == nil {
|
||||
func _cache_upload(m *ice.Message, r *http.Request, arg ...string) []string {
|
||||
if f, h, e := r.FormFile(kit.Select("upload", arg, 1)); e == nil {
|
||||
defer f.Close()
|
||||
|
||||
// 创建文件
|
||||
@ -161,13 +155,11 @@ func _cache_download(m *ice.Message, r *http.Response, arg ...string) []string {
|
||||
return arg
|
||||
}
|
||||
|
||||
func CacheCatch(m *ice.Message, kind, name string) *ice.Message {
|
||||
arg := _cache_catch(m, "catch", kind, name)
|
||||
_cache_save(m, arg[0], arg[1], arg[2], arg[3], arg[4:]...)
|
||||
return m
|
||||
}
|
||||
|
||||
const CACHE = "cache"
|
||||
const (
|
||||
CATCH = "catch"
|
||||
WATCH = "watch"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
@ -178,13 +170,13 @@ func init() {
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
CACHE: {Name: "cache data=auto auto", Help: "缓存池", Action: map[string]*ice.Action{
|
||||
kit.MDB_CREATE: {Name: "create type name text arg...", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_cache_save(m, "add", arg[0], arg[1], arg[2], arg[3:]...)
|
||||
}},
|
||||
kit.MDB_INSERT: {Name: "insert type name", Help: "插入", Hand: func(m *ice.Message, arg ...string) {
|
||||
arg = _cache_catch(m, arg[0], arg[1])
|
||||
CATCH: {Name: "catch type file", Help: "捕获", Hand: func(m *ice.Message, arg ...string) {
|
||||
arg = _cache_catch(m, "catch", arg[0], arg[1])
|
||||
_cache_save(m, arg[0], arg[1], arg[2], arg[3], arg[4:]...)
|
||||
}},
|
||||
WATCH: {Name: "watch key file", Help: "查看", Hand: func(m *ice.Message, arg ...string) {
|
||||
_cache_watch(m, arg[0], arg[1])
|
||||
}},
|
||||
kit.MDB_SHOW: {Name: "show type name text arg...", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 2 {
|
||||
_cache_show(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||
@ -198,14 +190,12 @@ func init() {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO remove
|
||||
switch arg[0] {
|
||||
case "download", "upload", "catch":
|
||||
case "download", "upload":
|
||||
arg = _cache_catch(m, arg...)
|
||||
fallthrough
|
||||
case "add":
|
||||
_cache_save(m, arg[0], arg[1], arg[2], arg[3], arg[4:]...)
|
||||
case "watch":
|
||||
_cache_watch(m, arg[1], arg[2])
|
||||
default:
|
||||
_cache_list(m, arg[0])
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/gdb"
|
||||
"github.com/shylinux/icebergs/base/nfs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"io/ioutil"
|
||||
@ -14,7 +15,7 @@ import (
|
||||
|
||||
func _dream_list(m *ice.Message) {
|
||||
// 任务列表
|
||||
m.Cmdy("nfs.dir", m.Conf(DREAM, "meta.path"), "time name").Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmdy(nfs.DIR, m.Conf(DREAM, "meta.path"), "time name").Table(func(index int, value map[string]string, head []string) {
|
||||
if m.Richs(SPACE, nil, value[kit.MDB_NAME], func(key string, value map[string]interface{}) {
|
||||
m.Push(kit.MDB_TYPE, value[kit.MDB_TYPE])
|
||||
m.Push(kit.MDB_STATUS, "start")
|
||||
@ -53,7 +54,7 @@ func _dream_show(m *ice.Message, name string) {
|
||||
)
|
||||
m.Cmd(m.Confv(DREAM, "meta.cmd"), "self", name)
|
||||
}
|
||||
m.Cmdy("nfs.dir", p)
|
||||
m.Cmdy(nfs.DIR, p)
|
||||
}
|
||||
|
||||
const DREAM = "dream"
|
||||
|
@ -1,11 +1,13 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"encoding/csv"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func _favor_list(m *ice.Message, zone, id string, fields ...string) {
|
||||
@ -30,8 +32,8 @@ func _favor_list(m *ice.Message, zone, id string, fields ...string) {
|
||||
// 详细信息
|
||||
m.Push("detail", value)
|
||||
m.Optionv("value", value)
|
||||
m.Push(kit.MDB_KEY, kit.MDB_RENDER)
|
||||
m.Push(kit.MDB_VALUE, m.Cmdx(m.Conf(FAVOR, kit.Keys(kit.MDB_META, kit.MDB_RENDER, value[kit.MDB_TYPE]))))
|
||||
m.Push(kit.MDB_KEY, mdb.RENDER)
|
||||
m.Push(kit.MDB_VALUE, m.Cmdx(m.Conf(FAVOR, kit.Keys(kit.MDB_META, mdb.RENDER, value[kit.MDB_TYPE]))))
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -120,6 +122,21 @@ func _favor_commit(m *ice.Message, zone, id string, arg ...string) {
|
||||
})
|
||||
})
|
||||
}
|
||||
func _favor_search(m *ice.Message, kind, name, text string, arg ...string) {
|
||||
m.Richs(FAVOR, nil, kit.Select(kit.MDB_FOREACH, ""), func(key string, val map[string]interface{}) {
|
||||
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
if name != value[kit.MDB_NAME] && !strings.Contains(kit.Format(value[kit.MDB_TEXT]), name) {
|
||||
return
|
||||
}
|
||||
m.Push("pod", m.Option("pod"))
|
||||
m.Push("ctx", "web")
|
||||
m.Push("cmd", "favor")
|
||||
m.Push(key, value, []string{kit.MDB_TIME}, val)
|
||||
m.Push(kit.MDB_SIZE, kit.FmtSize(int64(len(kit.Format(value[kit.MDB_TEXT])))))
|
||||
m.Push(key, value, []string{kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT}, val)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func _favor_modify(m *ice.Message, zone, id, pro, set, old string) {
|
||||
m.Richs(FAVOR, nil, zone, func(key string, val map[string]interface{}) {
|
||||
@ -276,24 +293,27 @@ func init() {
|
||||
FAVOR: {Name: "favor zone=auto id=auto auto", Help: "收藏夹", Meta: kit.Dict(
|
||||
"detail", []string{"编辑", "收藏", "收录", "导出", "删除"},
|
||||
), Action: map[string]*ice.Action{
|
||||
kit.MDB_EXPORT: {Name: "export file", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.EXPORT: {Name: "export file", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
_favor_export(m, kit.Select(_EXPORT, arg, 0))
|
||||
}},
|
||||
kit.MDB_IMPORT: {Name: "import file", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.IMPORT: {Name: "import file", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
_favor_import(m, kit.Select(_EXPORT, arg, 0))
|
||||
}},
|
||||
kit.MDB_CREATE: {Name: "create zone", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.CREATE: {Name: "create zone", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_favor_create(m, arg[0])
|
||||
}},
|
||||
kit.MDB_INSERT: {Name: "insert zone type name text", Help: "插入", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.INSERT: {Name: "insert zone type name text", Help: "插入", Hand: func(m *ice.Message, arg ...string) {
|
||||
_favor_insert(m, arg[0], arg[1], arg[2], kit.Select("", arg, 3))
|
||||
}},
|
||||
kit.MDB_MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||
_favor_modify(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg[0], arg[1], kit.Select("", arg, 2))
|
||||
}},
|
||||
kit.MDB_COMMIT: {Name: "commit arg...", Help: "提交", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.COMMIT: {Name: "commit arg...", Help: "提交", Hand: func(m *ice.Message, arg ...string) {
|
||||
_favor_commit(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg...)
|
||||
}},
|
||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
_favor_search(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||
}},
|
||||
kit.MDB_SHARE: {Name: "share arg...", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
|
||||
_favor_share(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg...)
|
||||
}},
|
||||
|
@ -10,7 +10,7 @@ const PROXY = "proxy"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
PROXY: {Name: "proxy", Help: "代理", Value: kit.Data(kit.MDB_SHORT, "proxy")},
|
||||
PROXY: {Name: "proxy", Help: "代理", Value: kit.Data(kit.MDB_SHORT, PROXY)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
PROXY: {Name: "proxy name cmd auto", Help: "代理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
91
base/web/render.go
Normal file
91
base/web/render.go
Normal file
@ -0,0 +1,91 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"github.com/skip2/go-qrcode"
|
||||
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Count(m *ice.Message, cmd, key, name string) int {
|
||||
count := kit.Int(m.Conf(cmd, kit.Keys(key, name)))
|
||||
m.Conf(cmd, kit.Keys(key, name), count+1)
|
||||
return count
|
||||
}
|
||||
func Format(key string, arg ...interface{}) string {
|
||||
switch args := kit.Simple(arg); key {
|
||||
case "a":
|
||||
return fmt.Sprintf("<a href='%s' target='_blank'>%s</a>", kit.Format(args[0]), kit.Select(kit.Format(args[0]), args, 1))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
const (
|
||||
STATUS = "status"
|
||||
COOKIE = "cookie"
|
||||
)
|
||||
|
||||
func Render(msg *ice.Message, cmd string, args ...interface{}) {
|
||||
if cmd != "" {
|
||||
defer func() { msg.Log(ice.LOG_EXPORT, "%s: %v", cmd, args) }()
|
||||
}
|
||||
switch arg := kit.Simple(args...); cmd {
|
||||
case ice.RENDER_VOID:
|
||||
case ice.RENDER_OUTPUT:
|
||||
case "redirect":
|
||||
http.Redirect(msg.W, msg.R, kit.MergeURL(arg[0], arg[1:]), 307)
|
||||
|
||||
case "refresh":
|
||||
arg = []string{"200", fmt.Sprintf(`<!DOCTYPE html><head><meta charset="utf-8"><meta http-equiv="Refresh" content="%d"></head><body>%s</body>`,
|
||||
kit.Int(kit.Select("3", arg, 0)), kit.Select("请稍后,系统初始化中...", arg, 1),
|
||||
)}
|
||||
fallthrough
|
||||
|
||||
case STATUS:
|
||||
RenderStatus(msg, kit.Int(kit.Select("200", arg, 0)), kit.Select("", arg, 1))
|
||||
|
||||
case COOKIE:
|
||||
RenderCookie(msg, arg[0], arg[1:]...)
|
||||
|
||||
case ice.RENDER_DOWNLOAD:
|
||||
msg.W.Header().Set("Content-Disposition", fmt.Sprintf("filename=%s", kit.Select(path.Base(arg[0]), arg, 2)))
|
||||
msg.W.Header().Set("Content-Type", kit.Select("text/html", arg, 1))
|
||||
http.ServeFile(msg.W, msg.R, arg[0])
|
||||
|
||||
case ice.RENDER_RESULT:
|
||||
if len(arg) > 0 {
|
||||
msg.W.Write([]byte(kit.Format(arg[0], args[1:]...)))
|
||||
} else {
|
||||
args = append(args, "length:", len(msg.Result()))
|
||||
msg.W.Write([]byte(msg.Result()))
|
||||
}
|
||||
|
||||
case ice.RENDER_QRCODE:
|
||||
if qr, e := qrcode.New(arg[0], qrcode.Medium); msg.Assert(e) {
|
||||
msg.W.Header().Set("Content-Type", "image/png")
|
||||
msg.Assert(qr.Write(kit.Int(kit.Select("256", arg, 1)), msg.W))
|
||||
}
|
||||
|
||||
default:
|
||||
if cmd != "" {
|
||||
msg.Echo(kit.Format(cmd, args...))
|
||||
}
|
||||
msg.W.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprint(msg.W, msg.Formats("meta"))
|
||||
}
|
||||
msg.Append(ice.MSG_OUTPUT, ice.RENDER_OUTPUT)
|
||||
}
|
||||
|
||||
func RenderCookie(msg *ice.Message, value string, arg ...string) { // name path expire
|
||||
expire := time.Now().Add(kit.Duration(kit.Select(msg.Conf(aaa.SESS, "meta.expire"), arg, 2)))
|
||||
http.SetCookie(msg.W, &http.Cookie{Value: value, Name: kit.Select(ice.MSG_SESSID, arg, 0), Path: kit.Select("/", arg, 1), Expires: expire})
|
||||
}
|
||||
func RenderStatus(msg *ice.Message, code int, text string) { // name path expire
|
||||
msg.W.WriteHeader(code)
|
||||
msg.W.Write([]byte(text))
|
||||
}
|
@ -5,6 +5,7 @@ import (
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/gdb"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
@ -15,7 +16,9 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func _serve_login(msg *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
const LOGIN = "_login"
|
||||
|
||||
func _serve_login(msg *ice.Message, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) {
|
||||
msg.Option(ice.MSG_USERNAME, "")
|
||||
msg.Option(ice.MSG_USERROLE, "")
|
||||
|
||||
@ -36,29 +39,30 @@ func _serve_login(msg *ice.Message, w http.ResponseWriter, r *http.Request) bool
|
||||
|
||||
if _, ok := msg.Target().Commands[LOGIN]; ok {
|
||||
// 权限检查
|
||||
msg.Target().Cmd(msg, LOGIN, LOGIN, kit.Simple(msg.Optionv("cmds"))...)
|
||||
msg.Target().Cmd(msg, LOGIN, msg.Option(ice.MSG_USERURL), cmds...)
|
||||
cmds = kit.Simple(msg.Optionv(ice.MSG_CMDS))
|
||||
|
||||
} else if ls := strings.Split(msg.Option(ice.MSG_USERURL), "/"); msg.Conf(SERVE, kit.Keys("meta.black", ls[1])) == "true" {
|
||||
return false // black
|
||||
return cmds, false // black
|
||||
|
||||
} else if msg.Conf(SERVE, kit.Keys("meta.white", ls[1])) == "true" {
|
||||
return true // white
|
||||
return cmds, true // white
|
||||
|
||||
} else {
|
||||
if msg.Warn(!msg.Options(ice.MSG_USERNAME), "not login %s", msg.Option(ice.MSG_USERURL)) {
|
||||
msg.Render("status", 401, "not login")
|
||||
return false
|
||||
msg.Render(STATUS, 401, "not login")
|
||||
return cmds, false
|
||||
}
|
||||
if !msg.Right(msg.Option(ice.MSG_USERURL)) {
|
||||
msg.Render("status", 403, "not auth")
|
||||
return false
|
||||
msg.Render(STATUS, 403, "not auth")
|
||||
return cmds, false
|
||||
}
|
||||
}
|
||||
|
||||
return msg.Option(ice.MSG_USERURL) != ""
|
||||
return cmds, msg.Option(ice.MSG_USERURL) != ""
|
||||
}
|
||||
func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.ResponseWriter, r *http.Request) {
|
||||
defer func() { msg.Cost("%s %v %v", r.URL.Path, msg.Optionv("cmds"), msg.Format("append")) }()
|
||||
defer func() { msg.Cost("%s %v %v", r.URL.Path, msg.Optionv(ice.MSG_CMDS), msg.Format("append")) }()
|
||||
if u, e := url.Parse(r.Header.Get("Referer")); e == nil {
|
||||
for k, v := range u.Query() {
|
||||
msg.Logs("refer", k, v)
|
||||
@ -111,19 +115,19 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
||||
// 请求参数
|
||||
for k, v := range r.Form {
|
||||
if msg.Optionv(k, v); k == ice.MSG_SESSID {
|
||||
msg.Render("cookie", v[0])
|
||||
msg.Render(COOKIE, v[0])
|
||||
}
|
||||
}
|
||||
|
||||
// 请求命令
|
||||
if msg.Option(ice.MSG_USERPOD, msg.Option("pod")); msg.Optionv("cmds") == nil {
|
||||
if msg.Option(ice.MSG_USERPOD, msg.Option("pod")); msg.Optionv(ice.MSG_CMDS) == nil {
|
||||
if p := strings.TrimPrefix(msg.Option(ice.MSG_USERURL), key); p != "" {
|
||||
msg.Optionv("cmds", strings.Split(p, "/"))
|
||||
msg.Optionv(ice.MSG_CMDS, strings.Split(p, "/"))
|
||||
}
|
||||
}
|
||||
|
||||
// 执行命令
|
||||
if cmds := kit.Simple(msg.Optionv("cmds")); _serve_login(msg, w, r) {
|
||||
if cmds, ok := _serve_login(msg, kit.Simple(msg.Optionv(ice.MSG_CMDS)), w, r); ok {
|
||||
msg.Option("_option", msg.Optionv(ice.MSG_OPTION))
|
||||
msg.Target().Cmd(msg, key, msg.Option(ice.MSG_USERURL), cmds...)
|
||||
}
|
||||
@ -190,8 +194,6 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
|
||||
const SERVE = "serve"
|
||||
|
||||
const LOGIN = "_login"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
@ -208,9 +210,6 @@ func init() {
|
||||
"publish", true,
|
||||
),
|
||||
|
||||
"title", "github.com/shylinux/contexts",
|
||||
"legal", []interface{}{`<a href="mailto:shylinuxc@gmail.com">shylinuxc@gmail.com</a>`},
|
||||
|
||||
"static", kit.Dict("/", "usr/volcanos/"),
|
||||
"volcanos", kit.Dict("path", "usr/volcanos", "branch", "master",
|
||||
"repos", "https://github.com/shylinux/volcanos",
|
||||
@ -228,10 +227,10 @@ func init() {
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
SERVE: {Name: "serve [random] [ups...]", Help: "服务器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if cli.NodeType(m, SERVER, cli.HostName); len(arg) > 0 && arg[0] == "random" {
|
||||
cli.NodeType(m, SERVER, cli.PathName)
|
||||
if cli.NodeInfo(m, SERVER, cli.HostName); len(arg) > 0 && arg[0] == "random" {
|
||||
cli.NodeInfo(m, SERVER, cli.PathName)
|
||||
// 随机端口
|
||||
m.Cmd(SPIDE, kit.MDB_CREATE, "self", "http://random")
|
||||
m.Cmd(SPIDE, mdb.CREATE, "self", "http://random")
|
||||
arg = arg[1:]
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/ctx"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"fmt"
|
||||
@ -151,12 +152,9 @@ func _share_action(m *ice.Message, value map[string]interface{}, arg ...string)
|
||||
return true
|
||||
}
|
||||
func _share_action_redirect(m *ice.Message, value map[string]interface{}, share string) bool {
|
||||
m.Render("redirect", "/share", "share", share,
|
||||
"title", kit.Format(value["name"]),
|
||||
"river", kit.Value(value, "extra.river"),
|
||||
"storm", kit.Value(value, "extra.storm"),
|
||||
"pod", kit.Value(value, "extra.tool.0.pod"),
|
||||
kit.UnMarshal(kit.Format(kit.Value(value, "extra.tool.0.value"))),
|
||||
tool := kit.Value(value, "extra.tool.0").(map[string]interface{})
|
||||
m.Render("redirect", "/share", "share", share, "title", kit.Format(value["name"]),
|
||||
"pod", kit.Format(tool["pod"]), kit.UnMarshal(kit.Format(tool["val"])),
|
||||
)
|
||||
return true
|
||||
}
|
||||
@ -240,7 +238,7 @@ func init() {
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
SHARE: {Name: "share share=auto auto", Help: "共享链", Action: map[string]*ice.Action{
|
||||
kit.MDB_CREATE: {Name: "create type name text arg...", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.CREATE: {Name: "create type name text arg...", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_share_create(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
@ -255,7 +253,7 @@ func init() {
|
||||
}},
|
||||
"/share/": {Name: "/share/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs(SHARE, nil, kit.Select(m.Option(kit.MDB_SHARE), arg, 0), func(key string, value map[string]interface{}) {
|
||||
m.Log_EXPORT(kit.MDB_META, SHARE, "arg", arg, "value", kit.Format(value))
|
||||
m.Log_SELECT(kit.MDB_META, SHARE, "arg", arg, "value", kit.Format(value))
|
||||
if m.Warn(m.Option(ice.MSG_USERROLE) != aaa.ROOT && kit.Time(kit.Format(value[kit.MDB_TIME])) < kit.Time(m.Time()), "expired") {
|
||||
m.Echo("expired")
|
||||
return
|
||||
|
@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
@ -58,7 +59,7 @@ func _spide_login(m *ice.Message, name string) {
|
||||
func _spide_create(m *ice.Message, name, address string, arg ...string) {
|
||||
if uri, e := url.Parse(address); e == nil && address != "" {
|
||||
if uri.Host == "random" {
|
||||
uri.Host = ":" + tcp.TCPPort(m)
|
||||
uri.Host = ":" + m.Cmdx(tcp.PORT, "get")
|
||||
address = strings.Replace(address, "random", uri.Host, -1)
|
||||
}
|
||||
|
||||
@ -90,7 +91,7 @@ func init() {
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
SPIDE: {Name: "spide name=auto [action:select=msg|raw|cache] [method:select=POST|GET] url [format:select=json|form|part|data|file] arg... auto", Help: "蜘蛛侠", Action: map[string]*ice.Action{
|
||||
kit.MDB_CREATE: {Name: "create name address", Help: "", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.CREATE: {Name: "create name address", Help: "", Hand: func(m *ice.Message, arg ...string) {
|
||||
_spide_create(m, arg[0], arg[1])
|
||||
}},
|
||||
"login": {Name: "login name", Help: "", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -237,7 +238,7 @@ func init() {
|
||||
switch cache {
|
||||
case "cache":
|
||||
m.Optionv("response", res)
|
||||
CacheCatch(m, res.Header.Get("Content-Type"), uri)
|
||||
m.Cmdy(CACHE, "catch", res.Header.Get("Content-Type"), uri)
|
||||
m.Echo(m.Append("data"))
|
||||
case "raw":
|
||||
if b, e := ioutil.ReadAll(res.Body); m.Assert(e) {
|
||||
|
@ -386,7 +386,7 @@ func StoryAdd(m *ice.Message, mime string, name string, text string, arg ...stri
|
||||
const STORY = "story"
|
||||
const (
|
||||
TRASH = "trash"
|
||||
CATCH = "catch"
|
||||
// CATCH = "catch"
|
||||
INDEX = "index"
|
||||
|
||||
LIST = "list"
|
||||
|
115
base/web/web.go
115
base/web/web.go
@ -2,19 +2,15 @@ package web
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/gdb"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/nfs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"github.com/skip2/go-qrcode"
|
||||
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Frame struct {
|
||||
@ -26,72 +22,6 @@ type Frame struct {
|
||||
send map[string]*ice.Message
|
||||
}
|
||||
|
||||
func Count(m *ice.Message, cmd, key, name string) int {
|
||||
count := kit.Int(m.Conf(cmd, kit.Keys(key, name)))
|
||||
m.Conf(cmd, kit.Keys(key, name), count+1)
|
||||
return count
|
||||
}
|
||||
func Format(key string, arg ...interface{}) string {
|
||||
switch args := kit.Simple(arg); key {
|
||||
case "a":
|
||||
return fmt.Sprintf("<a href='%s' target='_blank'>%s</a>", kit.Format(args[0]), kit.Select(kit.Format(args[0]), args, 1))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func Render(msg *ice.Message, cmd string, args ...interface{}) {
|
||||
if cmd != "" {
|
||||
defer func() { msg.Log(ice.LOG_EXPORT, "%s: %v", cmd, args) }()
|
||||
}
|
||||
switch arg := kit.Simple(args...); cmd {
|
||||
case ice.RENDER_VOID:
|
||||
case ice.RENDER_OUTPUT:
|
||||
case "redirect":
|
||||
http.Redirect(msg.W, msg.R, kit.MergeURL(arg[0], arg[1:]), 307)
|
||||
|
||||
case "refresh":
|
||||
arg = []string{"200", fmt.Sprintf(`<!DOCTYPE html><head><meta charset="utf-8"><meta http-equiv="Refresh" content="%d"></head><body>%s</body>`,
|
||||
kit.Int(kit.Select("3", arg, 0)), kit.Select("请稍后,系统初始化中...", arg, 1),
|
||||
)}
|
||||
fallthrough
|
||||
|
||||
case "status":
|
||||
msg.W.WriteHeader(kit.Int(kit.Select("200", arg, 0)))
|
||||
msg.W.Write([]byte(kit.Select("", arg, 1)))
|
||||
|
||||
case "cookie":
|
||||
expire := time.Now().Add(kit.Duration(msg.Conf(aaa.SESS, "meta.expire")))
|
||||
http.SetCookie(msg.W, &http.Cookie{Value: arg[0], Name: kit.Select(ice.MSG_SESSID, arg, 1), Path: "/", Expires: expire})
|
||||
|
||||
case ice.RENDER_DOWNLOAD:
|
||||
msg.W.Header().Set("Content-Disposition", fmt.Sprintf("filename=%s", kit.Select(path.Base(arg[0]), arg, 2)))
|
||||
msg.W.Header().Set("Content-Type", kit.Select("text/html", arg, 1))
|
||||
http.ServeFile(msg.W, msg.R, arg[0])
|
||||
|
||||
case ice.RENDER_RESULT:
|
||||
if len(arg) > 0 {
|
||||
msg.W.Write([]byte(kit.Format(arg[0], args[1:]...)))
|
||||
} else {
|
||||
args = append(args, "length:", len(msg.Result()))
|
||||
msg.W.Write([]byte(msg.Result()))
|
||||
}
|
||||
|
||||
case ice.RENDER_QRCODE:
|
||||
if qr, e := qrcode.New(arg[0], qrcode.Medium); msg.Assert(e) {
|
||||
msg.W.Header().Set("Content-Type", "image/png")
|
||||
msg.Assert(qr.Write(kit.Int(kit.Select("256", arg, 1)), msg.W))
|
||||
}
|
||||
|
||||
default:
|
||||
if cmd != "" {
|
||||
msg.Echo(kit.Format(cmd, args...))
|
||||
}
|
||||
msg.W.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprint(msg.W, msg.Formats("meta"))
|
||||
}
|
||||
msg.Append(ice.MSG_OUTPUT, ice.RENDER_OUTPUT)
|
||||
}
|
||||
|
||||
func (web *Frame) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if _serve_main(web.m, w, r) {
|
||||
web.ServeMux.ServeHTTP(w, r)
|
||||
@ -167,46 +97,11 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Load()
|
||||
|
||||
m.Cmd(SPIDE, kit.MDB_CREATE, "self", kit.Select("http://:9020", m.Conf(cli.RUNTIME, "conf.ctx_self")))
|
||||
m.Cmd(SPIDE, kit.MDB_CREATE, "dev", kit.Select("http://:9020", m.Conf(cli.RUNTIME, "conf.ctx_dev")))
|
||||
m.Cmd(SPIDE, kit.MDB_CREATE, "shy", kit.Select("https://shylinux.com:443", m.Conf(cli.RUNTIME, "conf.ctx_shy")))
|
||||
m.Cmd(SPIDE, mdb.CREATE, "self", kit.Select("http://:9020", m.Conf(cli.RUNTIME, "conf.ctx_self")))
|
||||
m.Cmd(SPIDE, mdb.CREATE, "dev", kit.Select("http://:9020", m.Conf(cli.RUNTIME, "conf.ctx_dev")))
|
||||
m.Cmd(SPIDE, mdb.CREATE, "shy", kit.Select("https://shylinux.com:443", m.Conf(cli.RUNTIME, "conf.ctx_shy")))
|
||||
|
||||
m.Cmd(nfs.SEARCH, "add", "favor", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[0] {
|
||||
case "set":
|
||||
m.Richs(FAVOR, nil, arg[1], func(key string, value map[string]interface{}) {
|
||||
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), "id", arg[2], func(index int, value map[string]interface{}) {
|
||||
if cmd := m.Conf(FAVOR, kit.Keys("meta.render", value["type"])); cmd != "" {
|
||||
m.Optionv("value", value)
|
||||
m.Cmdy(cmd, arg[1:])
|
||||
} else {
|
||||
m.Push("detail", value)
|
||||
}
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
m.Option("cache.limit", -2)
|
||||
wg := &sync.WaitGroup{}
|
||||
m.Richs(FAVOR, nil, "*", func(key string, val map[string]interface{}) {
|
||||
favor := kit.Format(kit.Value(val, "meta.name"))
|
||||
wg.Add(1)
|
||||
m.Gos(m, func(m *ice.Message) {
|
||||
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
if favor == arg[0] || value["type"] == arg[0] ||
|
||||
strings.Contains(kit.Format(value["name"]), arg[0]) || strings.Contains(kit.Format(value["text"]), arg[0]) {
|
||||
m.Push("pod", m.Option(ice.MSG_USERPOD))
|
||||
m.Push("engine", "favor")
|
||||
m.Push("favor", favor)
|
||||
m.Push("", value, []string{"id", "time", "type", "name", "text"})
|
||||
}
|
||||
})
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
wg.Wait()
|
||||
}}))
|
||||
m.Cmd("mdb.search", "create", "favor", "favor", "web")
|
||||
|
||||
m.Cmd(nfs.SEARCH, "add", "story", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[0] {
|
||||
|
1
conf.go
1
conf.go
@ -24,6 +24,7 @@ const ( // MSG
|
||||
MSG_OUTPUT = "_output"
|
||||
MSG_ARGS = "_args"
|
||||
|
||||
MSG_CMDS = "cmds"
|
||||
MSG_SESSID = "sessid"
|
||||
MSG_USERIP = "user.ip"
|
||||
MSG_USERUA = "user.ua"
|
||||
|
@ -9,107 +9,81 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func _action_share_create(m *ice.Message, arg ...string) {
|
||||
if m.Option("_index") != "" {
|
||||
m.Cmdy(web.SHARE, web.TYPE_ACTION, m.Option("_name"), m.Option("_text"),
|
||||
"tool.0.pod", kit.Select(m.Option("_pod"), m.Option("_node")),
|
||||
"tool.0.ctx", m.Option("_group"),
|
||||
"tool.0.cmd", m.Option("_index"),
|
||||
"tool.0.args", m.Option("_args"),
|
||||
"tool.0.value", m.Option("_value"),
|
||||
"tool.0.single", "yes",
|
||||
)
|
||||
} else {
|
||||
m.Option(ice.MSG_RIVER, arg[5])
|
||||
m.Option(ice.MSG_STORM, arg[7])
|
||||
m.Cmd("/action", arg[5], arg[7]).Table(func(index int, value map[string]string, head []string) {
|
||||
arg = append(arg, kit.Format("tool.%d.pod", index), value["node"])
|
||||
arg = append(arg, kit.Format("tool.%d.ctx", index), value["group"])
|
||||
arg = append(arg, kit.Format("tool.%d.cmd", index), value["index"])
|
||||
arg = append(arg, kit.Format("tool.%d.args", index), value["args"])
|
||||
})
|
||||
func _action_share_create(m *ice.Message, name, text string, arg ...string) {
|
||||
list := []string{}
|
||||
for i := 0; i < len(arg)-3; i += 5 {
|
||||
p := kit.Format("tool.%d.", i/5)
|
||||
list = append(list, p+POD, arg[i])
|
||||
list = append(list, p+CTX, arg[i+1])
|
||||
list = append(list, p+CMD, arg[i+2])
|
||||
list = append(list, p+ARG, arg[i+3])
|
||||
list = append(list, p+VAL, arg[i+4])
|
||||
}
|
||||
m.Cmdy(web.SHARE, ACTION, name, text, list)
|
||||
}
|
||||
func _action_share_list(m *ice.Message, river, storm string) {
|
||||
m.Richs(web.SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
|
||||
func _action_share_list(m *ice.Message, key string) {
|
||||
m.Richs(web.SHARE, nil, key, func(key string, value map[string]interface{}) {
|
||||
kit.Fetch(kit.Value(value, "extra.tool"), func(index int, value map[string]interface{}) {
|
||||
m.Push("river", river)
|
||||
m.Push("storm", storm)
|
||||
m.Push("action", index)
|
||||
m.Push(RIVER, "")
|
||||
m.Push(STORM, "")
|
||||
m.Push(ACTION, index)
|
||||
|
||||
m.Push("node", value["pod"])
|
||||
m.Push("group", value["ctx"])
|
||||
m.Push("index", value["cmd"])
|
||||
m.Push("args", value["args"])
|
||||
m.Push("node", value[POD])
|
||||
m.Push("group", value[CTX])
|
||||
m.Push("index", value[CMD])
|
||||
m.Push("args", value[ARG])
|
||||
|
||||
msg := m.Cmd(m.Space(value["pod"]), ctx.COMMAND, kit.Keys(value["ctx"], value["cmd"]))
|
||||
m.Push("name", value["cmd"])
|
||||
msg := m.Cmd(m.Space(value[POD]), ctx.COMMAND, kit.Keys(value[CTX], value[CMD]))
|
||||
m.Push("name", value[CMD])
|
||||
m.Push("help", kit.Select(msg.Append("help"), kit.Format(value["help"])))
|
||||
m.Push("inputs", msg.Append("list"))
|
||||
m.Push("feature", msg.Append("meta"))
|
||||
})
|
||||
})
|
||||
}
|
||||
func _action_share_show(m *ice.Message, river, storm, index string, arg ...string) {
|
||||
if i, e := strconv.Atoi(index); e == nil {
|
||||
m.Richs(web.SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
|
||||
kit.Fetch(kit.Value(value, kit.Keys("extra.tool", i-1)), func(value map[string]interface{}) {
|
||||
cmds := kit.Simple(kit.Keys(value["ctx"], value["cmd"]), arg)
|
||||
m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
func _action_order_list(m *ice.Message, river, storm string, arg ...string) {
|
||||
for _, v := range arg {
|
||||
m.Push("river", river)
|
||||
m.Push("storm", storm)
|
||||
m.Push("action", v)
|
||||
m.Push(RIVER, river)
|
||||
m.Push(STORM, storm)
|
||||
m.Push(ACTION, v)
|
||||
|
||||
m.Push("node", "")
|
||||
m.Push("group", "")
|
||||
m.Push("index", v)
|
||||
m.Push("args", "[]")
|
||||
|
||||
msg := m.Cmd(m.Space(m.Option("pod")), ctx.COMMAND, v)
|
||||
msg := m.Cmd(m.Space(m.Option(POD)), ctx.COMMAND, v)
|
||||
m.Push("name", msg.Append("name"))
|
||||
m.Push("help", msg.Append("help"))
|
||||
m.Push("feature", msg.Append("meta"))
|
||||
m.Push("inputs", msg.Append("list"))
|
||||
}
|
||||
}
|
||||
|
||||
func _action_action(m *ice.Message, action string, arg ...string) bool {
|
||||
switch action {
|
||||
case "upload":
|
||||
msg := m.Cmd(web.STORY, "upload")
|
||||
m.Option("name", msg.Append("name"))
|
||||
m.Option("data", msg.Append("data"))
|
||||
}
|
||||
return false
|
||||
}
|
||||
func _action_proxy(m *ice.Message) (proxy []string) {
|
||||
if m.Option("pod") != "" {
|
||||
proxy = append(proxy, web.PROXY, m.Option("pod"))
|
||||
m.Option("pod", "")
|
||||
}
|
||||
return proxy
|
||||
}
|
||||
func _action_list(m *ice.Message, river, storm string) {
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, "tool", kit.MDB_HASH, storm)
|
||||
m.Grows(RIVER, prefix, "", "", func(index int, value map[string]interface{}) {
|
||||
if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok {
|
||||
m.Push("river", river)
|
||||
m.Push("storm", storm)
|
||||
m.Push("action", index)
|
||||
if p := m.Option(POD); p != "" {
|
||||
m.Option(POD, "")
|
||||
// 代理列表
|
||||
m.Cmdy(web.SPACE, p, "web.chat./action", river, storm)
|
||||
}
|
||||
if m.Option("share") != "" {
|
||||
// 共享列表
|
||||
_action_share_list(m, m.Option("share"))
|
||||
}
|
||||
|
||||
m.Push("node", meta["pod"])
|
||||
m.Push("group", meta["ctx"])
|
||||
m.Push("index", meta["cmd"])
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, TOOL, kit.MDB_HASH, storm)
|
||||
m.Grows(RIVER, prefix, "", "", func(index int, value map[string]interface{}) {
|
||||
if meta, ok := kit.Value(value, kit.MDB_META).(map[string]interface{}); ok {
|
||||
m.Push(RIVER, river)
|
||||
m.Push(STORM, storm)
|
||||
m.Push(ACTION, index)
|
||||
|
||||
m.Push("node", meta[POD])
|
||||
m.Push("group", meta[CTX])
|
||||
m.Push("index", meta[CMD])
|
||||
m.Push("args", kit.Select("[]", kit.Format(meta["args"])))
|
||||
|
||||
msg := m.Cmd(m.Space(meta["pod"]), ctx.COMMAND, kit.Keys(meta["ctx"], meta["cmd"]))
|
||||
m.Push("name", meta["cmd"])
|
||||
msg := m.Cmd(m.Space(meta[POD]), ctx.COMMAND, kit.Keys(meta[CTX], meta[CMD]))
|
||||
m.Push("name", meta[CMD])
|
||||
m.Push("help", kit.Select(msg.Append("help"), kit.Format(meta["help"])))
|
||||
m.Push("feature", msg.Append("meta"))
|
||||
m.Push("inputs", msg.Append("list"))
|
||||
@ -117,64 +91,73 @@ func _action_list(m *ice.Message, river, storm string) {
|
||||
})
|
||||
}
|
||||
func _action_show(m *ice.Message, river, storm, index string, arg ...string) {
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, "tool", kit.MDB_HASH, storm)
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, TOOL, kit.MDB_HASH, storm)
|
||||
cmds := []string{}
|
||||
|
||||
if i, e := strconv.Atoi(index); e == nil {
|
||||
m.Richs(web.SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
|
||||
kit.Fetch(kit.Value(value, kit.Keys("extra.tool", i)), func(value map[string]interface{}) {
|
||||
// 共享命令
|
||||
cmds = kit.Simple(m.Space(value[POD]), kit.Keys(value[CTX], value[CMD]), arg)
|
||||
})
|
||||
})
|
||||
m.Grows(RIVER, prefix, kit.MDB_ID, kit.Format(i+1), func(index int, value map[string]interface{}) {
|
||||
if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok {
|
||||
cmds = kit.Simple(m.Space(meta["pod"]), kit.Keys(meta["ctx"], meta["cmd"]), arg[3:])
|
||||
if value, ok := kit.Value(value, kit.MDB_META).(map[string]interface{}); ok {
|
||||
// 群组命令
|
||||
cmds = kit.Simple(m.Space(value[POD]), kit.Keys(value[CTX], value[CMD]), arg)
|
||||
}
|
||||
})
|
||||
} else if !m.Warn(!m.Right(index), "no right of %v", index) {
|
||||
// 定制命令
|
||||
cmds = kit.Simple(index, arg)
|
||||
}
|
||||
if len(cmds) == 0 {
|
||||
m.Render("status", 404, "not found")
|
||||
return
|
||||
}
|
||||
if !m.Right(cmds) {
|
||||
m.Render("status", 403, "not auth")
|
||||
return
|
||||
}
|
||||
m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds)
|
||||
}
|
||||
func _action_proxy(m *ice.Message) (proxy []string) {
|
||||
if m.Option(POD) != "" {
|
||||
proxy = append(proxy, web.PROXY, m.Option(POD))
|
||||
m.Option(POD, "")
|
||||
}
|
||||
return proxy
|
||||
}
|
||||
|
||||
const (
|
||||
ORDER = "order"
|
||||
)
|
||||
const ACTION = "action"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
"/action": {Name: "/action", Help: "工作台", Action: map[string]*ice.Action{
|
||||
kit.MDB_SHARE: {Name: "share arg...", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
|
||||
_action_share_create(m, arg...)
|
||||
"/" + ACTION: {Name: "/action", Help: "工作台", Action: map[string]*ice.Action{
|
||||
web.SHARE: {Name: "share name text [pod ctx cmd arg]...", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
|
||||
_action_share_create(m, arg[0], arg[1], arg[2:]...)
|
||||
}},
|
||||
web.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := m.Cmd(web.STORY, web.UPLOAD)
|
||||
m.Option(kit.MDB_NAME, msg.Append(kit.MDB_NAME))
|
||||
m.Option(kit.MDB_DATA, msg.Append(kit.MDB_DATA))
|
||||
_action_show(m, m.Option(RIVER), m.Option(STORM), m.Option(ACTION),
|
||||
append([]string{ACTION, web.UPLOAD}, arg...)...)
|
||||
}},
|
||||
ORDER: {Name: "order cmd...", Help: "定制", Hand: func(m *ice.Message, arg ...string) {
|
||||
_action_order_list(m, m.Option(RIVER), m.Option(STORM), arg...)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 2 {
|
||||
if m.Option("share") != "" {
|
||||
// 共享列表
|
||||
_action_share_list(m, arg[0], arg[1])
|
||||
}
|
||||
if p := m.Option("pod"); p != "" {
|
||||
m.Option("pod", "")
|
||||
// 代理列表
|
||||
m.Cmdy(web.SPACE, p, "web.chat./action", arg)
|
||||
}
|
||||
if len(arg) == 0 {
|
||||
// 命令列表
|
||||
_action_list(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM))
|
||||
return
|
||||
}
|
||||
switch arg[2] {
|
||||
case "index":
|
||||
// 前端列表
|
||||
_action_order_list(m, arg[0], arg[1], arg[3:]...)
|
||||
return
|
||||
}
|
||||
|
||||
if arg[0] == "" && m.Option("share") != "" {
|
||||
// 共享命令
|
||||
_action_share_show(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||
return
|
||||
}
|
||||
if len(arg) > 3 && arg[3] == "action" && _action_action(m, arg[3]) {
|
||||
// 前置命令
|
||||
_action_list(m, m.Option(RIVER), m.Option(STORM))
|
||||
return
|
||||
}
|
||||
// 执行命令
|
||||
_action_show(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM), kit.Select(arg[2], m.Option("index")), arg[3:]...)
|
||||
_action_show(m, m.Option(RIVER), m.Option(STORM), arg[0], arg[1:]...)
|
||||
}},
|
||||
}}, nil)
|
||||
}
|
||||
|
@ -7,13 +7,6 @@ import (
|
||||
"github.com/shylinux/icebergs/base/gdb"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
RIVER = "river"
|
||||
STORM = "storm"
|
||||
)
|
||||
|
||||
var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
||||
@ -156,32 +149,41 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
||||
// 密码登录
|
||||
if len(arg) > 2 && aaa.UserLogin(m, arg[1], arg[2]) {
|
||||
m.Option(ice.MSG_SESSID, aaa.SessCreate(m, m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERROLE)))
|
||||
web.Render(m, "cookie", m.Option(ice.MSG_SESSID))
|
||||
web.Render(m, web.COOKIE, m.Option(ice.MSG_SESSID))
|
||||
}
|
||||
|
||||
default:
|
||||
// 群组检查
|
||||
m.Richs(RIVER, nil, arg[0], func(key string, value map[string]interface{}) {
|
||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, arg[0], "user"), m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
|
||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, arg[0], USER), m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
|
||||
if m.Option(ice.MSG_RIVER, arg[0]); len(arg) > 1 {
|
||||
// 应用检查
|
||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, arg[0], "tool"), arg[1], func(key string, value map[string]interface{}) {
|
||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, arg[0], TOOL), arg[1], func(key string, value map[string]interface{}) {
|
||||
m.Option(ice.MSG_STORM, arg[1])
|
||||
})
|
||||
}
|
||||
m.Log_AUTH(RIVER, m.Option(ice.MSG_RIVER), STORM, m.Option(ice.MSG_STORM))
|
||||
})
|
||||
})
|
||||
switch m.Option(ice.MSG_USERURL) {
|
||||
case "/action":
|
||||
arg = arg[2:]
|
||||
case "/storm":
|
||||
arg = arg[2:]
|
||||
case "/river":
|
||||
arg = arg[1:]
|
||||
}
|
||||
m.Optionv(ice.MSG_CMDS, arg)
|
||||
}
|
||||
}
|
||||
|
||||
if m.Right(m.Option(ice.MSG_USERURL), m.Optionv("cmds")) {
|
||||
if m.Right(m.Option(ice.MSG_USERURL), m.Optionv(ice.MSG_CMDS)) {
|
||||
return
|
||||
}
|
||||
// 登录检查
|
||||
if m.Warn(!m.Options(ice.MSG_USERNAME), "not login") {
|
||||
if m.Option("share") == "" {
|
||||
m.Render("status", 401, "not login")
|
||||
m.Render(web.STATUS, 401, "not login")
|
||||
m.Option(ice.MSG_USERURL, "")
|
||||
return
|
||||
}
|
||||
@ -189,57 +191,13 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
||||
}
|
||||
|
||||
// 权限检查
|
||||
if m.Warn(!m.Right(m.Option(ice.MSG_USERURL), m.Optionv("cmds")), "not auth") {
|
||||
m.Render("status", 403, "not auth")
|
||||
if m.Warn(!m.Right(m.Option(ice.MSG_USERURL), m.Optionv(ice.MSG_CMDS)), "not auth") {
|
||||
m.Render(web.STATUS, 403, "not auth")
|
||||
m.Option(ice.MSG_USERURL, "")
|
||||
return
|
||||
}
|
||||
}},
|
||||
|
||||
"/toast": {Name: "/toast", Help: "提示", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
"/carte": {Name: "/carte", Help: "菜单", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
"/tutor": {Name: "/tutor", Help: "向导", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
"/debug": {Name: "/debug", Help: "调试", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
"/input": {Name: "/input", Help: "输入", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
"/login": {Name: "/login", Help: "登录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[0] {
|
||||
case "check":
|
||||
m.Richs(aaa.USER, nil, m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
|
||||
m.Push("nickname", value["nickname"])
|
||||
})
|
||||
m.Render(m.Option(ice.MSG_USERNAME))
|
||||
|
||||
case "login":
|
||||
m.Render(m.Option(ice.MSG_SESSID))
|
||||
|
||||
case "share":
|
||||
switch arg[1] {
|
||||
case "river":
|
||||
case "storm":
|
||||
case "action":
|
||||
if m.Option("index") != "" {
|
||||
arg = append(arg, "tool.0.pod", m.Option("node"))
|
||||
arg = append(arg, "tool.0.ctx", m.Option("group"))
|
||||
arg = append(arg, "tool.0.cmd", m.Option("index"))
|
||||
arg = append(arg, "tool.0.args", m.Option("args"))
|
||||
arg = append(arg, "tool.0.single", "yes")
|
||||
} else {
|
||||
m.Option(ice.MSG_RIVER, arg[5])
|
||||
m.Option(ice.MSG_STORM, arg[7])
|
||||
m.Cmd("/action", arg[5], arg[7]).Table(func(index int, value map[string]string, head []string) {
|
||||
arg = append(arg, kit.Format("tool.%d.pod", index), value["node"])
|
||||
arg = append(arg, kit.Format("tool.%d.ctx", index), value["group"])
|
||||
arg = append(arg, kit.Format("tool.%d.cmd", index), value["index"])
|
||||
arg = append(arg, kit.Format("tool.%d.args", index), value["args"])
|
||||
})
|
||||
}
|
||||
default:
|
||||
return
|
||||
}
|
||||
m.Cmdy(web.SHARE, arg[1], arg[2], arg[3], arg[4:])
|
||||
}
|
||||
}},
|
||||
|
||||
"/ocean": {Name: "/ocean", Help: "大海洋", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
// 用户列表
|
||||
@ -313,89 +271,6 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
||||
m.Cmdy(web.SPACE, arg[2], ctx.COMMAND)
|
||||
}
|
||||
}},
|
||||
|
||||
"/target": {Name: "/target", Help: "对话框", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
"/source": {Name: "/source", Help: "输入框", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
|
||||
"commend": {Name: "commend label pod engine work auto", Help: "推荐引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) < 2 {
|
||||
m.Cmdy(web.LABEL, arg)
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "add":
|
||||
if m.Richs(cmd, nil, arg[1], nil) == nil {
|
||||
m.Rich(cmd, nil, kit.Data(kit.MDB_NAME, arg[1]))
|
||||
}
|
||||
m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) {
|
||||
m.Grow(cmd, kit.Keys(kit.MDB_HASH, key), kit.Dict(
|
||||
kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3:],
|
||||
))
|
||||
})
|
||||
case "get":
|
||||
wg := &sync.WaitGroup{}
|
||||
m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) {
|
||||
wg.Add(1)
|
||||
m.Gos(m, func(m *ice.Message) {
|
||||
m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
m.Cmdy(value[kit.MDB_TEXT], arg[2:])
|
||||
})
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
m.Sort("time", "time_r")
|
||||
wg.Wait()
|
||||
case "set":
|
||||
if arg[1] != "" {
|
||||
m.Cmdy(web.SPACE, arg[1], "web.chat.commend", "set", "", arg[2:])
|
||||
break
|
||||
}
|
||||
|
||||
if m.Richs(cmd, "meta.user", m.Option(ice.MSG_USERNAME), nil) == nil {
|
||||
m.Rich(cmd, "meta.user", kit.Dict(
|
||||
kit.MDB_NAME, m.Option(ice.MSG_USERNAME),
|
||||
))
|
||||
}
|
||||
switch m.Option("_action") {
|
||||
case "喜欢":
|
||||
m.Richs(cmd, "meta.user", m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
|
||||
m.Grow(cmd, kit.Keys("meta.user", kit.MDB_HASH, key, "like"), kit.Dict(
|
||||
kit.MDB_EXTRA, kit.Dict("engine", arg[2], "favor", arg[3], "id", arg[4]),
|
||||
kit.MDB_TYPE, arg[5], kit.MDB_NAME, arg[6], kit.MDB_TEXT, arg[7],
|
||||
))
|
||||
})
|
||||
case "讨厌":
|
||||
m.Richs(cmd, "meta.user", m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
|
||||
m.Grow(cmd, kit.Keys("meta.user", kit.MDB_HASH, key, "hate"), kit.Dict(
|
||||
kit.MDB_EXTRA, kit.Dict("engine", arg[2], "favor", arg[3], "id", arg[4]),
|
||||
kit.MDB_TYPE, arg[5], kit.MDB_NAME, arg[6], kit.MDB_TEXT, arg[7],
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
m.Richs(cmd, nil, arg[2], func(key string, value map[string]interface{}) {
|
||||
m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
m.Cmdy(value[kit.MDB_TEXT], "set", arg[3:])
|
||||
})
|
||||
})
|
||||
default:
|
||||
if len(arg) == 2 {
|
||||
m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value)
|
||||
})
|
||||
break
|
||||
}
|
||||
if len(arg) == 3 {
|
||||
m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value)
|
||||
})
|
||||
break
|
||||
}
|
||||
m.Cmdy(web.LABEL, arg[0], arg[1], "web.chat.commend", "get", arg[2:])
|
||||
// m.Cmdy("web.chat.commend", "get", arg[2:])
|
||||
}
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
package chat
|
@ -2,16 +2,23 @@ package chat
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const LEGAL = "legal"
|
||||
const FOOTER = "footer"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
"/footer": {Name: "/footer", Help: "状态栏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
kit.Fetch(m.Confv(web.SERVE, "meta.legal"), func(index int, value string) {
|
||||
m.Echo(value)
|
||||
})
|
||||
}},
|
||||
}}, nil)
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
FOOTER: {Name: "footer", Help: "状态栏", Value: kit.Dict(
|
||||
LEGAL, []interface{}{`<a href="mailto:shylinuxc@gmail.com">shylinuxc@gmail.com</a>`},
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
"/" + FOOTER: {Name: "/footer", Help: "状态栏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
kit.Fetch(m.Confv(FOOTER, LEGAL), func(index int, value string) { m.Echo(value) })
|
||||
}},
|
||||
},
|
||||
}, nil)
|
||||
}
|
||||
|
@ -2,25 +2,34 @@ package chat
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
CHECK = "check"
|
||||
LOGIN = "login"
|
||||
TITLE = "title"
|
||||
)
|
||||
const HEADER = "header"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
"/header": {Name: "/header", Help: "标题栏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch kit.Select("", arg, 0) {
|
||||
case "check":
|
||||
if m.Option(ice.MSG_USERNAME) != "" {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
HEADER: {Name: "header", Help: "标题栏", Value: kit.Dict(
|
||||
TITLE, "github.com/shylinux/contexts",
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
"/" + HEADER: {Name: "/header", Help: "标题栏", Action: map[string]*ice.Action{
|
||||
CHECK: {Name: "check", Help: "登录检查", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(m.Option(ice.MSG_USERNAME))
|
||||
}
|
||||
case "login":
|
||||
if m.Option(ice.MSG_USERNAME) != "" {
|
||||
m.Render(m.Option(ice.MSG_USERNAME))
|
||||
}
|
||||
default:
|
||||
m.Echo(m.Conf(web.SERVE, "meta.title"))
|
||||
}
|
||||
}},
|
||||
}}, nil)
|
||||
}},
|
||||
LOGIN: {Name: "login", Help: "用户登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(m.Option(ice.MSG_USERNAME))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Echo(m.Conf(HEADER, TITLE))
|
||||
}},
|
||||
},
|
||||
}, nil)
|
||||
}
|
||||
|
@ -2,69 +2,67 @@ package chat
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func _river_right(m *ice.Message, action string) bool {
|
||||
if m.Warn(m.Option(ice.MSG_RIVER) == "", "not join") {
|
||||
m.Render("status", 402, "not join")
|
||||
return false
|
||||
}
|
||||
|
||||
if !m.Right(RIVER, action) {
|
||||
m.Render("status", 403, "not auth")
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func _river_list(m *ice.Message) {
|
||||
m.Set(ice.MSG_OPTION, "key")
|
||||
m.Set(ice.MSG_OPTION, "name")
|
||||
m.Richs(RIVER, nil, "*", func(key string, value map[string]interface{}) {
|
||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, key, "user"), m.Option(ice.MSG_USERNAME), func(k string, val map[string]interface{}) {
|
||||
m.Push(key, value["meta"], []string{kit.MDB_KEY, kit.MDB_NAME})
|
||||
m.Set(ice.MSG_OPTION, kit.MDB_KEY)
|
||||
m.Set(ice.MSG_OPTION, kit.MDB_NAME)
|
||||
m.Richs(RIVER, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, key, USER), m.Option(ice.MSG_USERNAME), func(k string, val map[string]interface{}) {
|
||||
m.Push(key, value[kit.MDB_META], []string{kit.MDB_KEY, kit.MDB_NAME})
|
||||
})
|
||||
})
|
||||
}
|
||||
func _river_user(m *ice.Message, river string, user ...string) {
|
||||
m.Rich(RIVER, kit.Keys(kit.MDB_HASH, river, "user"), kit.Data("username", m.Conf(cli.RUNTIME, "boot.username")))
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, USER)
|
||||
m.Rich(RIVER, prefix, kit.Data(aaa.USERNAME, cli.UserName))
|
||||
for _, v := range user {
|
||||
user := m.Rich(RIVER, kit.Keys(kit.MDB_HASH, river, "user"), kit.Data("username", v))
|
||||
m.Log_INSERT(RIVER, river, "hash", user, "user", v)
|
||||
m.Rich(RIVER, prefix, kit.Data(aaa.USERNAME, v))
|
||||
m.Log_INSERT(RIVER, river, USER, v)
|
||||
}
|
||||
}
|
||||
func _river_share(m *ice.Message, river, name string, arg ...string) {
|
||||
m.Cmdy(web.SHARE, RIVER, name, river, arg)
|
||||
}
|
||||
func _river_rename(m *ice.Message, river string, name string) {
|
||||
old := m.Conf(RIVER, kit.Keys(kit.MDB_HASH, river, kit.MDB_META, kit.MDB_NAME))
|
||||
m.Log_MODIFY(RIVER, river, "value", name, "old", old)
|
||||
m.Conf(RIVER, kit.Keys(kit.MDB_HASH, river, kit.MDB_META, kit.MDB_NAME), name)
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, kit.MDB_META, kit.MDB_NAME)
|
||||
old := m.Conf(RIVER, prefix)
|
||||
m.Log_MODIFY(RIVER, river, kit.MDB_VALUE, name, "old", old)
|
||||
m.Conf(RIVER, prefix, name)
|
||||
}
|
||||
func _river_remove(m *ice.Message, river string) {
|
||||
m.Richs(RIVER, nil, river, func(value map[string]interface{}) {
|
||||
m.Log_REMOVE(RIVER, river, "value", kit.Format(value))
|
||||
m.Log_REMOVE(RIVER, river, kit.MDB_VALUE, kit.Format(value))
|
||||
})
|
||||
m.Conf(RIVER, kit.Keys(kit.MDB_HASH, river), "")
|
||||
}
|
||||
|
||||
const (
|
||||
USER = "user"
|
||||
TOOL = "tool"
|
||||
)
|
||||
const RIVER = "river"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
"/river": {Name: "/river river user|rename|remove arg...", Help: "小河流",
|
||||
"/" + RIVER: {Name: "/river", Help: "小河流",
|
||||
Action: map[string]*ice.Action{
|
||||
"user": {Name: "user user...", Help: "添加用户", Hand: func(m *ice.Message, arg ...string) {
|
||||
if _river_right(m, "user") {
|
||||
_river_user(m, m.Option(RIVER), arg...)
|
||||
}
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
_river_remove(m, m.Option(RIVER))
|
||||
}},
|
||||
"rename": {Name: "rename name", Help: "重命名", Hand: func(m *ice.Message, arg ...string) {
|
||||
if _river_right(m, "rename") {
|
||||
_river_rename(m, m.Option(RIVER), arg[0])
|
||||
}
|
||||
mdb.RENAME: {Name: "rename name", Help: "重命名", Hand: func(m *ice.Message, arg ...string) {
|
||||
_river_rename(m, m.Option(RIVER), arg[0])
|
||||
}},
|
||||
"remove": {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
if _river_right(m, "remove") {
|
||||
_river_remove(m, m.Option(RIVER))
|
||||
}
|
||||
web.SHARE: {Name: "share name", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
|
||||
_river_share(m, m.Option(RIVER), arg[0])
|
||||
}},
|
||||
USER: {Name: "user user...", Help: "添加用户", Hand: func(m *ice.Message, arg ...string) {
|
||||
_river_user(m, m.Option(RIVER), arg...)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_river_list(m)
|
||||
|
@ -2,75 +2,19 @@ package chat
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/toolkits"
|
||||
"sync"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
"search": {Name: "search", Help: "search", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
"search": {Name: "search label pod engine word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) < 2 {
|
||||
m.Cmdy(web.LABEL, arg)
|
||||
"/" + mdb.SEARCH: {Name: "/search", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) > 2 {
|
||||
m.Cmdy(mdb.RENDER, arg)
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "add":
|
||||
if m.Richs(cmd, nil, arg[1], nil) == nil {
|
||||
m.Rich(cmd, nil, kit.Data(kit.MDB_NAME, arg[1]))
|
||||
}
|
||||
m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) {
|
||||
m.Grow(cmd, kit.Keys(kit.MDB_HASH, key), kit.Dict(
|
||||
kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3:],
|
||||
))
|
||||
})
|
||||
case "get":
|
||||
wg := &sync.WaitGroup{}
|
||||
m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) {
|
||||
wg.Add(1)
|
||||
m.Gos(m, func(m *ice.Message) {
|
||||
m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
m.Cmdy(value[kit.MDB_TEXT], arg[2:])
|
||||
})
|
||||
wg.Done()
|
||||
})
|
||||
})
|
||||
wg.Wait()
|
||||
case "set":
|
||||
if arg[1] != "" {
|
||||
m.Cmdy(web.SPACE, arg[1], "web.chat.search", "set", "", arg[2:])
|
||||
break
|
||||
}
|
||||
|
||||
m.Richs(cmd, nil, arg[2], func(key string, value map[string]interface{}) {
|
||||
m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
m.Cmdy(value[kit.MDB_TEXT], "set", arg[3:])
|
||||
})
|
||||
})
|
||||
default:
|
||||
if len(arg) < 4 {
|
||||
m.Richs(cmd, nil, kit.Select(kit.MDB_FOREACH, arg, 2), func(key string, val map[string]interface{}) {
|
||||
if len(arg) < 3 {
|
||||
m.Push(key, val[kit.MDB_META], []string{kit.MDB_TIME, kit.MDB_NAME, kit.MDB_COUNT})
|
||||
return
|
||||
}
|
||||
m.Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||
m.Push("", value, []string{kit.MDB_TIME})
|
||||
m.Push("group", arg[2])
|
||||
m.Push("", value, []string{kit.MDB_NAME, kit.MDB_TEXT})
|
||||
})
|
||||
})
|
||||
break
|
||||
}
|
||||
m.Option("pod", "")
|
||||
m.Cmdy(web.LABEL, arg[0], arg[1], "web.chat.search", "get", arg[2:])
|
||||
m.Sort("time", "time_r")
|
||||
}
|
||||
m.Cmdy(mdb.SEARCH, arg)
|
||||
}},
|
||||
}}, nil)
|
||||
},
|
||||
}, nil)
|
||||
}
|
||||
|
@ -2,75 +2,74 @@ package chat
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func _storm_list(m *ice.Message, river string) {
|
||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, river, "tool"), "*", func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value["meta"], []string{kit.MDB_KEY, kit.MDB_NAME})
|
||||
m.Set(ice.MSG_OPTION, kit.MDB_KEY)
|
||||
m.Set(ice.MSG_OPTION, kit.MDB_NAME)
|
||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, river, TOOL), kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value[kit.MDB_META], []string{kit.MDB_KEY, kit.MDB_NAME})
|
||||
})
|
||||
m.Sort(kit.MDB_NAME)
|
||||
}
|
||||
func _storm_tool(m *ice.Message, river, storm string, arg ...string) {
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, "tool", kit.MDB_HASH, storm)
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, TOOL, kit.MDB_HASH, storm)
|
||||
for i := 0; i < len(arg)-3; i += 4 {
|
||||
id := m.Grow(RIVER, kit.Keys(prefix), kit.Data(
|
||||
"pod", arg[i], "ctx", arg[i+1], "cmd", arg[i+2], "help", arg[i+3],
|
||||
POD, arg[i], CTX, arg[i+1], CMD, arg[i+2], "help", arg[i+3],
|
||||
))
|
||||
m.Log_INSERT(RIVER, river, STORM, storm, "hash", id, "tool", arg[i:i+4])
|
||||
m.Log_INSERT(RIVER, river, STORM, storm, kit.MDB_HASH, id, TOOL, arg[i:i+4])
|
||||
}
|
||||
}
|
||||
func _storm_share(m *ice.Message, river, storm, name string, arg ...string) {
|
||||
m.Cmdy(web.SHARE, web.TYPE_STORM, name, storm, RIVER, river, arg)
|
||||
m.Cmdy(web.SHARE, STORM, name, storm, RIVER, river, arg)
|
||||
}
|
||||
func _storm_rename(m *ice.Message, river, storm string, name string) {
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, "tool", kit.MDB_HASH, storm)
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, TOOL, kit.MDB_HASH, storm)
|
||||
old := m.Conf(RIVER, kit.Keys(prefix, kit.MDB_META, kit.MDB_NAME))
|
||||
m.Log_MODIFY(RIVER, river, STORM, storm, "value", name, "old", old)
|
||||
m.Log_MODIFY(RIVER, river, STORM, storm, kit.MDB_VALUE, name, "old", old)
|
||||
m.Conf(RIVER, kit.Keys(prefix, kit.MDB_META, kit.MDB_NAME), name)
|
||||
}
|
||||
func _storm_remove(m *ice.Message, river string, storm string) {
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, "tool")
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, TOOL)
|
||||
m.Richs(RIVER, kit.Keys(prefix), storm, func(value map[string]interface{}) {
|
||||
m.Log_REMOVE(RIVER, river, STORM, storm, "value", kit.Format(value))
|
||||
m.Log_REMOVE(RIVER, river, STORM, storm, kit.MDB_VALUE, kit.Format(value))
|
||||
})
|
||||
m.Conf(RIVER, kit.Keys(prefix, kit.MDB_HASH, storm), "")
|
||||
}
|
||||
|
||||
const (
|
||||
POD = "pod"
|
||||
CTX = "ctx"
|
||||
CMD = "cmd"
|
||||
ARG = "arg"
|
||||
VAL = "val"
|
||||
)
|
||||
|
||||
const STORM = "storm"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
"/storm": {Name: "/storm share|tool|rename|remove arg...", Help: "暴风雨", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[0] {
|
||||
case "share":
|
||||
// TODO check right
|
||||
_storm_share(m, m.Option(RIVER), m.Option(STORM), m.Option("name"))
|
||||
return
|
||||
}
|
||||
|
||||
if m.Warn(m.Option(ice.MSG_RIVER) == "", "not join") {
|
||||
// m.Render("status", 402, "not join")
|
||||
return
|
||||
}
|
||||
|
||||
if len(arg) < 3 {
|
||||
_storm_list(m, arg[0])
|
||||
return
|
||||
}
|
||||
|
||||
if !m.Right(cmd, arg[2]) {
|
||||
m.Render("status", 403, "not auth")
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[2] {
|
||||
case "add", "tool":
|
||||
_storm_tool(m, arg[0], arg[1], arg[3:]...)
|
||||
case "rename":
|
||||
_storm_rename(m, arg[0], arg[1], arg[3])
|
||||
case "remove":
|
||||
_storm_remove(m, arg[0], arg[1])
|
||||
}
|
||||
}},
|
||||
}}, nil)
|
||||
Index.Merge(&ice.Context{
|
||||
Commands: map[string]*ice.Command{
|
||||
"/" + STORM: {Name: "/storm", Help: "暴风雨", Action: map[string]*ice.Action{
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
_storm_remove(m, m.Option(RIVER), m.Option(STORM))
|
||||
}},
|
||||
mdb.RENAME: {Name: "rename name", Help: "重命名", Hand: func(m *ice.Message, arg ...string) {
|
||||
_storm_rename(m, m.Option(RIVER), m.Option(STORM), arg[0])
|
||||
}},
|
||||
web.SHARE: {Name: "share name", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
|
||||
_storm_share(m, m.Option(RIVER), m.Option(STORM), arg[0])
|
||||
}},
|
||||
TOOL: {Name: "tool [pod ctx cmd help]...", Help: "添加工具", Hand: func(m *ice.Message, arg ...string) {
|
||||
_storm_tool(m, m.Option(RIVER), m.Option(STORM), arg...)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_storm_list(m, m.Option(RIVER))
|
||||
}},
|
||||
},
|
||||
}, nil)
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"github.com/shylinux/toolkits/logs"
|
||||
"github.com/shylinux/toolkits/util/bench"
|
||||
@ -14,6 +13,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -109,15 +109,15 @@ func init() {
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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 type name text arg...", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -3,6 +3,8 @@ package code
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"github.com/shylinux/toolkits/task"
|
||||
@ -83,7 +85,7 @@ func _pprof_show(m *ice.Message, zone string, id string) {
|
||||
list = append(list, web.TYPE_SHELL+": "+strings.Join(cmd, " "), strings.Join(res, "\n"))
|
||||
|
||||
// 结果展示
|
||||
p := kit.Format("%s:%s", m.Conf(web.SHARE, "meta.host"), m.Cmdx("tcp.getport"))
|
||||
p := kit.Format("%s:%s", m.Conf(web.SHARE, "meta.host"), m.Cmdx(tcp.PORT, "get"))
|
||||
m.Option(cli.CMD_STDOUT, "var/daemon/stdout")
|
||||
m.Option(cli.CMD_STDERR, "var/daemon/stderr")
|
||||
m.Cmd(cli.DAEMON, m.Confv(PPROF, "meta.pprof"), "-http="+p, val[BINNARY], msg.Append(kit.MDB_TEXT))
|
||||
@ -149,11 +151,11 @@ func init() {
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
PPROF: {Name: "pprof zone=auto id=auto auto", Help: "性能分析", Action: map[string]*ice.Action{
|
||||
kit.MDB_CREATE: {Name: "create zone [binnary [service [seconds]]]", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.CREATE: {Name: "create zone [binnary [service [seconds]]]", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_pprof_create(m, arg[0], kit.Select("bin/ice.bin", arg, 1),
|
||||
kit.Select("http://localhost:9020/code/pprof/profile", arg, 2), kit.Select("3", arg, 3))
|
||||
}},
|
||||
kit.MDB_INSERT: {Name: "insert zone type name [text]", Help: "插入", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.INSERT: {Name: "insert zone type name [text]", Help: "插入", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 2 {
|
||||
arg = append(arg, "")
|
||||
}
|
||||
@ -162,7 +164,7 @@ func init() {
|
||||
}
|
||||
_pprof_insert(m, arg[0], arg[1], arg[2], kit.Select("http://localhost:9020/code/bench?cmd="+arg[2], arg, 3), arg[4:]...)
|
||||
}},
|
||||
kit.MDB_MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||
_pprof_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 type name text arg...", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -2,6 +2,7 @@ package team
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
@ -221,20 +222,20 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
|
||||
PLAN: {Name: "plan scale:select=day|week|month|year|long begin_time=@date end_time=@date auto", Help: "计划", Meta: kit.Dict(
|
||||
"display", "/plugin/local/team/plan.js", "detail", []string{StatusPrepare, StatusProcess, StatusCancel, StatusFinish},
|
||||
), Action: map[string]*ice.Action{
|
||||
kit.MDB_INSERT: {Name: "insert zone type name text begin_time end_time", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.INSERT: {Name: "insert zone type name text begin_time end_time", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
_task_create(m, arg[0])
|
||||
_task_insert(m, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5])
|
||||
}},
|
||||
kit.MDB_DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
_task_delete(m, m.Option(ZONE), m.Option(kit.MDB_ID))
|
||||
}},
|
||||
kit.MDB_MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||
_task_modify(m, m.Option(ZONE), m.Option(kit.MDB_ID), arg[0], arg[1], arg[2])
|
||||
}},
|
||||
kit.MDB_IMPORT: {Name: "import file", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.IMPORT: {Name: "import file", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
_task_import(m, kit.Select(EXPORT, arg, 0))
|
||||
}},
|
||||
kit.MDB_EXPORT: {Name: "export file", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.EXPORT: {Name: "export file", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
_task_export(m, kit.Select(EXPORT, arg, 0))
|
||||
}},
|
||||
"plugin": {Name: "plugin", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -284,10 +285,10 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
|
||||
})
|
||||
}},
|
||||
TASK: {Name: "task zone=auto id=auto auto", Help: "任务", Action: map[string]*ice.Action{
|
||||
kit.MDB_DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
_task_delete(m, m.Option(ZONE), m.Option(kit.MDB_ID))
|
||||
}},
|
||||
kit.MDB_MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||
_task_modify(m, m.Option(ZONE), m.Option(kit.MDB_ID), arg[0], arg[1], arg[2])
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
8
exec.go
8
exec.go
@ -17,12 +17,12 @@ func (m *Message) TryCatch(msg *Message, safe bool, hand ...func(msg *Message))
|
||||
case io.EOF:
|
||||
case nil:
|
||||
default:
|
||||
fileline := kit.FileLine(3, 2)
|
||||
m.Log(LOG_WARN, "catch: %s", e, fileline)
|
||||
fileline := kit.FileLine(5, 2)
|
||||
m.Log(LOG_WARN, "catch: %s %s", e, fileline)
|
||||
m.Log(LOG_INFO, "chain: %s", msg.Format("chain"))
|
||||
m.Log(LOG_WARN, "catch: %s", e, fileline)
|
||||
m.Log(LOG_WARN, "catch: %s %s", e, fileline)
|
||||
m.Log(LOG_INFO, "stack: %s", msg.Format("stack"))
|
||||
m.Log(LOG_WARN, "catch: %s", e, fileline)
|
||||
m.Log(LOG_WARN, "catch: %s %s", e, fileline)
|
||||
if len(hand) > 1 {
|
||||
// 捕获异常
|
||||
m.TryCatch(msg, safe, hand[1:]...)
|
||||
|
34
init.go
34
init.go
@ -2,12 +2,7 @@ package ice
|
||||
|
||||
import (
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"github.com/shylinux/toolkits/conf"
|
||||
"github.com/shylinux/toolkits/logs"
|
||||
"github.com/shylinux/toolkits/miss"
|
||||
"github.com/shylinux/toolkits/task"
|
||||
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
@ -90,7 +85,7 @@ var Index = &Context{Name: "ice", Help: "冰山模块",
|
||||
},
|
||||
Commands: map[string]*Command{
|
||||
CTX_INIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
||||
defer m.Cost(CTX_INIT)
|
||||
defer m.Cost("_init ice")
|
||||
m.Travel(func(p *Context, c *Context) {
|
||||
if cmd, ok := c.Commands[CTX_INIT]; ok && p != nil {
|
||||
c.cmd(m.Spawns(c), cmd, CTX_INIT, arg...)
|
||||
@ -149,10 +144,6 @@ func Run(arg ...string) string {
|
||||
arg = append(arg, "web.space", "connect", "self")
|
||||
}
|
||||
|
||||
log.Init(conf.Sub("log"))
|
||||
miss.Init(conf.Sub("miss"))
|
||||
task.Init(conf.Sub("task"))
|
||||
|
||||
frame := &Frame{}
|
||||
Index.root = Index
|
||||
Index.server = frame
|
||||
@ -176,11 +167,28 @@ func Run(arg ...string) string {
|
||||
|
||||
var names = map[string]interface{}{}
|
||||
|
||||
var ErrNameExists = errors.New("name already exists")
|
||||
var ErrNameExists = "name already exists:"
|
||||
|
||||
type Error struct {
|
||||
Arg []interface{}
|
||||
FileLine string
|
||||
}
|
||||
|
||||
func NewError(n int, arg ...interface{}) *Error {
|
||||
return &Error{Arg: arg, FileLine: kit.FileLine(n, 3)}
|
||||
}
|
||||
func (e *Error) Error() string {
|
||||
return e.FileLine + " " + strings.Join(kit.Simple(e.Arg), " ")
|
||||
}
|
||||
|
||||
func Name(name string, value interface{}) string {
|
||||
if _, ok := names[name]; ok {
|
||||
panic(ErrNameExists)
|
||||
if s, ok := names[name]; ok {
|
||||
last := ""
|
||||
switch s := s.(type) {
|
||||
case *Context:
|
||||
last = s.Name
|
||||
}
|
||||
panic(NewError(4, ErrNameExists, name, "last:", last))
|
||||
}
|
||||
names[name] = value
|
||||
return name
|
||||
|
3
logs.go
3
logs.go
@ -35,6 +35,7 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message {
|
||||
// 文件行号
|
||||
switch level {
|
||||
case LOG_CMDS, LOG_INFO, LOG_WARN, "refer", "form":
|
||||
case "register", "begin":
|
||||
default:
|
||||
suffix += " " + kit.FileLine(3, 2)
|
||||
}
|
||||
@ -105,7 +106,7 @@ func (m *Message) Log_INSERT(arg ...interface{}) *Message {
|
||||
func (m *Message) Log_DELETE(arg ...interface{}) *Message {
|
||||
return m.log(LOG_DELETE, log_fields(arg...))
|
||||
}
|
||||
func (m *Message) Log_SELETE(arg ...interface{}) *Message {
|
||||
func (m *Message) Log_SELECT(arg ...interface{}) *Message {
|
||||
return m.log(LOG_SELECT, log_fields(arg...))
|
||||
}
|
||||
func (m *Message) Log_MODIFY(arg ...interface{}) *Message {
|
||||
|
2
meta.go
2
meta.go
@ -319,7 +319,7 @@ func (m *Message) Table(cbs ...func(index int, value map[string]string, head []s
|
||||
return m
|
||||
}
|
||||
func (m *Message) Render(cmd string, args ...interface{}) *Message {
|
||||
m.Log(LOG_EXPORT, "%s: %v", cmd, args)
|
||||
// m.Log(LOG_EXPORT, "%s: %v", cmd, args)
|
||||
m.Optionv(MSG_OUTPUT, cmd)
|
||||
m.Optionv(MSG_ARGS, args)
|
||||
|
||||
|
2
misc.go
2
misc.go
@ -39,7 +39,7 @@ func (m *Message) Right(arg ...interface{}) bool {
|
||||
return m.Option(MSG_USERROLE) == "root" || !m.Warn(m.Cmdx("aaa.role", "right", m.Option(MSG_USERROLE), kit.Keys(arg...)) != "ok", "no right")
|
||||
}
|
||||
func (m *Message) Space(arg interface{}) []string {
|
||||
if arg == nil || kit.Format(arg) == m.Conf("cli.runtime", "node.name") {
|
||||
if arg == nil || arg == "" || kit.Format(arg) == m.Conf("cli.runtime", "node.name") {
|
||||
return nil
|
||||
}
|
||||
return []string{"web.space", kit.Format(arg)}
|
||||
|
16
type.go
16
type.go
@ -137,11 +137,7 @@ func (c *Context) Register(s *Context, x Server, name ...string) *Context {
|
||||
s.server = x
|
||||
return s
|
||||
}
|
||||
func (c *Context) Merge(s *Context, x Server, name ...string) *Context {
|
||||
for _, n := range name {
|
||||
Name(n, s)
|
||||
}
|
||||
|
||||
func (c *Context) Merge(s *Context, x Server) *Context {
|
||||
if c.Commands == nil {
|
||||
c.Commands = map[string]*Command{}
|
||||
}
|
||||
@ -193,7 +189,7 @@ func (c *Context) Begin(m *Message, arg ...string) *Context {
|
||||
} else if c.context != nil {
|
||||
c.Cap(CTX_FOLLOW, kit.Keys(c.context.Cap(CTX_FOLLOW), c.Name))
|
||||
}
|
||||
m.Logs(LOG_BEGIN, CTX_FOLLOW, c.Cap(CTX_FOLLOW))
|
||||
m.Log(LOG_BEGIN, c.Cap(CTX_FOLLOW))
|
||||
c.Cap(CTX_STATUS, CTX_BEGIN)
|
||||
|
||||
if c.begin = m; c.server != nil {
|
||||
@ -210,7 +206,7 @@ func (c *Context) Start(m *Message, arg ...string) bool {
|
||||
|
||||
wait := make(chan bool)
|
||||
m.Gos(m, func(m *Message) {
|
||||
m.Logs(LOG_START, CTX_FOLLOW, c.Cap(CTX_FOLLOW))
|
||||
m.Log(LOG_START, c.Cap(CTX_FOLLOW))
|
||||
c.Cap(CTX_STATUS, CTX_START)
|
||||
|
||||
// 启动模块
|
||||
@ -469,6 +465,9 @@ func (m *Message) Travel(cb interface{}) *Message {
|
||||
return m
|
||||
}
|
||||
func (m *Message) Search(key interface{}, cb interface{}) *Message {
|
||||
if key == "" {
|
||||
return m
|
||||
}
|
||||
switch key := key.(type) {
|
||||
case string:
|
||||
// 查找模块
|
||||
@ -484,6 +483,9 @@ func (m *Message) Search(key interface{}, cb interface{}) *Message {
|
||||
} else if strings.Contains(key, ".") {
|
||||
list := strings.Split(key, ".")
|
||||
for _, p = range []*Context{m.target.root, m.target, m.source} {
|
||||
if p == nil {
|
||||
continue
|
||||
}
|
||||
for _, v := range list[:len(list)-1] {
|
||||
if s, ok := p.contexts[v]; ok {
|
||||
p = s
|
||||
|
Loading…
x
Reference in New Issue
Block a user