mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 09:40:24 +08:00
22 lines
382 B
Go
22 lines
382 B
Go
package context
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
)
|
|
|
|
const pathVars = "pathVars"
|
|
|
|
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))
|
|
}
|