Documentation
¶
Overview ¶
Package middleware contains application specific middleware.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware(auth Authentication) func(http.Handler) http.Handler
AuthMiddleware creates an http middleware that validates auth tokens in requests.
It takes an Authentication interface and returns a middleware function that checks for valid Authorization header tokens, responding with 401 Unauthorized if validation fails.
Types ¶
type Authentication ¶
type AuthenticationMock ¶
type AuthenticationMock struct { // ValidateTokenFunc mocks the ValidateToken method. ValidateTokenFunc func(ctx context.Context, token string) (bool, error) // contains filtered or unexported fields }
AuthenticationMock is a mock implementation of Authentication.
func TestSomethingThatUsesAuthentication(t *testing.T) { // make and configure a mocked Authentication mockedAuthentication := &AuthenticationMock{ ValidateTokenFunc: func(ctx context.Context, token string) (bool, error) { panic("mock out the ValidateToken method") }, } // use mockedAuthentication in code that requires Authentication // and then make assertions. }
func (*AuthenticationMock) ValidateToken ¶
ValidateToken calls ValidateTokenFunc.
func (*AuthenticationMock) ValidateTokenCalls ¶
func (mock *AuthenticationMock) ValidateTokenCalls() []struct { Ctx context.Context Token string }
ValidateTokenCalls gets all the calls that were made to ValidateToken. Check the length with:
len(mockedAuthentication.ValidateTokenCalls())
Click to show internal directories.
Click to hide internal directories.