diff --git a/core/trace/tracespec/vars.go b/core/trace/tracespec/keys.go similarity index 100% rename from core/trace/tracespec/vars.go rename to core/trace/tracespec/keys.go diff --git a/rest/internal/context/params.go b/rest/internal/context/params.go index b1f9ecf5..b25e0e6b 100644 --- a/rest/internal/context/params.go +++ b/rest/internal/context/params.go @@ -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) +} diff --git a/rest/internal/log.go b/rest/internal/log.go index 80b19355..1b4d2f7f 100644 --- a/rest/internal/log.go +++ b/rest/internal/log.go @@ -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) +}