Go API Documentation

github.com/TykTechnologies/tyk/internal/service/core

No package summary is available.

Package

Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

const (
	upstreamAuth = ContextKey("upstream-auth")
)

Types

ContextKey

ContextKey is the key type to be used for context interactions.

Field name Field type Comment
type

string

No comment on field.
type ContextKey string

Functions

func GetUpstreamAuth

GetUpstreamAuth returns the header name to be used for upstream authentication.

func GetUpstreamAuth(r *http.Request) model.UpstreamAuthProvider {
	auth := r.Context().Value(upstreamAuth)
	if auth == nil {
		return nil
	}

	provider, ok := auth.(model.UpstreamAuthProvider)
	if !ok {
		return nil
	}

	return provider
}

Cognitive complexity: 4, Cyclomatic complexity: 3

Uses: model.UpstreamAuthProvider.

func SetContext

SetContext updates the context of a request.

func SetContext(r *http.Request, ctx context.Context) {
	r2 := r.WithContext(ctx)
	*r = *r2
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func SetUpstreamAuth

SetUpstreamAuth sets the header name to be used for upstream authentication.

func SetUpstreamAuth(r *http.Request, auth model.UpstreamAuthProvider) {
	ctx := r.Context()
	ctx = context.WithValue(ctx, upstreamAuth, auth)
	SetContext(r, ctx)
}

Cognitive complexity: 0, Cyclomatic complexity: 1

Uses: context.WithValue.

Tests

Files: 1. Third party imports: 1. Imports from organisation: 0. Tests: 2. Benchmarks: 0.

Test functions

TestSetContext

References: assert.Equal, assert.Nil, context.Background, context.WithValue, core.ContextKey, core.SetContext, testing.T.

TestUpstreamAuth

References: assert.Equal, assert.Nil, assert.NotNil, context.WithValue, core.ContextKey, core.GetUpstreamAuth, core.SetContext, core.SetUpstreamAuth, model.MockUpstreamAuthProvider, testing.T.