From b3c672b08b735997ec2bd9d11bcde91e2be5eccb Mon Sep 17 00:00:00 2001 From: John Date: Thu, 19 Apr 2018 13:41:06 +0800 Subject: [PATCH] =?UTF-8?q?ghttp.Server=E5=90=AF=E5=8A=A8=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E6=97=B6=E5=A2=9E=E5=8A=A0=E6=8A=A5=E9=94=99=E6=8F=90?= =?UTF-8?q?=E9=86=92=EF=BC=8C=E5=AE=8C=E5=96=84glog=20backtrace=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E5=A2=9E=E5=8A=A0g.Map=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/g.go | 3 ++- g/net/ghttp/http_server.go | 2 ++ g/os/glog/glog.go | 7 ++++++- geg/other/test.go | 5 +++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/g/g.go b/g/g.go index 260512124..1bfbfd3e0 100644 --- a/g/g.go +++ b/g/g.go @@ -7,4 +7,5 @@ package g - +// 常用map数据结构 +type Map map[string]interface{} diff --git a/g/net/ghttp/http_server.go b/g/net/ghttp/http_server.go index a474d03b6..dc0c7c3e9 100644 --- a/g/net/ghttp/http_server.go +++ b/g/net/ghttp/http_server.go @@ -12,6 +12,7 @@ import ( "strings" "reflect" "net/http" + "gitee.com/johng/gf/g/os/glog" "gitee.com/johng/gf/g/os/gcache" "gitee.com/johng/gf/g/container/gmap" "gitee.com/johng/gf/g/container/gtype" @@ -133,6 +134,7 @@ func (s *Server) Run() error { s.startCloseQueueLoop() // 执行端口监听 if err := s.server.ListenAndServe(); err != nil { + glog.Error(err) return err } s.status = 1 diff --git a/g/os/glog/glog.go b/g/os/glog/glog.go index 15333bc36..23b96eb71 100644 --- a/g/os/glog/glog.go +++ b/g/os/glog/glog.go @@ -21,6 +21,7 @@ import ( "gitee.com/johng/gf/g/os/gfilepool" "runtime" "strconv" + "gitee.com/johng/gf/g/util/gregx" ) type Logger struct { @@ -247,6 +248,7 @@ func (l *Logger) checkLogIO() { fpath := path + string(filepath.Separator) + fname if fp, err := gfilepool.OpenWithPool(fpath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 600); err == nil { l.SetLogIO(fp.File()) + fp.Close() } else { fmt.Fprintln(os.Stderr, err) } @@ -293,7 +295,10 @@ func (l *Logger) backtrace() string { backtrace := "Trace:\n" for i := 1; i < 10000; i++ { if _, cfile, cline, ok := runtime.Caller(i + 3); ok { - backtrace += strconv.Itoa(i) + ". " + cfile + ":" + strconv.Itoa(cline) + "\n" + // 不打印出go源码路径 + if !gregx.IsMatchString("^" + runtime.GOROOT(), cfile) { + backtrace += strconv.Itoa(i) + ". " + cfile + ":" + strconv.Itoa(cline) + "\n" + } } else { break } diff --git a/geg/other/test.go b/geg/other/test.go index 06f3557d8..0fe79c90a 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -3,18 +3,19 @@ package main import ( "gitee.com/johng/gf/g/net/ghttp" "gitee.com/johng/gf/g/frame/gins" + "gitee.com/johng/gf/g" ) func main() { s := ghttp.GetServer() s.BindHandler("/template2", func(r *ghttp.Request){ tplcontent := `id:{{.id}}, name:{{.name}}` - content, _ := gins.View().ParseContent(tplcontent, map[string]interface{}{ + content, _ := gins.View().ParseContent(tplcontent, g.Map{ "id" : 123, "name" : "john", }) r.Response.Write(content) }) - s.SetPort(8199) + //s.SetPort(80) s.Run() } \ No newline at end of file