util

package
v0.0.0-...-7acbc57 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//ErrUtilJWTMapping error message for JWT mapping
	ErrUtilJWTMapping = "invalid mapping JWT claim with key '%s'"
)

Variables

This section is empty.

Functions

func GetClaimFromJWT

func GetClaimFromJWT(r *http.Request, ClaimID string) (interface{}, error)

GetClaimFromJWT get claim value using id

func GetClaimStringFromJWT

func GetClaimStringFromJWT(r *http.Request, claimID string) (string, error)

GetClaimStringFromJWT get ID From claim

func Hash

func Hash(plainString string) (string, error)

Hash return hash result from string input

func HashCompare

func HashCompare(plainString string, hashedString string) bool

HashCompare compare hashed string with plain string

func IsZeroOfUnderlyingType

func IsZeroOfUnderlyingType(x interface{}) bool

func MergeError

func MergeError(message string, err ...error) error

MergeError merge error message

func ParsePayload

func ParsePayload(r *http.Request, result interface{}) error

ParsePayload parse http body to respected model payload := new(model.User) _ := util.ParsePayload(r, payload)

func RandString

func RandString(n int) string

func URLParam

func URLParam(r *http.Request, key string) string

URLParam get url parameter

func WriteJSONData

func WriteJSONData(w http.ResponseWriter, data interface{}, message ...string)

WriteJSONData write http response as json

func WriteJSONDataWithTotal

func WriteJSONDataWithTotal(w http.ResponseWriter, data interface{}, total int64, message ...string)

WriteJSONDataWithTotal write http response as json with total data. Usualy it is used for grid / table data

func WriteJSONError

func WriteJSONError(w http.ResponseWriter, err error, statusCode ...int)

WriteJSONError write http response error as json

Types

type Error

type Error struct {
	Tag     string
	Message interface{}
	Errors  []error
	Data    map[string]interface{}
}

Error customized error

func (Error) Error

func (b Error) Error() string

Jump to

Keyboard shortcuts

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