responses

package
v0.0.0-...-59cac3b Latest Latest
Warning

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

Go to latest
Published: Oct 13, 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
	Not_Enough_Mana             ResponseCode = 13
	No_Such_Ritual              ResponseCode = 14
	No_Golem_Found              ResponseCode = 15
	Ritual_Not_Known            ResponseCode = 16
	No_Such_Status              ResponseCode = 17
	Golem_In_Blocking_Status    ResponseCode = 18
	New_Status_Not_Allowed      ResponseCode = 19
	Bad_Request                 ResponseCode = 20
	No_Available_Routes         ResponseCode = 21
	Target_Route_Unavailable    ResponseCode = 22
	UDB_Update_Failed           ResponseCode = 23
	Leaderboard_Not_Found       ResponseCode = 24
)

Jump to

Keyboard shortcuts

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