go-fastdfs/server/handler.go
2021-05-18 14:37:12 +08:00

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)
}