use package level defined contextKey as context key
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const pathVars = "pathVars"
|
||||
var pathVars = contextKey("pathVars")
|
||||
|
||||
func Vars(r *http.Request) map[string]string {
|
||||
vars, ok := r.Context().Value(pathVars).(map[string]string)
|
||||
@@ -19,3 +19,9 @@ func Vars(r *http.Request) map[string]string {
|
||||
func WithPathVars(r *http.Request, params map[string]string) *http.Request {
|
||||
return r.WithContext(context.WithValue(r.Context(), pathVars, params))
|
||||
}
|
||||
|
||||
type contextKey string
|
||||
|
||||
func (c contextKey) String() string {
|
||||
return "rest/internal/context context key" + string(c)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user