You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/rest/internal/context/params.go

28 lines
507 B
Go

4 years ago
package context
import (
"context"
"net/http"
)
var pathVars = contextKey("pathVars")
4 years ago
func Vars(r *http.Request) map[string]string {
vars, ok := r.Context().Value(pathVars).(map[string]string)
if ok {
return vars
}
return nil
}
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 {
4 years ago
return "rest/internal/context key: " + string(c)
}