common

package
v0.0.0-...-dacb89a Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JWT Record and claim
	JWT_COL_NAME         = "jwt"
	JWT_USER_ATTR        = "user"
	JWT_PASS_ATTR        = "pass"
	JWT_ENDPOINTS_ATTR   = "endpoints"
	JWT_COLLECTIONS_ATTR = "collections"
	JWT_USER_ADMIN       = "admin"
	// JWT claim
	JWT_EXPIRY = "exp"
)

Variables

This section is empty.

Functions

func AuthenticateUser

func AuthenticateUser(next http.Handler) http.Handler

func DisplayAppError

func DisplayAppError(w http.ResponseWriter, handlerError error, message string, code int)

func Error

func Error(w http.ResponseWriter, r *http.Request, code int, err error)

func GenerateJWT

func GenerateJWT(user *model.User) (string, error)

Generate JWT token

func InitKeys

func InitKeys()

Read the key files before starting http handlers

func Respond

func Respond(w http.ResponseWriter, r *http.Request, code int, data interface{})

Types

type AppClaims

type AppClaims struct {
	jwt.StandardClaims
	Phone string `json:"phone"`
}

type TokenExtractor

type TokenExtractor struct {
}

Extract JWT from Authorization header or "access_token" attribute.

func (TokenExtractor) ExtractToken

func (t TokenExtractor) ExtractToken(req *http.Request) (string, error)

Jump to

Keyboard shortcuts

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