middleware

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2019 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextMiddleware

func ContextMiddleware(
	con interface{},
	findUserFunc FindUser,
	config *_conf.Config,
) func(http.Handler) http.Handler

ContextMiddleware adds the authenticated user to http.Request.Context. if there's the token in the specified header / cookie in config.

func GetUser

func GetUser(ctx context.Context) interface{}

GetUser get user from context

func JwtToUser

func JwtToUser(
	jwtStr string,
	findUserFunc FindUser,
	con interface{},
	config *_conf.Config,
) (interface{}, error)

JwtToUser converts jwStr to the corresponding user.

func LoginRequired

func LoginRequired(
	con interface{},
	findUserFunc FindUser,
	conf *config.Config,
) func(http.Handler) http.Handler

LoginRequired enforces user authentication. If the user is not authenticated, it returns 401 (Not Authenticated).

func SetUser

func SetUser(
	r *http.Request,
	user interface{},
) *http.Request

SetUser set user to context

Types

type Error

type Error struct {
	Message string `json:"message,omitempty"`
}

Error represents an error.

type FindUser

type FindUser func(con interface{}, username string) (interface{}, error)

FindUser represents a function to find a user by username,

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL