mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
fix issue 437
This commit is contained in:
16
.example/net/ghttp/server/template/conflicts-name/client.go
Normal file
16
.example/net/ghttp/server/template/conflicts-name/client.go
Normal file
@ -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()
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
1
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ func Join(paths ...string) string {
|
||||
|
||||
// Exists checks whether given <path> 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())
|
||||
|
||||
@ -40,7 +40,7 @@ func fileRealPath(path string) string {
|
||||
|
||||
// fileExists checks whether given <path> 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
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user