From dcb74ee9df882e9c9d8df7b5d00442322918e53d Mon Sep 17 00:00:00 2001 From: John Date: Fri, 1 Nov 2019 20:36:09 +0800 Subject: [PATCH] comment update --- .example/os/gview/i18n/i18n.go | 21 +++++++++++ .example/other/test.go | 37 ++++++------------- os/glog/glog_logger.go | 10 +++-- ...{glog_unit_test.go => glog_z_unit_test.go} | 0 4 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 .example/os/gview/i18n/i18n.go rename os/glog/{glog_unit_test.go => glog_z_unit_test.go} (100%) diff --git a/.example/os/gview/i18n/i18n.go b/.example/os/gview/i18n/i18n.go new file mode 100644 index 000000000..b5a575244 --- /dev/null +++ b/.example/os/gview/i18n/i18n.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "github.com/gogf/gf/frame/g" +) + +func main() { + content := `{{.name}} says "a{#hello}{#world}!"` + result1, _ := g.View().ParseContent(content, g.Map{ + "name": "john", + "I18nLanguage": "zh-CN", + }) + fmt.Println(result1) + + result2, _ := g.View().ParseContent(content, g.Map{ + "name": "john", + "I18nLanguage": "ja", + }) + fmt.Println(result2) +} diff --git a/.example/other/test.go b/.example/other/test.go index b203dfff9..31633195c 100644 --- a/.example/other/test.go +++ b/.example/other/test.go @@ -1,35 +1,22 @@ package main import ( - "fmt" - "github.com/gogf/gf/encoding/gbase64" "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/gipv4" - "github.com/gogf/gf/os/gproc" - "github.com/gogf/gf/os/gtime" - "math" - "net" + "github.com/gogf/gf/net/ghttp" ) func main() { - netInterfaces, err := net.Interfaces() - if err != nil { - fmt.Printf("fail to get net interfaces: %v", err) - } + s := g.Server() + s.BindHandler("/", func(r *ghttp.Request) { - for _, netInterface := range netInterfaces { - macAddr := netInterface.HardwareAddr.String() - if len(macAddr) == 0 { - continue - } - fmt.Println(net.ParseMAC(netInterface.HardwareAddr.String())) - } + }) + s.BindHandler("/user", func(r *ghttp.Request) { - return - ip, _ := gipv4.IntranetIP() - - g.Dump(math.MaxInt64) - g.Dump(gipv4.Ip2long(ip), gbase64.EncodeString(ip)) - g.Dump(gproc.Pid()) - g.Dump(gtime.Nanosecond()) + }) + s.BindHandler("/user/:id", func(r *ghttp.Request) { + r.Response.Write(r.GetRouterString("id")) + }) + s.EnablePprof() + s.SetPort(3000) + s.Run() } diff --git a/os/glog/glog_logger.go b/os/glog/glog_logger.go index e0d74addd..fafb65012 100644 --- a/os/glog/glog_logger.go +++ b/os/glog/glog_logger.go @@ -9,6 +9,7 @@ package glog import ( "bytes" "fmt" + "github.com/gogf/gf/internal/intlog" "io" "os" "strings" @@ -65,11 +66,11 @@ func (l *Logger) Clone() *Logger { // It returns nil if file logging is disabled, or file opening fails. func (l *Logger) getFilePointer() *gfpool.File { if path := l.config.Path; path != "" { - // Content containing "{}" in the file name is formatted using gtime + // Content containing "{}" in the file name is formatted using gtime. file, _ := gregex.ReplaceStringFunc(`{.+?}`, l.config.File, func(s string) string { return gtime.Now().Format(strings.Trim(s, "{}")) }) - // Create path if it does not exist。 + // Create path if it does not exist. if !gfile.Exists(path) { if err := gfile.Mkdir(path); err != nil { fmt.Fprintln(os.Stderr, fmt.Sprintf(`[glog] mkdir "%s" failed: %s`, path, err.Error())) @@ -158,9 +159,12 @@ func (l *Logger) print(std io.Writer, lead string, value ...interface{}) { } buffer.WriteString(valueStr + "\n") if l.config.Flags&F_ASYNC > 0 { - asyncPool.Add(func() { + err := asyncPool.Add(func() { l.printToWriter(std, buffer) }) + if err != nil { + intlog.Error(err) + } } else { l.printToWriter(std, buffer) } diff --git a/os/glog/glog_unit_test.go b/os/glog/glog_z_unit_test.go similarity index 100% rename from os/glog/glog_unit_test.go rename to os/glog/glog_z_unit_test.go