handler

package
v0.0.0-...-c877efe Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMethodNotAllowed = &ErrorResponse{StatusCode: 405, Message: "Method not allowed, (405)"}
	ErrNotFound         = &ErrorResponse{StatusCode: 404, Message: "Error! Resource not found. (404)"}
	ErrBadRequest       = &ErrorResponse{StatusCode: 400, Message: "Bad request, (400)"}
	UnAuthorized        = &ErrorResponse{StatusCode: 401, Message: "Unauthorized! (401)"}
)

Functions

func ItemContext

func ItemContext(next http.Handler) http.Handler

func NewHandler

func NewHandler(db db.Database) http.Handler

func UserContext

func UserContext(next http.Handler) http.Handler

func ValidateSession

func ValidateSession(w http.ResponseWriter, r *http.Request) (*models.User, error)

ValidateSession and check user has atleast one of the roles. returns WebUserObject object iff session is valid

Types

type Claims

type Claims struct {
	Id       int    `json:"id"` // User Id
	Username string `json:"username"`
	Password string `json:"password"`
	jwt.StandardClaims
}

Claims struct for jwt token contents

type Credentials

type Credentials struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

Credentials struct for demarshalling session post body

type ErrorResponse

type ErrorResponse struct {
	Err        error  `json:"-"`
	StatusCode int    `json:"-"`
	StatusText string `json:"status_text"`
	Message    string `json:"message"`
}

func ErrorRenderer

func ErrorRenderer(err error) *ErrorResponse

func ServerErrorRenderer

func ServerErrorRenderer(err error) *ErrorResponse

func (*ErrorResponse) Render

Jump to

Keyboard shortcuts

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