utils

package
v0.0.0-...-204c8b9 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticationRequiredMiddleware

func AuthenticationRequiredMiddleware(next http.Handler) http.Handler

AuthenticationRequiredMiddleware will check if the user has valid permissions

func CreateSignedToken

func CreateSignedToken(claims *UserClaim) (string, error)

createSignedToken will create and return a signed token based on the username

func ErrorResponseWriter

func ErrorResponseWriter(rw http.ResponseWriter, statusCode int, message string, data interface{}) error

ErrorResponseWriter writes response of type - ErrorResponse

func JSONContentTypeMiddleware

func JSONContentTypeMiddleware(next http.Handler) http.Handler

JSONContentTypeMiddleware will add the json content type header for all endpoints

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

LoggingMiddleware will log all requests

func PaginatedResponseWriter

func PaginatedResponseWriter(rw http.ResponseWriter, statusCode int, message string, count int, next string, prev string, students []models.Student) error

PaginatedResponseWriter writes response of type - PaginatedResponse

func ParseToken

func ParseToken(tokenString string, claims *UserClaim) (*jwt.Token, error)

parseToken will parse a token from a string

func ResponseWriter

func ResponseWriter(rw http.ResponseWriter, statusCode int, message string, student models.Student) error

ResponseWriter writes response of type - Response

Types

type Credentials

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

type UserClaim

type UserClaim struct {
	*jwt.StandardClaims
	UserInfo
}

type UserInfo

type UserInfo struct {
	Username string
}

Jump to

Keyboard shortcuts

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