diff --git a/base/aaa/sess.go b/base/aaa/sess.go index 2a869c67..1d6e0759 100644 --- a/base/aaa/sess.go +++ b/base/aaa/sess.go @@ -62,6 +62,7 @@ const ( GRANT = "grant" LOGIN = "login" LOGOUT = "logout" + EXPIRE = "expire" ) const ( SESS_CREATE = "sess.create" diff --git a/base/aaa/user.go b/base/aaa/user.go index 9ab4bbcc..9126bc90 100644 --- a/base/aaa/user.go +++ b/base/aaa/user.go @@ -120,9 +120,6 @@ func init() { )}, }, Commands: map[string]*ice.Command{ USER: {Name: "user username auto create", Help: "用户", Action: ice.MergeAction(map[string]*ice.Action{ - ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { - UserRoot(ice.Pulse) - }}, mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { if arg[0] == USER { _user_search(m, arg[1], kit.Select("", arg, 2)) diff --git a/base/cli/runtime.go b/base/cli/runtime.go index c195919e..db8c95b2 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -7,6 +7,7 @@ import ( "strings" ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" @@ -50,6 +51,7 @@ func _runtime_init(m *ice.Message) { ice.Info.HostName = m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME)) ice.Info.PathName = m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME)) ice.Info.UserName = m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME)) + aaa.UserRoot(ice.Pulse) // 启动次数 boot m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))+1) @@ -151,8 +153,8 @@ func init() { }, Commands: map[string]*ice.Command{ RUNTIME: {Name: "runtime info=ifconfig,hostinfo,hostname,userinfo,procinfo,bootinfo,diskinfo,env,file,route auto", Help: "运行环境", Action: map[string]*ice.Action{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { - _runtime_init(m) m.Cmd(RUNTIME, MAXPROCS, "1") + _runtime_init(m) }}, MAXPROCS: {Name: "maxprocs", Help: "最大并发", Hand: func(m *ice.Message, arg ...string) { if len(arg) > 0 { diff --git a/base/ctx/command.go b/base/ctx/command.go index 2ed48d90..09de07fc 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -12,18 +12,20 @@ import ( ) func _command_list(m *ice.Message, name string) { - switch kit.Ext(name) { - case nfs.JS: - m.Push(DISPLAY, ice.FileURI(name)) - name = kit.Select(CAN_PLUGIN, ice.GetFileCmd(name)) + if kit.FileExists(path.Join(ice.SRC, name)) { + switch kit.Ext(name) { + case nfs.JS: + m.Push(DISPLAY, ice.FileURI(name)) + name = kit.Select(CAN_PLUGIN, ice.GetFileCmd(name)) - case nfs.GO: - name = ice.GetFileCmd(name) + case nfs.GO: + name = ice.GetFileCmd(name) - default: - if file, msg := name, m.Cmd(mdb.RENDER, kit.Ext(name)); msg.Length() > 0 && kit.FileExists(path.Join(ice.SRC, name)) { - m.Push(ARGS, kit.Format(kit.List(file))) - name = kit.Keys(msg.Append(mdb.TEXT), msg.Append(mdb.NAME)) + default: + if file, msg := name, m.Cmd(mdb.RENDER, kit.Ext(name)); msg.Length() > 0 { + m.Push(ARGS, kit.Format(kit.List(file))) + name = kit.Keys(msg.Append(mdb.TEXT), msg.Append(mdb.NAME)) + } } } if strings.HasPrefix(name, "can.") { diff --git a/base/lex/split.go b/base/lex/split.go index b4c925d6..ceafc1f6 100644 --- a/base/lex/split.go +++ b/base/lex/split.go @@ -57,6 +57,8 @@ func _split_list(m *ice.Message, file string, arg ...string) map[string]interfac ls = cb(deep, ls, data) case func([]string, map[string]interface{}) []string: ls = cb(ls, data) + case func([]string): + cb(ls) } // 参数字段 diff --git a/base/mdb/mdb.go b/base/mdb/mdb.go index 86380399..e73210e4 100644 --- a/base/mdb/mdb.go +++ b/base/mdb/mdb.go @@ -143,11 +143,8 @@ func NextPageLimit(m *ice.Message, total string, arg ...string) { const MDB = "mdb" var Index = &ice.Context{Name: MDB, Help: "数据模块", Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - ice.Pulse.Option(ice.CACHE_LIMIT, "10") - }}, - ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - }}, + ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, + ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, INSERT: {Name: "insert key sub type arg...", Help: "添加", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { switch arg[2] { case ZONE: // insert key sub type zone arg... diff --git a/base/web/render.go b/base/web/render.go index d5e82937..e6875808 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -83,13 +83,12 @@ func CookieName(url string) string { return ice.MSG_SESSID + "_" + kit.ReplaceAll(kit.ParseURLMap(url)[tcp.HOST], ".", "_", ":", "_") } 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))) + expire := time.Now().Add(kit.Duration(kit.Select(msg.Conf(aaa.SESS, kit.Keym(aaa.EXPIRE)), arg, 2))) http.SetCookie(msg.W, &http.Cookie{Value: value, Name: kit.Select(CookieName(msg.Option(ice.MSG_USERWEB)), arg, 0), Path: kit.Select(ice.PS, arg, 1), Expires: expire}) } func RenderRedirect(msg *ice.Message, arg ...string) { - // http.Redirect(msg.W, msg.R, kit.MergeURL(arg[0], arg[1:]), http.StatusTemporaryRedirect) - http.Redirect(msg.W, msg.R, kit.MergeURL(arg[0], arg[1:]), http.StatusMovedPermanently) + http.Redirect(msg.W, msg.R, kit.MergeURL(arg[0], arg[1:]), http.StatusTemporaryRedirect) } func RenderType(w http.ResponseWriter, name, mime string) { if mime != "" { diff --git a/base/web/serve.go b/base/web/serve.go index 19573068..e4f1365e 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -58,7 +58,7 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool { } else { r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, ":")[0]) } - m.Info("").Info("%s %s %s", r.Header.Get(ice.MSG_USERIP), r.Method, r.URL) + m.Info("%s %s %s", r.Header.Get(ice.MSG_USERIP), r.Method, r.URL) // 参数日志 if m.Config(LOGHEADERS) == ice.TRUE { @@ -111,19 +111,10 @@ func _serve_params(msg *ice.Message, path string) { msg.Logs("refer", ls[2], ls[3]) msg.Option(ls[2], ls[3]) } - case ice.POD: - msg.Logs("refer", ls[1], ls[2]) - msg.Option(ls[1], ls[2]) } } func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.ResponseWriter, r *http.Request) { - // 会话变量 - msg.Option(ice.MSG_SESSID, "") - for _, v := range r.Cookies() { - msg.Option(v.Name, v.Value) - } - - // 请求参数 + // 地址参数 if u, e := url.Parse(r.Header.Get("Referer")); e == nil { _serve_params(msg, u.Path) for k, v := range u.Query() { @@ -133,9 +124,10 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon } _serve_params(msg, r.URL.Path) - // 请求数据 + // 请求参数 switch r.Header.Get(ContentType) { case ContentJSON: + defer r.Body.Close() var data interface{} if e := json.NewDecoder(r.Body).Decode(&data); !msg.Warn(e, ice.ErrNotFound, data) { msg.Log_IMPORT(mdb.VALUE, kit.Format(data)) @@ -148,7 +140,7 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon if r.ParseForm(); len(r.PostForm) > 0 { for k, v := range r.PostForm { if len(v) > 1 { - msg.Logs("form", k, len(v), kit.Format(v)) + msg.Logs("form", k, len(v), kit.Join(v, ice.SP)) } else { msg.Logs("form", k, v) } @@ -156,19 +148,8 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon } } - // 请求地址 + // 请求参数 msg.R, msg.W = r, w - msg.Option(ice.MSG_USERWEB, _serve_domain(msg)) - msg.Option(ice.MSG_USERADDR, kit.Select(r.RemoteAddr, r.Header.Get(ice.MSG_USERADDR))) - msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP)) - msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent")) - - // 会话别名 - if sessid := msg.Option(CookieName(msg.Option(ice.MSG_USERWEB))); sessid != "" { - msg.Option(ice.MSG_SESSID, sessid) - } - - // 参数转换 for k, v := range r.Form { if msg.IsCliUA() { for i, p := range v { @@ -176,31 +157,55 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon } } if msg.Optionv(k, v); k == ice.MSG_SESSID { + msg.Option(ice.MSG_SESSID, v[0]) RenderCookie(msg, v[0]) } } + for k, v := range r.PostForm { + msg.Optionv(k, v) + } - if msg.Option(ice.MSG_USERPOD, msg.Option(ice.POD)); msg.Optionv(ice.MSG_CMDS) == nil { - if p := strings.TrimPrefix(r.URL.Path, key); p != "" { // 地址命令 + // 会话参数 + for _, v := range r.Cookies() { + msg.Option(v.Name, v.Value) + } + + // 用户参数 + msg.Option(ice.MSG_USERWEB, _serve_domain(msg)) + msg.Option(ice.MSG_USERADDR, kit.Select(r.RemoteAddr, r.Header.Get(ice.MSG_USERADDR))) + msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP)) + msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent")) + if msg.Option(ice.POD) != "" { + msg.Option(ice.MSG_USERPOD, msg.Option(ice.POD)) + } + + // 会话参数 + if sessid := msg.Option(CookieName(msg.Option(ice.MSG_USERWEB))); msg.Option(ice.MSG_SESSID) == "" { + msg.Option(ice.MSG_SESSID, sessid) + } + + // 解析命令 + if msg.Optionv(ice.MSG_CMDS) == nil { + if p := strings.TrimPrefix(r.URL.Path, key); p != "" { msg.Optionv(ice.MSG_CMDS, strings.Split(p, ice.PS)) } } - msg.Option(ice.MSG_OUTPUT, "") + // 执行命令 if cmds, ok := _serve_login(msg, key, kit.Simple(msg.Optionv(ice.MSG_CMDS)), w, r); ok { - msg.Option(ice.MSG_OPTS, msg.Optionv(ice.MSG_OPTION)) - msg.Target().Cmd(msg, key, cmds...) // 执行命令 - msg.Cost(kit.Format("%s %v %v", r.URL.Path, cmds, msg.FormatSize())) + defer func() { msg.Cost(kit.Format("%s %v %v", r.URL.Path, cmds, msg.FormatSize())) }() + msg.Option(ice.MSG_OPTS, kit.Filter(kit.Simple(msg.Optionv(ice.MSG_OPTION)), func(k string) bool { + return !strings.HasPrefix(k, ice.MSG_SESSID) + })) + msg.Target().Cmd(msg, key, cmds...) } // 输出响应 switch args := msg.Optionv(ice.MSG_ARGS).(type) { case []interface{}: Render(msg, msg.Option(ice.MSG_OUTPUT), args...) - case []string: - Render(msg, msg.Option(ice.MSG_OUTPUT), args) default: - Render(msg, msg.Option(ice.MSG_OUTPUT), kit.List()) + Render(msg, msg.Option(ice.MSG_OUTPUT), args) } } func _serve_login(msg *ice.Message, key string, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) { @@ -211,7 +216,7 @@ func _serve_login(msg *ice.Message, key string, cmds []string, w http.ResponseWr } if msg.Option(ice.MSG_USERNAME) == "" && msg.Config(tcp.LOCALHOST) == ice.TRUE && tcp.IsLocalHost(msg, msg.Option(ice.MSG_USERIP)) { - aaa.UserRoot(msg) // 主机认证 + aaa.UserRoot(msg) // 本机认证 } if msg.Option(ice.MSG_USERNAME) == "" && msg.Option(SHARE) != "" { @@ -299,7 +304,7 @@ func init() { repos := kit.Select(ice.INTSHELL, ice.VOLCANOS, strings.Contains(r.Header.Get("User-Agent"), "Mozilla/5.0")) if repos == ice.VOLCANOS { - if s := msg.Cmdx("web.chat.website", "show", "index.iml", "Header", "", "River", "", "Action", "", "Footer", ""); s != "" { + if s := msg.Cmdx("web.chat.website", "show", "index.iml", "Header", "", "River", ""); s != "" { Render(msg, ice.RENDER_RESULT, s) return true } @@ -334,23 +339,20 @@ func init() { m.Config(kit.Keys(aaa.WHITE, k), ice.TRUE) } }}, - cli.START: {Name: "start dev name=ops proto=http host port=9020 nodename password username userrole staffname", Help: "启动", Hand: func(m *ice.Message, arg ...string) { - ice.Info.Domain = kit.Select(kit.Format("%s://%s:%s", m.Option(tcp.PROTO), - kit.Select(m.Cmd(tcp.HOST).Append(aaa.IP), m.Option(tcp.HOST)), m.Option(tcp.PORT)), ice.Info.Domain) + cli.START: {Name: "start dev proto=http host port=9020 nodename password username userrole staffname", Help: "启动", Hand: func(m *ice.Message, arg ...string) { + ice.Info.Domain = kit.Select(kit.Format("%s://%s:%s", m.Option(tcp.PROTO), kit.Select(m.Cmd(tcp.HOST).Append(aaa.IP), m.Option(tcp.HOST)), m.Option(tcp.PORT)), ice.Info.Domain) if cli.NodeInfo(m, SERVER, kit.Select(ice.Info.HostName, m.Option("nodename"))); m.Option(tcp.PORT) == tcp.RANDOM { m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT)) } if m.Option("staffname") != "" { - m.Config("staffname", m.Option("staffname")) - m.Option(aaa.USERNAME, m.Option("staffname")) + m.Config("staffname", m.Option(aaa.USERNAME, m.Option("staffname"))) } aaa.UserRoot(m, m.Option(aaa.PASSWORD), m.Option(aaa.USERNAME), m.Option(aaa.USERROLE)) - m.Go(func() { m.Cmd(BROAD, SERVE) }) - m.Target().Start(m, m.OptionSimple(mdb.NAME, tcp.HOST, tcp.PORT)...) + m.Go(func() { m.Cmd(BROAD, SERVE) }) + m.Target().Start(m, m.OptionSimple(tcp.HOST, tcp.PORT)...) m.Sleep300ms() - m.Option(mdb.NAME, "") for _, k := range kit.Split(m.Option(ice.DEV)) { m.Cmd(SPACE, tcp.DIAL, ice.DEV, k, mdb.NAME, ice.Info.NodeName) } diff --git a/base/web/space.go b/base/web/space.go index f12456df..537bfdd7 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -93,7 +93,7 @@ func _space_handle(m *ice.Message, safe bool, send map[string]*ice.Message, c *w if len(target) == 0 { if msg.Option(ice.MSG_HANDLE) == ice.TRUE { - msg.Debug("what %v %v", msg.FormatMeta(), msg.FormatStack()) + msg.Debug("what %v %v", msg.FormatMeta(), msg.FormatStack(1, 100)) continue } if msg.Optionv(ice.MSG_HANDLE, ice.TRUE); safe { // 下行命令 diff --git a/base/web/web.go b/base/web/web.go index 43a76eae..1551b2c4 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -83,7 +83,7 @@ func (web *Frame) Start(m *ice.Message, arg ...string) bool { cb(web) // 启动框架 default: m.Cmd(tcp.SERVER, tcp.LISTEN, mdb.TYPE, WEB, m.OptionSimple(mdb.NAME, tcp.HOST, tcp.PORT), func(l net.Listener) { - m.Cmdy(mdb.INSERT, SERVE, "", mdb.HASH, arg, m.OptionSimple(tcp.PROTO, ice.DEV), cli.STATUS, tcp.START) + m.Cmdy(mdb.INSERT, SERVE, "", mdb.HASH, mdb.NAME, WEB, arg, m.OptionSimple(tcp.PROTO, ice.DEV), cli.STATUS, tcp.START) defer m.Cmd(mdb.MODIFY, SERVE, "", mdb.HASH, m.OptionSimple(mdb.NAME), cli.STATUS, tcp.STOP) m.Warn(web.Server.Serve(l)) // 启动服务 }) diff --git a/core/chat/cmd.go b/core/chat/cmd.go index 4a79d429..649fdcc9 100644 --- a/core/chat/cmd.go +++ b/core/chat/cmd.go @@ -13,19 +13,6 @@ import ( ) func _cmd_file(m *ice.Message, arg ...string) bool { - // if mdb.HashSelect(m.Spawn(), path.Join(arg...)).Table(func(index int, value map[string]string, head []string) { - // m.RenderCmd(value[mdb.NAME]) - // }).Length() > 0 { - // return true - // } - // - // p := path.Join(m.Config(nfs.PATH), path.Join(arg...)) - // if mdb.HashSelect(m.Spawn(), kit.Ext(p)).Table(func(index int, value map[string]string, head []string) { - // m.RenderCmd(value[mdb.NAME], p) - // }).Length() > 0 { - // return true - // } - // switch p := path.Join(arg...); kit.Ext(p) { case nfs.JS: m.Display(ice.FileURI(p)) @@ -50,10 +37,11 @@ func _cmd_file(m *ice.Message, arg ...string) bool { m.RenderCmd("can.parse", m.Cmdx(nfs.CAT, p)) default: - p = strings.TrimPrefix(p, ice.SRC+ice.PS) - if msg := m.Cmd(mdb.RENDER, kit.Ext(p)); msg.Length() > 0 && kit.FileExists(path.Join(ice.SRC, p)) { - m.Cmdy(mdb.RENDER, kit.Ext(p), p, ice.SRC+ice.PS).RenderResult() - break + if p = strings.TrimPrefix(p, ice.SRC+ice.PS); kit.FileExists(path.Join(ice.SRC, p)) { + if msg := m.Cmd(mdb.RENDER, kit.Ext(p)); msg.Length() > 0 { + m.Cmdy(mdb.RENDER, kit.Ext(p), p, ice.SRC+ice.PS).RenderResult() + break + } } return false } diff --git a/core/chat/website.go b/core/chat/website.go index 4ce445e8..68087ddd 100644 --- a/core/chat/website.go +++ b/core/chat/website.go @@ -31,8 +31,7 @@ func _website_parse(m *ice.Message, text string, args ...string) (map[string]int river, storm, last := kit.Dict( "Header", kit.Dict("menus", kit.List(), "style", kit.Dict("display", "none")), "River", kit.Dict("menus", kit.List(), "action", kit.List()), - "Action", kit.Dict("menus", kit.List(), "action", kit.List(), "legend_event", "onclick"), - "Footer", kit.Dict("style", kit.Dict("display", "none")), args, + args, ), kit.Dict(), kit.Dict() prefix := "" @@ -69,10 +68,6 @@ func _website_parse(m *ice.Message, text string, args ...string) (map[string]int last[mdb.LIST] = append(last[mdb.LIST].([]interface{}), kit.Dict(mdb.INDEX, kit.Keys(prefix, v), "order", len(last))) } return ls - default: - if msg := m.Cmd(mdb.RENDER, kit.Ext(ls[0])); msg.Length() > 0 { - ls[0], data[ctx.ARGS] = kit.Keys(msg.Append(mdb.TEXT), msg.Append(mdb.NAME)), kit.List(ls[0]) - } } if ls[0] == "" { @@ -179,6 +174,9 @@ func init() { m.Cmd(mdb.ENGINE, mdb.CREATE, nfs.TXT, m.PrefixKey()) web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool { + if r.Method != http.MethodGet { + return false + } if ok := true; m.Richs(WEBSITE, nil, r.URL.Path, func(key string, value map[string]interface{}) { value = kit.GetMeta(value) ok = _website_render(m, w, r, kit.Format(value[mdb.TYPE]), kit.Format(value[mdb.TEXT])) @@ -186,27 +184,28 @@ func init() { return true } if strings.HasPrefix(r.URL.Path, CHAT_WEBSITE) { - if r.Method == http.MethodGet { - _website_render(m, w, r, kit.Ext(r.URL.Path), m.Cmdx(nfs.CAT, strings.Replace(r.URL.Path, CHAT_WEBSITE, SRC_WEBSITE, 1))) - return true - } + _website_render(m, w, r, kit.Ext(r.URL.Path), m.Cmdx(nfs.CAT, strings.Replace(r.URL.Path, CHAT_WEBSITE, SRC_WEBSITE, 1))) + return true } return false }) }}, "show": {Hand: func(m *ice.Message, arg ...string) { - if kit.Ext(arg[0]) == nfs.ZML { + switch kit.Ext(arg[0]) { + case nfs.ZML: m.RenderCmd("can.parse", m.Cmdx(nfs.CAT, path.Join(SRC_WEBSITE, arg[0]))) - return - } - if text := m.Cmd(m.PrefixKey(), ice.PS+arg[0]).Append(mdb.TEXT); text != "" { - if res, ok := _website_parse(m, text, arg[1:]...); ok { + + case nfs.IML: + if res, ok := _website_parse(m, m.Cmdx(nfs.CAT, path.Join(SRC_WEBSITE, arg[0])), arg[1:]...); ok { m.Echo(_website_template2, kit.Format(res)) - return } - } - if res, ok := _website_parse(m, m.Cmdx(nfs.CAT, path.Join(SRC_WEBSITE, arg[0])), arg[1:]...); ok { - m.Echo(_website_template2, kit.Format(res)) + + default: + if text := m.Cmd(m.PrefixKey(), ice.PS+arg[0]).Append(mdb.TEXT); text != "" { + if res, ok := _website_parse(m, text, arg[1:]...); ok { + m.Echo(_website_template2, kit.Format(res)) + } + } } }}, "inner": {Hand: func(m *ice.Message, arg ...string) {}}, diff --git a/core/code/autogen.go b/core/code/autogen.go index 16b67dac..c4ebebde 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -199,7 +199,6 @@ func init() { }}, BINPACK: {Name: "binpack", Help: "打包:生成 src/binpack.go", Hand: func(m *ice.Message, arg ...string) { _autogen_version(m) - m.Cmdy(WEBPACK, mdb.CREATE) if m.Cmd(BINPACK, mdb.CREATE); kit.FileExists(ice.USR_RELEASE) && m.Option(ice.MSG_USERPOD) == "" { m.Cmd(nfs.COPY, path.Join(ice.USR_RELEASE, "conf.go"), path.Join(ice.USR_ICEBERGS, "conf.go")) m.Cmd(cli.SYSTEM, "sh", "-c", `cat src/binpack.go|sed 's/package main/package ice/g' > usr/release/binpack.go`) diff --git a/core/code/go.go b/core/code/go.go index 2052b37f..767c513e 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -5,6 +5,7 @@ import ( "os" "path" "strings" + "sync" "time" ice "shylinux.com/x/icebergs" @@ -57,15 +58,62 @@ func _go_find(m *ice.Message, key string, dir string) { func _go_grep(m *ice.Message, key string, dir string) { m.Cmd(nfs.GREP, dir, key).Tables(func(value map[string]string) { m.PushSearch(value) }) } -func _go_exec(m *ice.Message, arg ...string) { - if key := ice.GetFileCmd(path.Join(arg[2], arg[1])); key != "" { - m.Cmdy(cli.SYSTEM, GO, ice.RUN, ice.SRC_MAIN_GO, key) - } else if m.Option(cli.CMD_DIR, arg[2]); strings.HasSuffix(arg[1], "_test.go") { - m.Cmdy(cli.SYSTEM, GO, "test", "-v", nfs.PWD+arg[1]) - } else { - m.Cmdy(cli.SYSTEM, GO, ice.RUN, nfs.PWD+arg[1]) + +var _cache_mods = map[string]*ice.Message{} +var _cache_lock = sync.Mutex{} + +func _go_doc(m *ice.Message, mod string, pkg string) *ice.Message { + _cache_lock.Lock() + defer _cache_lock.Unlock() + + key := kit.Keys(mod, pkg) + if msg, ok := _cache_mods[key]; ok && kit.Time(msg.Time("24h")) > kit.Time(m.Time()) { + return msg + } + + if mod != "" { + m.Cmd(cli.SYSTEM, "go", "get", mod) + } + if msg := _vimer_go_complete(m.Spawn(), key); msg.Length() > 0 { + _cache_mods[key] = msg + return msg + } + return nil +} + +func _go_exec(m *ice.Message, arg ...string) { + if m.Option(mdb.TEXT) == "" { + if m.Option(nfs.LINE) == "1" { + m.Push(mdb.NAME, "package") + } else { + m.Push(mdb.NAME, "import") + m.Push(mdb.NAME, "const") + m.Push(mdb.NAME, "type") + m.Push(mdb.NAME, "func") + } + return + } + + if m.Option(mdb.NAME) == ice.PT { + switch m.Option(mdb.TYPE) { + case "msg", "m": + m.Copy(_go_doc(m, "shylinux.com/x/ice", "Message")) + m.Copy(_go_doc(m, "shylinux.com/x/icebergs", "Message")) + + case "ice", "*ice": + m.Copy(_go_doc(m, "shylinux.com/x/ice", "")) + + case "kit": + m.Copy(_go_doc(m, "shylinux.com/x/toolkits", "")) + + default: + m.Copy(_go_doc(m, "", m.Option(mdb.TYPE))) + } + + } else { + m.Push(mdb.NAME, "msg") + m.Push(mdb.NAME, "ice") } - m.SetAppend() } func _go_show(m *ice.Message, arg ...string) { if arg[1] == "main.go" { diff --git a/core/code/js.go b/core/code/js.go index 8cc369ad..8abd47ae 100644 --- a/core/code/js.go +++ b/core/code/js.go @@ -28,6 +28,22 @@ func _js_main_script(m *ice.Message, arg ...string) (res []string) { return } +func _js_exec(m *ice.Message, arg ...string) { + if m.Option(mdb.NAME) == ice.PT { + switch m.Option(mdb.TYPE) { + case "msg": + m.Cmdy("web.code.vim.tags", "msg").Cut("name,text") + case "can": + m.Cmdy("web.code.vim.tags").Cut(mdb.ZONE) + default: + m.Cmdy("web.code.vim.tags", strings.TrimPrefix(m.Option(mdb.TYPE), "can.")).Cut("name,text") + } + } else { + m.Push(mdb.NAME, "msg") + m.Push(mdb.NAME, "can") + } +} + const JS = "js" const CSS = "css" const HTML = "html" @@ -57,8 +73,7 @@ func init() { m.ProcessCommand(kit.Select("can.code.inner.plugin", key), kit.Simple()) }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(cli.SYSTEM, NODE, "-e", kit.Join(_js_main_script(m, arg...), ice.NL)).SetAppend() - m.Echo(ice.NL) + _js_exec(m, arg...) }}, mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { if arg[0] == mdb.FOREACH { diff --git a/core/code/sh.go b/core/code/sh.go index 0845aea6..184e992e 100644 --- a/core/code/sh.go +++ b/core/code/sh.go @@ -32,10 +32,24 @@ _list() { return } +func _sh_exec(m *ice.Message, arg ...string) { + if m.Option(mdb.TEXT) == "" { + // if _cache_bin != nil { + // m.Copy(_cache_bin) + // break + // } + // _cache_bin = m + + // m.Push(mdb.NAME, "_list") + // _vimer_list(m, "/bin") + // _vimer_list(m, "/sbin") + } +} + const SH = nfs.SH func init() { - Index.Merge(&ice.Context{Name: SH, Help: "命令", Commands: map[string]*ice.Command{ + Index.Register(&ice.Context{Name: SH, Help: "命令", Commands: map[string]*ice.Command{ SH: {Name: "sh path auto", Help: "命令", Action: ice.MergeAction(map[string]*ice.Action{ ice.CTX_INIT: {Name: "_init", Help: "初始化", Hand: func(m *ice.Message, arg ...string) { for _, cmd := range []string{mdb.SEARCH, mdb.ENGINE, mdb.RENDER, mdb.PLUGIN} { @@ -54,7 +68,7 @@ func init() { _go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2]) }}, mdb.ENGINE: {Name: "engine", Help: "引擎", Hand: func(m *ice.Message, arg ...string) { - _sh_main_script(m, arg...) + _sh_exec(m, arg...) }}, mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { _sh_main_script(m, arg...) @@ -101,5 +115,5 @@ func init() { ), ), KEYWORD, kit.Dict(), ))}, - }}) + }}, nil) } diff --git a/core/code/shy.go b/core/code/shy.go index 5403ec8c..ab315804 100644 --- a/core/code/shy.go +++ b/core/code/shy.go @@ -2,18 +2,39 @@ package code import ( "path" + "strings" ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/cli" + "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" - "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" ) +func _shy_exec(m *ice.Message, arg ...string) { + switch left := kit.Select("", kit.Slice(kit.Split(m.Option(mdb.TEXT), "\t \n`"), -1), 0); strings.TrimSpace(left) { + case cli.FG, cli.BG: + m.Push(mdb.NAME, cli.RED) + m.Push(mdb.NAME, cli.BLUE) + m.Push(mdb.NAME, cli.GREEN) + + default: + switch kit.Select("", kit.Split(m.Option(mdb.TEXT)), 0) { + case "field": + m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, "", "", ice.OptionFields("index,name,text")) + _vimer_list(m, ice.SRC, ctx.INDEX) + + case "chain": + m.Push(mdb.NAME, cli.FG) + m.Push(mdb.NAME, cli.BG) + } + } +} + const SHY = "shy" func init() { - Index.Merge(&ice.Context{Name: SHY, Help: "脚本", Commands: map[string]*ice.Command{ + Index.Register(&ice.Context{Name: SHY, Help: "脚本", Commands: map[string]*ice.Command{ SHY: {Name: "shy path auto", Help: "脚本", Action: ice.MergeAction(map[string]*ice.Action{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { for _, cmd := range []string{mdb.SEARCH, mdb.ENGINE, mdb.RENDER, mdb.PLUGIN} { @@ -25,7 +46,7 @@ func init() { m.ProcessCommand("web.wiki.word", kit.Simple(path.Join(arg[2], arg[1]))) }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(nfs.SOURCE, path.Join(arg[2], arg[1]), kit.Dict(ice.MSG_ALIAS, m.Confv("web.wiki.word", kit.Keym(mdb.ALIAS)))) + _shy_exec(m, arg...) }}, mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { if arg[0] == SHY { @@ -53,5 +74,5 @@ func init() { ), ), KEYWORD, kit.Dict(), ))}, - }}) + }}, nil) } diff --git a/core/code/vimer.go b/core/code/vimer.go index 5384fdcf..5d7a42b3 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -3,7 +3,6 @@ package code import ( "path" "strings" - "sync" ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/cli" @@ -14,28 +13,6 @@ import ( kit "shylinux.com/x/toolkits" ) -var _cache_mods = map[string]*ice.Message{} -var _cache_lock = sync.Mutex{} - -func _vimer_doc(m *ice.Message, mod string, pkg string) *ice.Message { - _cache_lock.Lock() - defer _cache_lock.Unlock() - - key := kit.Keys(mod, pkg) - if msg, ok := _cache_mods[key]; ok && kit.Time(msg.Time("24h")) > kit.Time(m.Time()) { - return msg - } - - if mod != "" { - m.Cmd(cli.SYSTEM, "go", "get", mod) - } - if msg := _vimer_go_complete(m.Spawn(), key); msg.Length() > 0 { - _cache_mods[key] = msg - return msg - } - return nil -} - func _vimer_defs(m *ice.Message, ext string) string { defs := kit.Dict( nfs.SH, ` @@ -114,82 +91,9 @@ func _vimer_inputs(m *ice.Message, arg ...string) { m.Cmdy(web.DREAM, mdb.INPUTS, arg) } } + func _vimer_complete(m *ice.Message, arg ...string) { - const ( - PRE = "pre" - END = "end" - ) - - switch left := kit.Select("", kit.Slice(kit.Split(m.Option(PRE), "\t \n`"), -1), 0); kit.Ext(m.Option(nfs.FILE)) { - case nfs.SH: - if m.Option(PRE) == "" { - // if _cache_bin != nil { - // m.Copy(_cache_bin) - // break - // } - // _cache_bin = m - - // m.Push(mdb.NAME, "_list") - // _vimer_list(m, "/bin") - // _vimer_list(m, "/sbin") - } - - case nfs.SHY: - switch strings.TrimSpace(left) { - case cli.FG, cli.BG: - m.Push(mdb.NAME, cli.RED) - m.Push(mdb.NAME, cli.BLUE) - m.Push(mdb.NAME, cli.GREEN) - - default: - switch kit.Select("", kit.Split(m.Option(PRE)), 0) { - case "field": - m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, "", "", ice.OptionFields("index,name,text")) - _vimer_list(m, ice.SRC, ctx.INDEX) - - case "chain": - m.Push(mdb.NAME, cli.FG) - m.Push(mdb.NAME, cli.BG) - } - } - - case nfs.GO: - if m.Option(mdb.NAME) == ice.PT { - switch m.Option(mdb.TYPE) { - case "msg", "m": - m.Copy(_vimer_doc(m, "shylinux.com/x/ice", "Message")) - m.Copy(_vimer_doc(m, "shylinux.com/x/icebergs", "Message")) - - case "ice", "*ice": - m.Copy(_vimer_doc(m, "shylinux.com/x/ice", "")) - - case "kit": - m.Copy(_vimer_doc(m, "shylinux.com/x/toolkits", "")) - - default: - m.Copy(_vimer_doc(m, "", m.Option(mdb.TYPE))) - } - - } else { - m.Push(mdb.NAME, "msg") - m.Push(mdb.NAME, "ice") - } - - case nfs.JS: - if m.Option(mdb.NAME) == ice.PT { - switch m.Option(mdb.TYPE) { - case "msg": - m.Cmdy("web.code.vim.tags", "msg").Cut("name,text") - case "can": - m.Cmdy("web.code.vim.tags").Cut(mdb.ZONE) - default: - m.Cmdy("web.code.vim.tags", strings.TrimPrefix(m.Option(mdb.TYPE), "can.")).Cut("name,text") - } - } else { - m.Push(mdb.NAME, "msg") - m.Push(mdb.NAME, "can") - } - + switch left := kit.Select("", kit.Slice(kit.Split(m.Option(mdb.TEXT), "\t \n`"), -1), 0); kit.Ext(m.Option(nfs.FILE)) { case nfs.ZML: switch left { case mdb.TYPE: @@ -205,18 +109,20 @@ func _vimer_complete(m *ice.Message, arg ...string) { m.Push(mdb.NAME, "open") default: - if strings.HasSuffix(m.Option(PRE), " ") { + if strings.HasSuffix(m.Option(mdb.TEXT), " ") { m.Push(mdb.NAME, "index") m.Push(mdb.NAME, "action") m.Push(mdb.NAME, "args") m.Push(mdb.NAME, "type") - } else if m.Option(PRE) == "" { + } else if m.Option(mdb.TEXT) == "" { m.Push(mdb.NAME, "head") m.Push(mdb.NAME, "left") m.Push(mdb.NAME, "main") m.Push(mdb.NAME, "foot") } } + default: + m.Cmdy(mdb.ENGINE, kit.Ext(m.Option(nfs.FILE)), m.Option(nfs.FILE), m.Option(nfs.PATH)) } } func _vimer_go_complete(m *ice.Message, name string, arg ...string) *ice.Message { @@ -298,9 +204,7 @@ func init() { m.ToastSuccess() }}, BINPACK: {Name: "binpack", Help: "打包模式", Hand: func(m *ice.Message, arg ...string) { - m.Cmd(nfs.LINK, ice.GO_SUM, path.Join(ice.SRC_RELEASE, ice.GO_SUM)) - m.Cmd(nfs.LINK, ice.GO_MOD, path.Join(ice.SRC_RELEASE, ice.GO_MOD)) - m.Cmdy(nfs.CAT, ice.GO_MOD) + m.Cmdy(WEBPACK, mdb.CREATE) m.Cmdy(AUTOGEN, BINPACK) m.ProcessInner() m.ToastSuccess() diff --git a/exec.go b/exec.go index 2ffc9cc6..e7e66377 100644 --- a/exec.go +++ b/exec.go @@ -16,11 +16,11 @@ func (m *Message) TryCatch(msg *Message, silent bool, hand ...func(msg *Message) case io.EOF: case nil: default: - fileline := kit.FileLine(4, 5) + fileline := m.FormatStack(2, 1) m.Log(LOG_WARN, "catch: %s %s", e, fileline) m.Log("chain", msg.FormatChain()) m.Log(LOG_WARN, "catch: %s %s", e, fileline) - m.Log("stack", msg.FormatStack()) + m.Log("stack", msg.FormatStack(2, 100)) m.Log(LOG_WARN, "catch: %s %s", e, fileline) m.Echo("%v", e) if len(hand) > 1 { diff --git a/init.go b/init.go index c8f4b021..fa2afcf0 100644 --- a/init.go +++ b/init.go @@ -37,7 +37,7 @@ func (f *Frame) Start(m *Message, arg ...string) bool { for _, k := range kit.Split("log,gdb,ssh") { m.Start(k) } - m.Cmdy(arg) + m.Cmd(arg) return true } func (f *Frame) Close(m *Message, arg ...string) bool { @@ -119,6 +119,7 @@ func Run(arg ...string) string { } } + Pulse.meta[MSG_DETAIL] = arg switch Index.Merge(Index).Begin(Pulse.Spawn(), arg...); kit.Select("", arg, 0) { case SERVE, SPACE: // 启动服务 switch strings.Split(os.Getenv("TERM"), "-")[0] { @@ -137,7 +138,6 @@ func Run(arg ...string) string { } Pulse.Cmd(INIT) - // defer Pulse.Cmd(EXIT) if Pulse.Cmdy(arg); strings.TrimSpace(Pulse.Result()) == "" { Pulse.Table() } diff --git a/logs.go b/logs.go index ef1623e8..64df59f1 100644 --- a/logs.go +++ b/logs.go @@ -44,8 +44,8 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message { // 长度截断 switch level { case LOG_INFO, LOG_SEND, LOG_RECV: - if len(str) > 2048 { - str = str[:2048] + if len(str) > 4096 { + str = str[:4096] } } @@ -104,7 +104,7 @@ func (m *Message) Warn(err interface{}, arg ...interface{}) bool { func (m *Message) Error(err bool, str string, arg ...interface{}) bool { if err { m.Echo(ErrWarn).Echo(str, arg...) - m.log(LOG_ERROR, m.FormatStack()) + m.log(LOG_ERROR, m.FormatStack(1, 100)) m.log(LOG_ERROR, str, arg...) m.log(LOG_ERROR, m.FormatChain()) return true @@ -173,20 +173,26 @@ func (m *Message) FormatMeta() string { func (m *Message) FormatsMeta() string { return kit.Formats(m.meta) } -func (m *Message) FormatStack() string { - pc := make([]uintptr, 100) - frames := runtime.CallersFrames(pc[:runtime.Callers(2, pc)]) +func (m *Message) FormatStack(s, n int) string { + pc := make([]uintptr, n+10) + frames := runtime.CallersFrames(pc[:runtime.Callers(s+1, pc)]) - meta := []string{} + list := []string{} for { frame, more := frames.Next() file := kit.Slice(kit.Split(frame.File, PS, PS), -1)[0] name := kit.Slice(kit.Split(frame.Function, PS, PS), -1)[0] - if meta = append(meta, kit.Format("%s:%d\t%s", file, frame.Line, name)); !more { + if !strings.HasPrefix(name, "runtime.") && !strings.HasPrefix(name, "http.") && !strings.HasPrefix(name, "icebergs.") && !strings.HasPrefix(name, "web.(*Frame)") { + list = append(list, kit.Format("%s:%d\t%s", file, frame.Line, name)) + } + if len(list) >= n { + break + } + if !more { break } } - return kit.Join(meta, NL) + return kit.Join(list, NL) } func (m *Message) FormatChain() string { ms := []*Message{} diff --git a/meta.go b/meta.go index 6a3cb853..f8da0094 100644 --- a/meta.go +++ b/meta.go @@ -182,7 +182,7 @@ func (m *Message) Echo(str string, arg ...interface{}) *Message { return m } func (m *Message) Copy(msg *Message, arg ...string) *Message { - if m == nil || m == msg { + if m == nil || msg == nil || m == msg { return m } if len(arg) > 0 { diff --git a/misc.go b/misc.go index 6045a936..0f316227 100644 --- a/misc.go +++ b/misc.go @@ -266,10 +266,8 @@ func (c *Context) _cmd(m *Message, cmd *Command, key string, sub string, h *Acti } if order { m.Option(name, kit.Select(value, arg, i)) - } else { - if m.Option(name) == "" { - m.Option(name, value) - } + } else if m.Option(name) == "" && value != "" { + m.Option(name, value) } } if !order { diff --git a/misc/git/status.go b/misc/git/status.go index abca5f12..c1271fc7 100644 --- a/misc/git/status.go +++ b/misc/git/status.go @@ -1,6 +1,7 @@ package git import ( + "path" "strings" "time" @@ -298,12 +299,15 @@ func init() { _repos_cmd(m, m.Option(REPOS), PUSH, "--tags") m.ProcessRefresh3ms() }}, - code.BINPACK: {Name: "binpack", Help: "打包模式", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(code.VIMER, code.BINPACK) - }}, code.DEVPACK: {Name: "devpack", Help: "开发模式", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(code.VIMER, code.DEVPACK) }}, + code.BINPACK: {Name: "binpack", Help: "发布模式", Hand: func(m *ice.Message, arg ...string) { + m.Cmd(nfs.LINK, ice.GO_SUM, path.Join(ice.SRC_RELEASE, ice.GO_SUM)) + m.Cmd(nfs.LINK, ice.GO_MOD, path.Join(ice.SRC_RELEASE, ice.GO_MOD)) + m.Cmdy(nfs.CAT, ice.GO_MOD) + m.Cmdy(code.VIMER, code.BINPACK) + }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { m.Action(PULL, MAKE, PUSH, TAGS, STASH, PIE, "publish")