jio

package
v0.0.0-...-41fd8b9 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: MIT Imports: 5 Imported by: 3

README

jio Folder

JIO stands for JSON Input Output, these files are mostly used for easily converting json to structs and back to json again.

jio/in

The in file contains functions for checking the input of the request.

jio/out

The out file contains functions for converting any output to JSON. If you need to add or change custom errors this is the file where you would find it.

Documentation

Index

Constants

View Source
const (
	InvalidParameters   int = 4001
	InvalidJSON         int = 4002
	CredentialsExist    int = 6001
	CredentialsNotFound int = 6002
	TokenExpired        int = 6003
	UserTokenNotFound   int = 6004
)

Const for custom errors

Variables

This section is empty.

Functions

func CheckParams

func CheckParams(body interface{}, params []string) []string

CheckParams checks if all listed params in params are set in body struc

func CheckParamsStruc

func CheckParamsStruc(body interface{}) []string

CheckParamsStruc checks if all parameters in the structure are set

func CreateMsg

func CreateMsg(status string, dataMsg interface{}, errMsg interface{}) ([]byte, error)

CreateMsg creates an unified JSON structure for writing

func Error

func Error(w http.ResponseWriter, newErr error, code int)

Error outputs error

func Readbody

func Readbody(w http.ResponseWriter, r *http.Request) []byte

Readbody reads body to byte array and if failed return error 500

func WriteMsg

func WriteMsg(w http.ResponseWriter, dataMsg interface{}, errMsg interface{})

WriteMsg writes a unified JSON structure to the client

Types

type ErrorMsg

type ErrorMsg struct {
	Code       int      `json:"code"`
	CustomCode int      `json:"custom_code"`
	ErrorType  string   `json:"type"`
	ErrorParam []string `json:"param"`
	Message    string   `json:"message"`
}

ErrorMsg the message to send to the client if an error occures

func CreateErrorMsg

func CreateErrorMsg(cusCode int, errorParam []string) ErrorMsg

CreateErrorMsg create error message with given cusCode and params

func CreateErrorMsgError

func CreateErrorMsgError(cusCode int, errorParam []string, err error) ErrorMsg

CreateErrorMsgError creates error message with given cusCode, params and error

Jump to

Keyboard shortcuts

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