From 51ce14e0c178af4aedfecc0289940f46ff8a6ca9 Mon Sep 17 00:00:00 2001 From: shaoying Date: Wed, 28 Jul 2021 22:55:28 +0800 Subject: [PATCH] opt some --- base/yac/script.go | 2 +- conf.go | 2 +- core/code/publish.go | 4 ++-- core/wiki/chart.go | 2 +- data.go | 2 +- exec.go | 9 +++------ logs.go | 2 +- meta.go | 9 +++------ 8 files changed, 13 insertions(+), 19 deletions(-) diff --git a/base/yac/script.go b/base/yac/script.go index 33f28ef3..106f3114 100644 --- a/base/yac/script.go +++ b/base/yac/script.go @@ -83,7 +83,7 @@ func _exp_true(m *ice.Message, arg string) bool { if arg == ice.TRUE { return true } - if arg == "false" { + if arg == ice.FALSE { return false } if n1, e1 := strconv.ParseInt(arg, 10, 64); e1 == nil { diff --git a/conf.go b/conf.go index d44dcaa5..abb9ec5a 100644 --- a/conf.go +++ b/conf.go @@ -36,8 +36,8 @@ const ( // DIR USR_INTSHELL = "usr/intshell" USR_INSTALL = "usr/install" USR_PUBLISH = "usr/publish" - USR_LOCAL = "usr/local" + USR_LOCAL = "usr/local" USR_LOCAL_WORK = "usr/local/work" USR_LOCAL_RIVER = "usr/local/river" USR_LOCAL_IMAGE = "usr/local/image" diff --git a/core/code/publish.go b/core/code/publish.go index 6060399b..2685e354 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -98,8 +98,8 @@ func init() { m.Cmdy(nfs.DIR, "./", "time,size,line,path,link") }}, ice.CONTEXTS: {Name: "contexts", Help: "环境", Hand: func(m *ice.Message, arg ...string) { - u := kit.ParseURL(m.Option(ice.MSG_USERWEB)) - host := m.ReplaceLocalhost(u.Host) + u := kit.ParseURL(m.ReplaceLocalhost(m.Option(ice.MSG_USERWEB))) + host := u.Host m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, strings.Split(host, ":")[0], kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(host, ":"), 1))) m.Option("hostport", fmt.Sprintf("%s:%s", strings.Split(host, ":")[0], kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(host, ":"), 1))) diff --git a/core/wiki/chart.go b/core/wiki/chart.go index 074d4359..8f3616ad 100644 --- a/core/wiki/chart.go +++ b/core/wiki/chart.go @@ -375,7 +375,7 @@ func _chart_show(m *ice.Message, kind, text string, arg ...string) { m.Option("stroke-width", "2") m.Option("font-family", "monospace") // 扩展参数 - m.Option("compact", "false") + m.Option("compact", ice.FALSE) m.Option("padding", "10") m.Option("marginx", "10") m.Option("marginy", "10") diff --git a/data.go b/data.go index 1c8bf266..2fcd0037 100644 --- a/data.go +++ b/data.go @@ -56,7 +56,7 @@ func (m *Message) Grows(prefix string, chain interface{}, match string, value st limit := kit.Int(m.Option("cache.limit")) if begin := kit.Int(m.Option("cache.begin")); begin != 0 && limit > 0 { - count := kit.Int(m.Option("cache.count", kit.Int(kit.Value(cache, "meta.count")))) + count := kit.Int(m.Option("cache.count", kit.Int(kit.Value(cache, kit.Keym("count"))))) if begin > 0 { m.Option("cache.offend", count-begin-limit) } else { diff --git a/exec.go b/exec.go index d7d5885a..529fee03 100644 --- a/exec.go +++ b/exec.go @@ -22,18 +22,15 @@ func (m *Message) TryCatch(msg *Message, safe bool, hand ...func(msg *Message)) m.Log(LOG_WARN, "catch: %s %s", e, fileline) m.Log("stack", msg.Format("stack")) m.Log(LOG_WARN, "catch: %s %s", e, fileline) - if len(hand) > 1 { - // 捕获异常 + if len(hand) > 1 { // 捕获异常 m.TryCatch(msg, safe, hand[1:]...) - } else if !safe { - // 抛出异常 + } else if !safe { // 抛出异常 m.Assert(e) } } }() - if len(hand) > 0 { - // 运行函数 + if len(hand) > 0 { // 运行函数 hand[0](msg) } return m diff --git a/logs.go b/logs.go index d1f88bbf..83b2f650 100644 --- a/logs.go +++ b/logs.go @@ -25,7 +25,7 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message { return m // 禁用日志 } if str = strings.TrimSpace(kit.Format(str, arg...)); Log != nil { - Log(m, m.Format("prefix"), level, str) + Log(m, m.Format(kit.MDB_PREFIX), level, str) // 日志分流 } if m.Option("_disable_log") == TRUE { diff --git a/meta.go b/meta.go index a2f26dff..d6a311ad 100644 --- a/meta.go +++ b/meta.go @@ -140,8 +140,7 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message { if m == nil { return m } - if len(arg) > 0 { - // 精确复制 + if len(arg) > 0 { // 精确复制 for _, k := range arg[1:] { if kit.IndexOf(m.meta[arg[0]], k) == -1 { m.meta[arg[0]] = append(m.meta[arg[0]], k) @@ -151,8 +150,7 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message { return m } - // 复制选项 - for _, k := range msg.meta[MSG_OPTION] { + for _, k := range msg.meta[MSG_OPTION] { // 复制选项 if kit.IndexOf(m.meta[MSG_OPTION], k) == -1 { m.meta[MSG_OPTION] = append(m.meta[MSG_OPTION], k) } @@ -163,8 +161,7 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message { } } - // 复制数据 - for _, k := range msg.meta[MSG_APPEND] { + for _, k := range msg.meta[MSG_APPEND] { // 复制数据 if i := kit.IndexOf(m.meta[MSG_OPTION], k); i > -1 && len(m.meta[k]) > 0 { m.meta[k] = m.meta[k][:0] }