From 50279c8fc4ceffc410f2157635a4687649183a1b Mon Sep 17 00:00:00 2001 From: shaoying Date: Fri, 26 Feb 2021 21:43:00 +0800 Subject: [PATCH] opt some --- base/web/dream.go | 18 +++++++++++------- base/web/serve.go | 31 ++++++++++++++++--------------- conf.go | 10 ++++++++++ core/code/autogen.go | 26 +++++++++++++------------- 4 files changed, 50 insertions(+), 35 deletions(-) diff --git a/base/web/dream.go b/base/web/dream.go index 0c30dabd..4cf3a900 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -138,21 +138,25 @@ func init() { }, Configs: map[string]*ice.Config{ DREAM: {Name: DREAM, Help: "梦想家", Value: kit.Data(kit.MDB_PATH, "usr/local/work", - "cmd", []interface{}{"ice.bin", SPACE, tcp.DIAL}, - "env", kit.Dict("ctx_log", "bin/boot.log"), + kit.SSH_CMD, []interface{}{"ice.bin", SPACE, tcp.DIAL}, + kit.SSH_ENV, kit.Dict(ice.CTX_LOG, ice.BIN_BOOTLOG), "miss", `#!/bin/bash -[ -f ~/.ish/plug.sh ] || [ -f $PWD/.ish/plug.sh ] || git clone ${ISH_CONF_HUB_PROXY:="https://"}github.com/shylinux/intshell $PWD/.ish -[ "$ISH_CONF_PRE" != "" ] || source $PWD/.ish/plug.sh || source ~/.ish/plug.sh +[ -f $PWD/.ish/plug.sh ] || [ -f $HOME/.ish/plug.sh ] || git clone ${ISH_CONF_HUB_PROXY:="https://"}github.com/shylinux/intshell $PWD/.ish +[ "$ISH_CONF_PRE" != "" ] || source $PWD/.ish/plug.sh || source $HOME/.ish/plug.sh require miss.sh +# ish_miss_prepare_compile ish_miss_prepare_develop -ish_miss_prepare_compile ish_miss_prepare_install -# ish_miss_prepare_volcanos -# ish_miss_prepare_learning +# ish_miss_prepare wubi-dict + +ish_miss_prepare_contexts +# ish_miss_prepare_intshell # ish_miss_prepare_icebergs # ish_miss_prepare_toolkits +# ish_miss_prepare_volcanos +# ish_miss_prepare_learning make `, diff --git a/base/web/serve.go b/base/web/serve.go index 88a6fe87..3ebe72ca 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -35,7 +35,7 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool { m.Info("").Info("%s %s %s", r.Header.Get(ice.MSG_USERIP), r.Method, r.URL) // 输出日志 - if m.Conf(SERVE, "meta.logheaders") == "true" { + if m.Conf(SERVE, kit.Keym("logheaders")) == "true" { for k, v := range r.Header { m.Info("%s: %v", k, kit.Format(v)) } @@ -57,15 +57,16 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool { // 主页接口 if r.Method == "GET" && r.URL.Path == "/" { - msg := m.Spawn() + msg, repos := m.Spawn(), ice.INTSHELL if msg.W, msg.R = w, r; strings.Contains(r.Header.Get("User-Agent"), "curl") { - Render(msg, ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, "meta.intshell.path"), m.Conf(SERVE, "meta.intshell.index"))) + repos = ice.INTSHELL } else { + repos = ice.VOLCANOS if ice.DumpBinPack(w, r.URL.Path, func(name string) { RenderType(w, name, "") }) { return false } - Render(msg, ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, "meta.volcanos.path"), m.Conf(SERVE, "meta.volcanos.index"))) } + Render(msg, ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, kit.Keym(repos, kit.SSH_PATH)), m.Conf(SERVE, kit.Keym(repos, kit.SSH_INDEX)))) return false } @@ -93,7 +94,7 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon } // 请求地址 - msg.Option(ice.MSG_USERWEB, kit.Select(msg.Conf(SHARE, "meta.domain"), r.Header.Get("Referer"))) + msg.Option(ice.MSG_USERWEB, kit.Select(msg.Conf(SHARE, kit.Keym("domain")), r.Header.Get("Referer"))) msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent")) msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP)) if msg.R, msg.W = r, w; r.Header.Get("X-Real-Port") != "" { @@ -201,18 +202,18 @@ func init() { SERVE: {Name: SERVE, Help: "服务器", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME, tcp.LOCALHOST, true, aaa.BLACK, kit.Dict(), aaa.WHITE, kit.Dict( LOGIN, true, SPACE, true, SHARE, true, - "volcanos", true, "intshell", true, - "require", true, "publish", true, + ice.VOLCANOS, true, ice.INTSHELL, true, + ice.REQUIRE, true, ice.PUBLISH, true, ), "logheaders", false, - "static", kit.Dict("/", "usr/volcanos/"), - "volcanos", kit.Dict("path", "usr/volcanos", "index", "page/index.html", - "repos", "https://github.com/shylinux/volcanos", "branch", "master", - ), "publish", "usr/publish/", + kit.SSH_STATIC, kit.Dict("/", "usr/volcanos/"), + ice.VOLCANOS, kit.Dict(kit.MDB_PATH, "usr/volcanos", kit.SSH_INDEX, "page/index.html", + kit.SSH_REPOS, "https://github.com/shylinux/volcanos", kit.SSH_BRANCH, "master", + ), ice.PUBLISH, "usr/publish/", - "intshell", kit.Dict("path", "usr/intshell", "index", "index.sh", - "repos", "https://github.com/shylinux/intshell", "branch", "master", - ), "require", ".ish/pluged", + ice.INTSHELL, kit.Dict(kit.MDB_PATH, "usr/intshell", kit.SSH_INDEX, "index.sh", + kit.SSH_REPOS, "https://github.com/shylinux/intshell", kit.SSH_BRANCH, "master", + ), ice.REQUIRE, ".ish/pluged", )}, }, Commands: map[string]*ice.Command{ @@ -251,7 +252,7 @@ func init() { m.Render(ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, kit.Keym("intshell.path")), path.Join(arg...))) }}, "/publish/": {Name: "/publish/", Help: "私有云", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - _share_local(m, m.Conf(SERVE, kit.Keym("publish")), path.Join(arg...)) + _share_local(m, m.Conf(SERVE, kit.Keym(ice.PUBLISH)), path.Join(arg...)) }}, "/require/": {Name: "/require/", Help: "公有云", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { _share_repos(m, path.Join(arg[0], arg[1], arg[2]), arg[3:]...) diff --git a/conf.go b/conf.go index 7a457d38..abad436c 100644 --- a/conf.go +++ b/conf.go @@ -16,6 +16,9 @@ const ( // REPOS ICEBERGS = "icebergs" CONTEXTS = "contexts" INTSHELL = "intshell" + + PUBLISH = "publish" + REQUIRE = "require" ) const ( // DIR ETC_MISS = "etc/miss.sh" @@ -23,6 +26,9 @@ const ( // DIR ETC_EXIT = "etc/exit.shy" SRC_MAIN = "src/main.shy" SRC_MAIN_GO = "src/main.go" + SRC_VERSION = "src/version.go" + SRC_BINPACK = "src/binpack.go" + BIN_BOOTLOG = "bin/boot.log" BIN_ICE_BIN = "bin/ice.bin" BIN_ICE = "bin/ice.sh" MAKEFILE = "makefile" @@ -30,6 +36,10 @@ const ( // DIR ORDER_JS = "order.js" GO_MOD = "go.mod" GO_SUM = "go.sum" + + CTX_DEV = "ctx_dev" + CTX_PID = "ctx_pid" + CTX_LOG = "ctx_log" ) const ( // MSG MSG_DETAIL = "detail" diff --git a/core/code/autogen.go b/core/code/autogen.go index ec6e17a1..5af232c1 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -8,19 +8,17 @@ import ( "github.com/shylinux/icebergs/base/web" kit "github.com/shylinux/toolkits" - "os" "path" "strings" ) func _autogen_script(m *ice.Message, dir string) { if b, e := kit.Render(m.Conf(AUTOGEN, kit.Keym(SHY)), m); m.Assert(e) { - m.Cmd(nfs.SAVE, dir, string(b)) + m.Cmd(nfs.DEFS, dir, string(b)) } } func _autogen_source(m *ice.Message, name string) { - m.Cmd(nfs.PUSH, path.Join(kit.SSH_SRC, kit.Keys(kit.MDB_MAIN, SHY)), - "\n", kit.SSH_SOURCE+` `+path.Join(name, kit.Keys(name, SHY)), "\n") + m.Cmd(nfs.PUSH, ice.SRC_MAIN, "\n", kit.SSH_SOURCE+` `+path.Join(name, kit.Keys(name, SHY)), "\n") } func _autogen_module(m *ice.Message, dir string, ctx string, from string) (list []string) { name, value := "", "" @@ -67,7 +65,7 @@ func _autogen_mod(m *ice.Message, file string) (mod string) { } func _autogen_version(m *ice.Message) { - file := "src/version.go" + file := ice.SRC_VERSION m.Cmd(nfs.SAVE, file, kit.Format(`package main import ( @@ -91,17 +89,19 @@ func init() { strings.TrimSpace(m.Cmdx(cli.SYSTEM, "git", "describe", "--tags")), ice.Info.HostName, ice.Info.UserName, )) - m.Cmdy(nfs.DIR, "src/binpack.go", "time,size,line,path") + defer m.Cmdy(nfs.CAT, file) + m.Cmdy(nfs.DIR, file, "time,size,line,path") - m.Cmdy(nfs.CAT, file) + m.Cmdy(nfs.DIR, ice.SRC_BINPACK, "time,size,line,path") + m.Cmdy(nfs.DIR, ice.SRC_MAIN_GO, "time,size,line,path") } func _autogen_miss(m *ice.Message) { - file := "etc/miss.sh" - if _, e := os.Stat(file); os.IsNotExist(e) { - m.Cmd(nfs.SAVE, file, m.Conf(web.DREAM, kit.Keym("miss"))) - } - m.Cmdy(nfs.DIR, file, "time,size,line,path") - m.Cmdy(nfs.CAT, file) + m.Cmd(nfs.DEFS, ice.ETC_MISS, m.Conf(web.DREAM, kit.Keym("miss"))) + defer m.Cmdy(nfs.CAT, ice.ETC_MISS) + + m.Cmdy(nfs.DIR, ice.ETC_MISS, "time,size,line,path") + m.Cmdy(nfs.DIR, ice.GO_MOD, "time,size,line,path") + m.Cmdy(nfs.DIR, ice.GO_SUM, "time,size,line,path") } const AUTOGEN = "autogen"