github.com/koko1123/flow-go-1@v0.29.6/engine/access/rest/middleware/request_attribute.go (about) 1 package middleware 2 3 import ( 4 "context" 5 "net/http" 6 ) 7 8 type ctxKeyType string 9 10 // addRequestAttribute adds the given attribute name and value to the request context 11 func addRequestAttribute(req *http.Request, attributeName string, attributeValue interface{}) *http.Request { 12 contextKey := ctxKeyType(attributeName) 13 return req.WithContext(context.WithValue(req.Context(), contextKey, attributeValue)) 14 } 15 16 // getRequestAttribute returns the value for the given attribute name from the request context if found 17 func getRequestAttribute(req *http.Request, attributeName string) (interface{}, bool) { 18 contextKey := ctxKeyType(attributeName) 19 value := req.Context().Value(contextKey) 20 return value, value != nil 21 }