mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 12:17:53 +08:00
ghttp.Server启动失败时增加报错提醒,完善glog backtrace信息,增加g.Map类型
This commit is contained in:
parent
7bdb528f5d
commit
b3c672b08b
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user