diff --git a/.example/net/ghttp/server/template/conflicts-name/client b/.example/net/ghttp/server/template/conflicts-name/client new file mode 100644 index 000000000..e69de29bb diff --git a/.example/net/ghttp/server/template/conflicts-name/client.go b/.example/net/ghttp/server/template/conflicts-name/client.go new file mode 100644 index 000000000..48786e7a8 --- /dev/null +++ b/.example/net/ghttp/server/template/conflicts-name/client.go @@ -0,0 +1,16 @@ +package main + +import ( + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/net/ghttp" +) + +// https://github.com/gogf/gf/issues/437 +func main() { + s := g.Server() + s.BindHandler("/", func(r *ghttp.Request) { + r.Response.WriteTpl("client/layout.html") + }) + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/ghttp/server/template/conflicts-name/template/client/layout.html b/.example/net/ghttp/server/template/conflicts-name/template/client/layout.html new file mode 100644 index 000000000..56a6051ca --- /dev/null +++ b/.example/net/ghttp/server/template/conflicts-name/template/client/layout.html @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/errors/gerror/gerror_error.go b/errors/gerror/gerror_error.go index d58b83ab2..6b0927872 100644 --- a/errors/gerror/gerror_error.go +++ b/errors/gerror/gerror_error.go @@ -131,8 +131,8 @@ func formatSubStack(st stack, buffer *bytes.Buffer) { if strings.Contains(file, gFILTER_KEY) { continue } + // Avoid GF stacks if not in GF development. if !intlog.IsInGFDevelop() { - // Avoid GF stacks if not in GF development. if strings.Contains(file, "github.com/gogf/gf/") { continue } diff --git a/net/ghttp/ghttp_server_log.go b/net/ghttp/ghttp_server_log.go index 165546db5..4e10c766f 100644 --- a/net/ghttp/ghttp_server_log.go +++ b/net/ghttp/ghttp_server_log.go @@ -24,13 +24,15 @@ func (s *Server) handleAccessLog(r *Request) { if r.TLS != nil { scheme = "https" } - s.config.Logger.File(s.config.AccessLogPattern).Stdout(s.config.LogStdout).Printf( - `%d "%s %s %s %s %s" %.3f, %s, "%s", "%s"`, - r.Response.Status, - r.Method, scheme, r.Host, r.URL.String(), r.Proto, - float64(r.LeaveTime-r.EnterTime)/1000, - r.GetClientIp(), r.Referer(), r.UserAgent(), - ) + s.config.Logger.File(s.config.AccessLogPattern). + Stdout(s.config.LogStdout). + Printf( + `%d "%s %s %s %s %s" %.3f, %s, "%s", "%s"`, + r.Response.Status, + r.Method, scheme, r.Host, r.URL.String(), r.Proto, + float64(r.LeaveTime-r.EnterTime)/1000, + r.GetClientIp(), r.Referer(), r.UserAgent(), + ) } // 处理服务错误信息,主要是panic,http请求的status由access log进行管理 @@ -52,12 +54,15 @@ func (s *Server) handleErrorLog(err error, r *Request) { ) if stack := gerror.Stack(err); stack != "" { content += "\nStack:\n" + stack - s.config.Logger.File(s.config.AccessLogPattern).Stack(false).Stdout(s.config.LogStdout).Error(content) + s.config.Logger.File(s.config.AccessLogPattern). + Stack(false). + Stdout(s.config.LogStdout). + Error(content) return } s.config.Logger.File(s.config.AccessLogPattern). Stack(s.config.ErrorStack). StackWithFilter(gPATH_FILTER_KEY). Stdout(s.config.LogStdout). - Errorf(content) + Error(content) } diff --git a/os/gfile/gfile.go b/os/gfile/gfile.go index e693dfd1a..be9ce3c78 100644 --- a/os/gfile/gfile.go +++ b/os/gfile/gfile.go @@ -101,7 +101,7 @@ func Join(paths ...string) string { // Exists checks whether given exist. func Exists(path string) bool { - if _, err := os.Stat(path); !os.IsNotExist(err) { + if stat, err := os.Stat(path); stat != nil && !os.IsNotExist(err) { return true } return false @@ -228,11 +228,7 @@ func CopyDir(src string, dst string) (err error) { if !si.IsDir() { return fmt.Errorf("source is not a directory") } - _, err = os.Stat(dst) - if err != nil && !os.IsNotExist(err) { - return - } - if err == nil { + if Exists(dst) { return fmt.Errorf("destination already exists") } err = os.MkdirAll(dst, si.Mode()) diff --git a/os/gfsnotify/gfsnotify_filefunc.go b/os/gfsnotify/gfsnotify_filefunc.go index 37f0da364..7518ca19f 100644 --- a/os/gfsnotify/gfsnotify_filefunc.go +++ b/os/gfsnotify/gfsnotify_filefunc.go @@ -40,7 +40,7 @@ func fileRealPath(path string) string { // fileExists checks whether given exist. func fileExists(path string) bool { - if _, err := os.Stat(path); !os.IsNotExist(err) { + if stat, err := os.Stat(path); stat != nil && !os.IsNotExist(err) { return true } return false diff --git a/os/gspath/gspath.go b/os/gspath/gspath.go index 8c7a501ad..89d2d06d5 100644 --- a/os/gspath/gspath.go +++ b/os/gspath/gspath.go @@ -165,7 +165,7 @@ func (sp *SPath) Search(name string, indexFiles ...string) (filePath string, isD path := "" for _, v := range array { path = gfile.Join(v, name) - if stat, err := os.Stat(path); !os.IsNotExist(err) { + if stat, err := os.Stat(path); stat != nil && !os.IsNotExist(err) { path = gfile.Abs(path) // Security check: the result file path must be under the searching directory. if len(path) >= len(v) && path[:len(v)] == v {