1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

add web.time.cost

This commit is contained in:
shaoying 2019-08-13 16:04:08 +08:00
parent 668dacb7c5
commit a19e759ec9
3 changed files with 12 additions and 3 deletions

View File

@ -4,5 +4,5 @@ var version = struct {
host string
self int
}{
"2019-08-06 21:00:10", "ZYB-20190522USI", 379,
"2019-08-13 16:01:31", "ZYB-20190522USI", 382,
}

View File

@ -90,8 +90,13 @@ type DEBUG interface {
func (m *Message) Time(arg ...interface{}) string {
t := m.time
if len(arg) > 0 {
if d, e := time.ParseDuration(arg[0].(string)); e == nil {
arg, t = arg[1:], t.Add(d)
switch v := arg[0].(type) {
case time.Time:
return fmt.Sprintf("%v", v.Sub(t))
default:
if d, e := time.ParseDuration(arg[0].(string)); e == nil {
arg, t = arg[1:], t.Add(d)
}
}
}

View File

@ -21,6 +21,7 @@ import (
"path/filepath"
"strconv"
"strings"
"time"
)
type MUX interface {
@ -158,6 +159,9 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
web.HandleFunc(key, func(w http.ResponseWriter, r *http.Request) {
m.TryCatch(m.Spawn(m.Conf("serve", "autofree")), true, func(msg *ctx.Message) {
defer func() {
msg.Log("time", "cost: %v", msg.Time(time.Now()))
}()
msg.Option("remote_addr", r.RemoteAddr)
msg.Option("remote_ip", r.Header.Get("remote_ip"))
msg.Option("index_url", r.Header.Get("index_url"))