fix golint issues in rest (#529)
This commit is contained in:
@@ -10,19 +10,23 @@ import (
|
||||
"github.com/tal-tech/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// LogContext is a context key.
|
||||
var LogContext = contextKey("request_logs")
|
||||
|
||||
// A LogCollector is used to collect logs.
|
||||
type LogCollector struct {
|
||||
Messages []string
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
// Append appends msg into log context.
|
||||
func (lc *LogCollector) Append(msg string) {
|
||||
lc.lock.Lock()
|
||||
lc.Messages = append(lc.Messages, msg)
|
||||
lc.lock.Unlock()
|
||||
}
|
||||
|
||||
// Flush flushes collected logs.
|
||||
func (lc *LogCollector) Flush() string {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
@@ -48,18 +52,22 @@ func (lc *LogCollector) takeAll() []string {
|
||||
return messages
|
||||
}
|
||||
|
||||
// Error logs the given v along with r in error log.
|
||||
func Error(r *http.Request, v ...interface{}) {
|
||||
logx.ErrorCaller(1, format(r, v...))
|
||||
}
|
||||
|
||||
// Errorf logs the given v with format along with r in error log.
|
||||
func Errorf(r *http.Request, format string, v ...interface{}) {
|
||||
logx.ErrorCaller(1, formatf(r, format, v...))
|
||||
}
|
||||
|
||||
// Info logs the given v along with r in access log.
|
||||
func Info(r *http.Request, v ...interface{}) {
|
||||
appendLog(r, format(r, v...))
|
||||
}
|
||||
|
||||
// Infof logs the given v with format along with r in access log.
|
||||
func Infof(r *http.Request, format string, v ...interface{}) {
|
||||
appendLog(r, formatf(r, format, v...))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user