use package level defined contextKey as context key

This commit is contained in:
kevin
2020-09-20 12:46:35 +08:00
parent dc17855367
commit 86d3de4c89
3 changed files with 14 additions and 2 deletions

View File

@@ -10,7 +10,7 @@ import (
"github.com/tal-tech/go-zero/rest/httpx"
)
const LogContext = "request_logs"
var LogContext = contextKey("request_logs")
type LogCollector struct {
Messages []string
@@ -82,3 +82,9 @@ func formatf(r *http.Request, format string, v ...interface{}) string {
func formatWithReq(r *http.Request, v string) string {
return fmt.Sprintf("(%s - %s) %s", r.RequestURI, httpx.GetRemoteAddr(r), v)
}
type contextKey string
func (c contextKey) String() string {
return "rest/internal context key " + string(c)
}