fiber

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: Unlicense Imports: 10 Imported by: 0

Documentation

Overview

Package fiber provides utility functions for gofiber v2, jwt-go With additional validation functions, sending JSON response and parsing request bodies, getting JWT claims

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticationMiddleware added in v0.1.1

func AuthenticationMiddleware(j JWTConfig) func(*fiber.Ctx) error

AuthenticationMiddleware ...

func CheckFieldLength

func CheckFieldLength(field, title string, max, min int) (ok bool, message string)

CheckFieldLength Validation of strings' length and return if valid based on maximum and minimum length specified and error message if invalid

func GenerateJWTSignedString added in v0.1.1

func GenerateJWTSignedString(claimMaps fiber.Map) (string, error)

GenerateJWTSignedString ...

func GetJSONFieldValues

func GetJSONFieldValues(q interface{}) map[string]string

GetJSONFieldValues Returns a map of JSON keys and values of a struct

func GetJWTClaim

func GetJWTClaim(key string) map[string]interface{}

GetJWTClaim Wrapper function for getting a JWT claim by key

func GetJWTClaimOfType added in v0.1.2

func GetJWTClaimOfType(key string, valueType interface{}) error

GetJWTClaimOfType ...

func GetJWTClaims

func GetJWTClaims() jwt.MapClaims

GetJWTClaims Get User JWT claims of the current context

func LogError

func LogError(err error)

LogError Logs errors

func ParseBody

func ParseBody(in interface{}) error

ParseBody Parses the request body from the copied current context

func SendBadRequestResponse

func SendBadRequestResponse(message string) error

SendBadRequestResponse Wrapper function for SendJSONMessage of 400 Bad request

func SendJSONMessage

func SendJSONMessage(message string, isSuccess bool, httpStatusCode int) error

SendJSONMessage Sends JSON Message with HTTP Status code to current context

func SendSuccessResponse

func SendSuccessResponse(message string) error

SendSuccessResponse Wrapper function for SendJSONMessage of 200 Success

func ValidateField

func ValidateField(field, title string, isMandatory bool, max, min int, format string) (ok bool, message string)

ValidateField Validation of strings and return if valid based on specification and error message if invalid

func ValidateJSONField

func ValidateJSONField(q interface{}, tag string, isMandatory bool, max, min int, format string) (bool, string)

ValidateJSONField Wrapper function for JSON field validation of a struct

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context GoFiber Context

var Ctx Context

Ctx Context to be initiated by the New function

func (*Context) New

func (ctx *Context) New(c *fiber.Ctx)

New Copies GoFiber context as new current context

type JWTConfig added in v0.1.1

type JWTConfig struct {
	Duration     time.Duration
	CookieMaxAge int
	SetCookies   bool
	SecretKey    []byte
}

JWTConfig configuration for JWT

type Message

type Message struct {
	Message string `json:"message"`
	Status  string `json:"status"`
}

Message struct for GoFiber context response

Jump to

Keyboard shortcuts

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