forked from x/icebergs
opt m.FormatMeta
This commit is contained in:
parent
c434e334a9
commit
b2e8e5b28f
@ -71,7 +71,12 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool {
|
||||
default:
|
||||
kit.If(cmd != "" && cmd != ice.RENDER_RAW, func() { m.Echo(kit.Format(cmd, args...)) })
|
||||
RenderType(m.W, nfs.JSON, "")
|
||||
m.FormatsMeta(m.W)
|
||||
m.FormatsMeta(m.W, ice.MSG_USERIP, ice.MSG_USERUA, ice.MSG_METHOD,
|
||||
ice.MSG_USERWEB, ice.MSG_REFERER, ice.MSG_DAEMON, ice.MSG_USERPOD,
|
||||
ice.MSG_LANGUAGE, ice.MSG_THEME, ice.MSG_BG, ice.MSG_FG,
|
||||
ice.MSG_RIVER, ice.MSG_STORM, ice.MSG_INDEX, ice.MSG_FIELDS,
|
||||
ice.MSG_SOURCE, ice.MSG_TARGET,
|
||||
)
|
||||
}
|
||||
m.Render(ice.RENDER_VOID)
|
||||
return true
|
||||
|
@ -111,13 +111,13 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
|
||||
case SHARE:
|
||||
add(arg[0], arg[1])
|
||||
}
|
||||
kit.For(u.Query(), func(k string, v []string) { _log(ctx.ARGS, k, v).Optionv(k, v) })
|
||||
kit.For(u.Query(), func(k string, v []string) { m.Optionv(k, v) })
|
||||
}
|
||||
kit.For(kit.ParseQuery(r.URL.RawQuery), func(k string, v []string) { m.Optionv(k, v) })
|
||||
if r.Method == http.MethodGet && m.Option(ice.MSG_CMDS) != "" {
|
||||
_log(ctx.ARGS, ice.MSG_CMDS, m.Optionv(ice.MSG_CMDS))
|
||||
}
|
||||
switch r.Header.Get(ContentType) {
|
||||
switch kit.Select("", kit.Split(r.Header.Get(ContentType)), 0) {
|
||||
case ApplicationJSON:
|
||||
kit.For(kit.UnMarshal(r.Body), func(k string, v ice.Any) { m.Optionv(k, v) })
|
||||
default:
|
||||
@ -125,8 +125,8 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
|
||||
kit.For(r.PostForm, func(k string, v []string) { _log(FORM, k, kit.Join(v, lex.SP)).Optionv(k, v) })
|
||||
}
|
||||
kit.For(r.Cookies(), func(k, v string) { m.Optionv(k, v) })
|
||||
m.Options(ice.MSG_REFERER, r.Header.Get(Referer))
|
||||
m.Options(ice.MSG_METHOD, r.Method, ice.MSG_COUNT, "0")
|
||||
m.Options(ice.MSG_REFERER, r.Header.Get(Referer))
|
||||
m.Options(ice.MSG_USERWEB, _serve_domain(m), ice.MSG_USERPOD, m.Option(ice.POD))
|
||||
m.Options(ice.MSG_USERUA, r.Header.Get(UserAgent), ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
|
||||
m.Options(ice.MSG_SESSID, kit.Select(m.Option(ice.MSG_SESSID), m.Option(CookieName(m.Option(ice.MSG_USERWEB)))))
|
||||
@ -139,6 +139,7 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
|
||||
defer func() {
|
||||
kit.If(m.Option(ice.MSG_STATUS) == "", func() { m.StatusTimeCount() })
|
||||
m.Cost(kit.Format("%s: %s %v", r.Method, r.URL.String(), m.FormatSize()))
|
||||
m.Options(ice.MSG_COST, m.FormatCost(), ice.MSG_OPTION, kit.Simple(m.Optionv(ice.MSG_OPTION), ice.MSG_COST))
|
||||
}()
|
||||
m.Option(ice.MSG_OPTS, kit.Simple(m.Optionv(ice.MSG_OPTION), func(k string) bool { return !strings.HasPrefix(k, ice.MSG_SESSID) }))
|
||||
if m.Detailv(m.PrefixKey(), cmds); len(cmds) > 1 && cmds[0] == ctx.ACTION && cmds[1] != ctx.ACTION {
|
||||
|
41
conf.go
41
conf.go
@ -186,10 +186,10 @@ const ( // DIR
|
||||
)
|
||||
const ( // MSG
|
||||
MSG_CMDS = "cmds"
|
||||
MSG_DEBUG = "debug"
|
||||
MSG_FIELDS = "fields"
|
||||
MSG_SESSID = "sessid"
|
||||
MSG_METHOD = "method"
|
||||
MSG_SESSID = "sessid"
|
||||
MSG_DEBUG = "debug"
|
||||
|
||||
MSG_DETAIL = "detail"
|
||||
MSG_OPTION = "option"
|
||||
@ -226,23 +226,26 @@ const ( // MSG
|
||||
MSG_USERZONE = "user.zone"
|
||||
MSG_LANGUAGE = "user.lang"
|
||||
|
||||
MSG_BG = "sess.bg"
|
||||
MSG_FG = "sess.fg"
|
||||
MSG_MODE = "sess.mode"
|
||||
MSG_THEME = "sess.theme"
|
||||
MSG_TITLE = "sess.title"
|
||||
MSG_RIVER = "sess.river"
|
||||
MSG_STORM = "sess.storm"
|
||||
MSG_COUNT = "sess.count"
|
||||
MSG_DAEMON = "sess.daemon"
|
||||
MSG_REFERER = "sess.referer"
|
||||
MSG_FILES = "file.system"
|
||||
LOG_DISABLE = "log.disable"
|
||||
LOG_TRACEID = "log.id"
|
||||
YAC_MESSAGE = "yac.message"
|
||||
YAC_STACK = "yac.stack"
|
||||
SSH_ALIAS = "ssh.alias"
|
||||
SSH_TARGET = "ssh.target"
|
||||
MSG_BG = "sess.bg"
|
||||
MSG_FG = "sess.fg"
|
||||
MSG_COST = "sess.cost"
|
||||
MSG_MODE = "sess.mode"
|
||||
MSG_THEME = "sess.theme"
|
||||
MSG_TITLE = "sess.title"
|
||||
MSG_RIVER = "sess.river"
|
||||
MSG_STORM = "sess.storm"
|
||||
MSG_COUNT = "sess.count"
|
||||
MSG_DAEMON = "sess.daemon"
|
||||
MSG_REFERER = "sess.referer"
|
||||
MSG_FILES = "file.system"
|
||||
MSG_CHECKER = "aaa.checker"
|
||||
YAC_MESSAGE = "yac.message"
|
||||
YAC_STACK = "yac.stack"
|
||||
SSH_ALIAS = "ssh.alias"
|
||||
SSH_TARGET = "ssh.target"
|
||||
LOG_DISABLE = "log.disable"
|
||||
LOG_TRACEID = "log.id"
|
||||
|
||||
TOAST_DURATION = "toast.duration"
|
||||
)
|
||||
const ( // RENDER
|
||||
|
1
lock.go
1
lock.go
@ -73,6 +73,7 @@ func (m *Message) setDetail(key string, arg ...string) *Message {
|
||||
return m
|
||||
}
|
||||
func (m *Message) Optionv(key string, arg ...Any) Any {
|
||||
key = kit.Select(MSG_OPTION, key)
|
||||
var unlock func()
|
||||
if len(arg) > 0 {
|
||||
unlock = m.lock.Lock()
|
||||
|
14
logs.go
14
logs.go
@ -178,7 +178,9 @@ func (m *Message) FormatShip(traceid ...string) string {
|
||||
return kit.Format("%s%02d %4s->%-4s", _traceid, m.code, m.source.Name, m.target.Name)
|
||||
}
|
||||
func (m *Message) FormatSize() string {
|
||||
return kit.Format("%dx%d %v %v", m.Length(), len(m.value(MSG_APPEND)), kit.Simple(m.value(MSG_APPEND)), kit.FmtSize(len(m.Result())))
|
||||
n := len(m.value(MSG_APPEND))
|
||||
kit.If(m.FieldsIsDetail(), func() { n = len(m.value(KEY)) })
|
||||
return kit.Format("%dx%d %v %v", m.Length(), n, kit.Simple(m.value(MSG_APPEND)), kit.FmtSize(len(m.Result())))
|
||||
}
|
||||
func (m *Message) FormatCost() string { return kit.FmtDuration(time.Since(m.time)) }
|
||||
func (m *Message) FormatMeta() string {
|
||||
@ -195,17 +197,19 @@ func (m *Message) FormatsMeta(w io.Writer, arg ...string) (res string) {
|
||||
ls := m.value(k)
|
||||
kit.If(len(ls) == 0 || len(ls) == 1 && ls[0] == "", func() { m.index(MSG_OPTION, i, "") })
|
||||
})
|
||||
m.value(MSG_OPTION, kit.Filters(m.value(MSG_OPTION), MSG_CMDS, MSG_FIELDS, MSG_SESSID, MSG_OPTS, MSG_INDEX, "", "aaa.checker")...)
|
||||
kit.If(len(arg) == 0 && m.Option(DEBUG) == TRUE, func() { arg = []string{SP, SP, NL} })
|
||||
bio, count, NL := bufio.NewWriter(w), 0, kit.Select("", arg, 2)
|
||||
kit.For(m.Optionv(""), func(key string) { kit.If(strings.HasPrefix(key, "sessid_"), func() { arg = append(arg, key) }) })
|
||||
m.value(MSG_OPTION, kit.Filters(m.value(MSG_OPTION), kit.Simple(MSG_CMDS, MSG_SESSID, MSG_OPTS, "", MSG_COUNT, MSG_CHECKER, arg)...)...)
|
||||
bio, count := bufio.NewWriter(w), 0
|
||||
defer bio.Flush()
|
||||
SP, NL := SP, NL
|
||||
kit.If(m.Option(MSG_DEBUG) != TRUE, func() { SP, NL = "", "" })
|
||||
echo := func(arg ...Any) { fmt.Fprint(bio, arg...) }
|
||||
push := func(k string) {
|
||||
if len(m.value(k)) == 0 {
|
||||
return
|
||||
}
|
||||
kit.If(count > 0, func() { echo(FS, NL) })
|
||||
echo(kit.Format("%s%q:%s", kit.Select("", arg, 0), k, kit.Select("", arg, 1)))
|
||||
echo(kit.Format("%s%q:%s", SP, k, SP))
|
||||
b, _ := json.Marshal(m.value(k))
|
||||
bio.Write(b)
|
||||
count++
|
||||
|
Loading…
x
Reference in New Issue
Block a user