responses

package
v0.0.0-...-dd894d6 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatResponse

func FormatResponse(code ResponseCode, data interface{}, messageDetail string) (string, error)

Returns the prettified json string of a properly structure api response given the inputs

func JSON

func JSON(input interface{}) (string, error)

Prettifies input into json string for output

func SendRes

func SendRes(w http.ResponseWriter, code ResponseCode, data interface{}, messageDetail string)

Types

type Response

type Response struct {
	Code    ResponseCode `json:"code" binding:"required"`
	Message string       `json:"message" binding:"required"`
	Data    interface{}  `json:"data"`
}

Defines Response structure for output

type ResponseCode

type ResponseCode int

enum for api response codes

const (
	CRITICAL_JSON_MARSHAL_ERROR ResponseCode = -3
	JSON_Marshal_Error          ResponseCode = -2
	Unimplemented               ResponseCode = -1
	Generic_Failure             ResponseCode = 0
	Generic_Success             ResponseCode = 1
	Auth_Failure                ResponseCode = 2
	Username_Validation_Failure ResponseCode = 3
	DB_Save_Failure             ResponseCode = 4
	Generate_Token_Failure      ResponseCode = 5
	WDB_Get_Failure             ResponseCode = 6
	UDB_Get_Failure             ResponseCode = 7
	JSON_Unmarshal_Error        ResponseCode = 8
	No_WDB_Context              ResponseCode = 9
	No_UDB_Context              ResponseCode = 10
	No_AuthPair_Context         ResponseCode = 11
	User_Not_Found              ResponseCode = 12
)

Jump to

Keyboard shortcuts

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