From 5f7d55da1a1592cb9f8e9e5ae8d065e4407f50f1 Mon Sep 17 00:00:00 2001 From: shaoying Date: Fri, 28 Sep 2018 23:28:33 +0800 Subject: [PATCH] tce mod some --- Makefile | 15 +++--- etc/dotsfile/shy.vim | 38 +++++++------- src/contexts/web/web.go | 114 +++++++++++++++++++--------------------- 3 files changed, 82 insertions(+), 85 deletions(-) diff --git a/Makefile b/Makefile index 4e765bae..9eba94b2 100644 --- a/Makefile +++ b/Makefile @@ -6,16 +6,17 @@ install: @go get github.com/nsf/termbox-go @go get github.com/skip2/go-qrcode @go get github.com/gomarkdown/markdown - @touch etc/local.shy - @touch etc/local_exit.shy - @touch etc/init.shy - @touch etc/exit.shy - @touch etc/login.txt - @touch etc/history.txt go install $(BENCH) - # @[ `uname` = "Darwin" ] && md5 `which bench` @date +install_all: install + touch etc/local.shy + touch etc/local_exit.shy + touch etc/init.shy + touch etc/exit.shy + touch etc/login.txt + touch etc/history.txt + build: go build $(BENCH) diff --git a/etc/dotsfile/shy.vim b/etc/dotsfile/shy.vim index ef96204c..905d6924 100644 --- a/etc/dotsfile/shy.vim +++ b/etc/dotsfile/shy.vim @@ -17,31 +17,33 @@ syn keyword shStatement if else elif end for syn keyword shStatement let var " ctx command -syn match shStatement "\(^\|\t\|$(\)cache" -syn match shStatement "\(^\|\t\|$(\)config" -syn match shStatement "\(^\|\t\|$(\)detail" -syn match shStatement "\(^\|\t\|$(\)option" -syn match shStatement "\(^\|\t\|$(\)append" -syn match shStatement "\(^\|\t\|$(\)result" +syn match shStatement "\(^\|\t\|$(\|\ \ \)cache" +syn match shStatement "\(^\|\t\|$(\|\ \ \)config" + +syn match shStatement "\(^\|\t\|$(\|\ \ \)detail" +syn match shStatement "\(^\|\t\|$(\|\ \ \)option" +syn match shStatement "\(^\|\t\|$(\|\ \ \)append" +syn match shStatement "\(^\|\t\|$(\|\ \ \)result" " ctx command -syn match shCommand "\(^\|\t\|$(\)message" -syn match shCommand "\(^\|\t\|$(\)session" -syn match shCommand "\(^\|\t\|$(\)context" -syn match shCommand "\(^\|\t\|$(\)server" -syn match shCommand "\(^\|\t\|$(\)command" -syn match shCommand "\(^\|\t\|$(\)right" +syn match shCommand "\(^\|\t\|$(\|\ \ \)command" +syn match shCommand "\(^\|\t\|$(\|\ \ \)context" +syn match shCommand "\(^\|\t\|$(\|\ \ \)message" +syn match shCommand "\(^\|\t\|$(\|\ \ \)session" +syn match shCommand "\(^\|\t\|$(\|\ \ \)server" +syn match shCommand "\(^\|\t\|$(\|\ \ \)right" " tcp command -syn match shCommand "\(^\|\t\|$(\)listen" +syn match shCommand "\(^\|\t\|$(\|\ \ \)listen" " web command -syn match shCommand "\(^\|\t\|$(\)serve" -syn match shCommand "\(^\|\t\|$(\)route" +syn match shCommand "\(^\|\t\|$(\|\ \ \)client" +syn match shCommand "\(^\|\t\|$(\|\ \ \)serve\$" +syn match shCommand "\(^\|\t\|$(\|\ \ \)route" -syn match shCommand "\(^\|\t\|$(\)open" -syn match shCommand "\(^\|\t\|$(\)cookie" -syn match shCommand "\(^\|\t\|$(\)login" +syn match shCommand "\(^\|\t\|$(\|\ \ \)open" +syn match shCommand "\(^\|\t\|$(\|\ \ \)cookie" +syn match shCommand "\(^\|\t\|$(\|\ \ \)login" hi def link shComment Comment hi def link shString String diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 6a0e334f..24549659 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -773,82 +773,78 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", if k == "" { continue } - fields[k] = true - if len(fields) == 1 { + if fields[k] = true; len(fields) == 1 { m.Meta["append"] = append(m.Meta["append"], "index") } m.Meta["append"] = append(m.Meta["append"], k) } - switch ret := result.(type) { - case map[string]interface{}: - m.Log("fuck", "fuck %v", ret) - m.Append("index", "0") - for k, v := range ret { - switch value := v.(type) { - case string: - m.Append(k, strings.Replace(value, "\n", " ", -1)) - case float64: - m.Append(k, fmt.Sprintf("%d", int(value))) - default: - if _, ok := fields[k]; ok { - m.Append(k, fmt.Sprintf("%v", value)) + if len(fields) > 0 { + + switch ret := result.(type) { + case map[string]interface{}: + m.Append("index", "0") + for k, v := range ret { + switch value := v.(type) { + case string: + m.Append(k, strings.Replace(value, "\n", " ", -1)) + case float64: + m.Append(k, fmt.Sprintf("%d", int(value))) + default: + if _, ok := fields[k]; ok { + m.Append(k, fmt.Sprintf("%v", value)) + } } } - } - m.Table() - return - case []interface{}: - for i, r := range ret { - m.Add("append", "index", i) - if rr, ok := r.(map[string]interface{}); ok { - for k, v := range rr { - switch value := v.(type) { - case string: - if _, ok := fields[k]; len(fields) == 0 || ok { - m.Add("append", k, strings.Replace(value, "\n", " ", -1)) - } - case float64: - if _, ok := fields[k]; len(fields) == 0 || ok { - m.Add("append", k, fmt.Sprintf("%v", value)) - } - case bool: - if _, ok := fields[k]; len(fields) == 0 || ok { - m.Add("append", k, fmt.Sprintf("%v", value)) - } - case map[string]interface{}: - for kk, vv := range value { - key := k + "." + kk - if _, ok := fields[key]; len(fields) == 0 || ok { - m.Add("append", key, strings.Replace(fmt.Sprintf("%v", vv), "\n", " ", -1)) + case []interface{}: + for i, r := range ret { + m.Add("append", "index", i) + if rr, ok := r.(map[string]interface{}); ok { + for k, v := range rr { + switch value := v.(type) { + case string: + if _, ok := fields[k]; len(fields) == 0 || ok { + m.Add("append", k, strings.Replace(value, "\n", " ", -1)) + } + case float64: + if _, ok := fields[k]; len(fields) == 0 || ok { + m.Add("append", k, fmt.Sprintf("%d", int64(value))) + } + case bool: + if _, ok := fields[k]; len(fields) == 0 || ok { + m.Add("append", k, fmt.Sprintf("%v", value)) + } + case map[string]interface{}: + for kk, vv := range value { + key := k + "." + kk + if _, ok := fields[key]; len(fields) == 0 || ok { + m.Add("append", key, strings.Replace(fmt.Sprintf("%v", vv), "\n", " ", -1)) + } + } + default: + if _, ok := fields[k]; ok { + m.Add("append", k, fmt.Sprintf("%v", value)) } - } - default: - if _, ok := fields[k]; ok { - m.Add("append", k, fmt.Sprintf("%v", value)) } } } } - } - if m.Has("json_key") { - m.Sort(m.Option("json_key")) + if m.Has("json_key") { + m.Sort(m.Option("json_key")) + } + m.Meta["index"] = nil + for i, _ := range ret { + m.Add("append", "index", i) + } } - m.Meta["index"] = nil - for i, _ := range ret { - m.Add("append", "index", i) - } - m.Table() - return } } - result := string(buf) - m.Echo("%s", result) - // m.Append("response", result) + if m.Table(); len(m.Meta["append"]) == 0 { + m.Echo("%s", string(buf)) + } } // }}} - }}, "post": &ctx.Command{Name: "post", Help: "访问服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { @@ -1597,9 +1593,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", var data WXMsg b, e := ioutil.ReadAll(r.Body) - m.Log("fuck", "b: %v", string(b)) e = xml.Unmarshal(b, &data) - m.Log("fuck", "b: %#v", data) // de := xml.NewDecoder(r.Body) // e := de.Decode(&data)