github.com/TykTechnologies/tyk/ctx
No package summary is available.
Package
Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 0. Benchmarks: 0.
Constants
const (
SessionData Key = iota
// Deprecated: UpdateSession was used to trigger a session update, use *SessionData.Touch instead.
UpdateSession
AuthToken
HashedAuthToken
VersionData
VersionName
VersionDefault
OrgSessionContext
ContextData
RetainHost
TrackThisEndpoint
DoNotTrackThisEndpoint
UrlRewritePath
RequestMethod
OrigRequestURL
LoopLevel
LoopLevelLimit
ThrottleLevel
ThrottleLevelLimit
Trace
CheckLoopLimits
UrlRewriteTarget
TransformedRequestMethod
Definition
RequestStatus
GraphQLRequest
GraphQLIsWebSocketUpgrade
OASOperation
// CacheOptions holds cache options required for cache writer middleware.
CacheOptions
OASDefinition
SelfLooping
)
Types
Key
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type Key uint
Functions
func GetAuthToken
func GetAuthToken(r *http.Request) string {
if v := r.Context().Value(AuthToken); v != nil {
value, ok := v.(string)
if ok {
return value
}
}
return ""
}
Cognitive complexity: 4, Cyclomatic complexity: 3
func GetDefinition
GetDefinition will return a deep copy of the API definition valid for the request.
func GetDefinition(r *http.Request) *apidef.APIDefinition {
if v := r.Context().Value(Definition); v != nil {
if val, ok := v.(*apidef.APIDefinition); ok {
return reflect.Clone(val)
}
}
return nil
}
Cognitive complexity: 4, Cyclomatic complexity: 3
func GetOASDefinition
GetOASDefinition will return a deep copy of the OAS API definition valid for the request.
func GetOASDefinition(r *http.Request) *oas.OAS {
if v := r.Context().Value(OASDefinition); v != nil {
if val, ok := v.(*oas.OAS); ok {
return reflect.Clone(val)
}
}
return nil
}
Cognitive complexity: 4, Cyclomatic complexity: 3
func GetSession
func GetSession(r *http.Request) *user.SessionState {
if v := r.Context().Value(SessionData); v != nil {
if val, ok := v.(*user.SessionState); ok {
return val
} else {
logger.Get().Warning("SessionState struct differ from the gateway version, trying to unmarshal.")
sess := user.SessionState{}
b, _ := json.Marshal(v)
e := json.Unmarshal(b, &sess)
if e == nil {
return &sess
}
}
}
return nil
}
Cognitive complexity: 9, Cyclomatic complexity: 4
func SetDefinition
SetDefinition sets an API definition object to the request context.
func SetDefinition(r *http.Request, s *apidef.APIDefinition) {
ctx := r.Context()
ctx = context.WithValue(ctx, Definition, s)
core.SetContext(r, ctx)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func SetOASDefinition
SetOASDefinition sets an OAS API definition object to the request context.
func SetOASDefinition(r *http.Request, s *oas.OAS) {
ctx := r.Context()
ctx = context.WithValue(ctx, OASDefinition, s)
core.SetContext(r, ctx)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func SetSession
func SetSession(r *http.Request, s *user.SessionState, scheduleUpdate bool, hashKey ...bool) {
if len(hashKey) > 1 {
ctxSetSession(r, s, scheduleUpdate, hashKey[0])
} else {
ctxSetSession(r, s, scheduleUpdate, config.Global().HashKeys)
}
}
Cognitive complexity: 4, Cyclomatic complexity: 2
Private functions
func ctxSetSession
ctxSetSession (r *http.Request, s *user.SessionState, scheduleUpdate bool, hashKey bool)
References: context.WithValue, core.SetContext, storage.HashKey.
Tests
Files: 1. Third party imports: 1. Imports from organisation: 1. Tests: 2. Benchmarks: 2.