lib

package
v0.0.0-...-9477886 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VALIDATE_ERROR = 101 //Primary Validation fail
	NO_ERROR       = 0
)

Error Code. PLEASE Map New Error Code To The HTTP Code Map Below.

View Source
const (
	STATUS_OK          = 200
	STATUS_BAD_REQUEST = 400
)

HTTP Code

View Source
const INVALID_REQUEST_MSG = "Invalid Request, Please provide correct input"

Error Messages

View Source
const PACKAGE_NAME = "github.com/mayur-tolexo/drift/lib"

Variables

View Source
var (
	//ErrorHTTPCode : Error Code to Http Code map
	ErrorHTTPCode = map[int]int{
		NO_ERROR:       STATUS_OK,
		VALIDATE_ERROR: STATUS_BAD_REQUEST,
	}
)

Functions

func AppendDebugMsg

func AppendDebugMsg(err error, debugMsg ...string) error

AppendDebugMsg : append debugMsg in error

func BadReqError

func BadReqError(err error, debugMsg ...string) error

BadReqError : error occured while validating request like while typecasting request, fk in request dosn't exists

func BuildResponse

func BuildResponse(data interface{}, err error) (int, interface{})

BuildResponse : creates the response of API

func GetErrorCode

func GetErrorCode(err error) (code int)

GetErrorCode : Get Error Code from *Error

func GetErrorHTTPCode

func GetErrorHTTPCode(err error) (httpCode int, status bool)

GetErrorHTTPCode : Get HTTP code from error code. Please check for httpCode = 0.

func GetPriorityValue

func GetPriorityValue(a ...interface{}) (pVal interface{})

GetPriorityValue : get the value by priority

func StackTrace

func StackTrace(depth int) (funcName string, file string, line int)

StackTrace : Get function name, file name and line no of the caller function Depth is the value from which it will start searching in the stack

func Unmarshal

func Unmarshal(reqBody string, structModel interface{}) (err error)

Unmarshal : unmarshal of request body and wrap error

func UnmarshalError

func UnmarshalError(err error, debugMsg ...string) error

UnmarshalError : error occured while unmarshal

func VError

func VError(debugMsg ...string) error

VError : validation error

Types

type Error

type Error struct {
	Code     int    `json:"code"`
	Msg      string `json:"Message"`
	Trace    string `json:"trace,omitempty"`
	DebugMsg string `json:"debug_msg,omitempty"`
}

Error Model

func (*Error) Error

func (e *Error) Error() string

Error : Implement Error method of error interface

type MsgResp

type MsgResp struct {
	Data interface{}
	Msg  string
}

MsgResp : Message response for create/update/delete api

type Resp

type Resp struct {
	Data   interface{} `json:"data,omitempty"`
	Error  error       `json:"error,omitempty"`
	Status bool        `json:"status"`
}

Resp : Response Model

func NewResp

func NewResp() *Resp

NewResp : Create New Response Objext

func (*Resp) Set

func (r *Resp) Set(data interface{}, status bool, err error)

Set Response Values

Jump to

Keyboard shortcuts

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