helper

package
v0.0.0-...-4598f8e Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package helper for handling response to client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIErrorResponse

func APIErrorResponse(c *gin.Context, statusCode int, err interface{})

APIErrorResponse will send JSON response with error value to the client

func APIResponse

func APIResponse(c *gin.Context, statusCode int, message string, data interface{})

APIResponse will send JSON response to the client and some additional detail

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswordHash will compare 'hashed' password with the 'input' password

func EmailIsValid

func EmailIsValid(email string) (isValid bool)

EmailIsValid will check whether given email was valid

func GenerateSecureKey

func GenerateSecureKey(length int) (string, error)

GenerateSecureKey will create 'Secure Key' with given length

func HashPassword

func HashPassword(password string) (hashed string, err error)

HashPassword will generated hashed password so it wont easily be roken by unauthorized person

func PasswordTooShort

func PasswordTooShort(password string) (isPasswordtooShort bool)

PasswordTooShort will check whether password length is not match the minimum password lenght for the user account

func ValidationError

func ValidationError(err error) (eMessage *[]string)

ValidationError is a 'Request' error detail generator it will break given error value into detailed error message so we know which field is the cause of error upon handling request

Types

type Error

type Error struct {
	ErrCode uint   `json:"code"`
	Message string `json:"message,omitempty"`
	Error   error  `json:"error"`
}

Error is custom dbError struct

type ErrorResponse

type ErrorResponse struct {
	Status int         `json:"status"`
	Method string      `json:"method"`
	Error  interface{} `json:"error"`
}

ErrorResponse is a response that containing error Details of the error shoul not be technical as it will be sent to the user

type Response

type Response struct {
	Status  int         `json:"status"`
	Method  string      `json:"method"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

Response is response helper to send to client/ user

Jump to

Keyboard shortcuts

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