mirror of
https://gitee.com/sjqzhang/go-fastdfs.git
synced 2024-12-02 03:08:11 +08:00
43 lines
841 B
Go
43 lines
841 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"runtime/debug"
|
|
"time"
|
|
|
|
log "github.com/sjqzhang/seelog"
|
|
)
|
|
|
|
type HttpHandler struct{}
|
|
|
|
func (HttpHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
|
status_code := "200"
|
|
defer func(t time.Time) {
|
|
logStr := fmt.Sprintf("[Access] %s | %s | %s | %s | %s |%s",
|
|
time.Now().Format("2006/01/02 - 15:04:05"),
|
|
//res.Header(),
|
|
time.Since(t).String(),
|
|
server.util.GetClientIp(req),
|
|
req.Method,
|
|
status_code,
|
|
req.RequestURI,
|
|
)
|
|
logacc.Info(logStr)
|
|
}(time.Now())
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
status_code = "500"
|
|
res.WriteHeader(500)
|
|
print(err)
|
|
buff := debug.Stack()
|
|
log.Error(err)
|
|
log.Error(string(buff))
|
|
}
|
|
}()
|
|
if Config().EnableCrossOrigin {
|
|
server.CrossOrigin(res, req)
|
|
}
|
|
http.DefaultServeMux.ServeHTTP(res, req)
|
|
}
|