apihelper

package
v0.0.0-...-d933f62 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package apihelper automate construction of http response

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildChatfuelResponseError

func BuildChatfuelResponseError(err *servicehelper.Error) (int, gin.H)

BuildChatfuelResponseError apply the right status to the http response and build the error JSON object for Chatfuel

func GetBoolQueryParam

func GetBoolQueryParam(c *gin.Context, value *bool, queryParam string, defaultValue bool) bool

GetBoolQueryParam allow to retrieve a boolean query parameter. It takes the gin context as param to build error if queryParam is not formatted correctly and a default value to set value if the parameter is optional and not set.

func GetDateQueryParam

func GetDateQueryParam(c *gin.Context, queryParam string, dateLayout string, defaultValue string) (string, bool)

GetDateQueryParam allow to retrieve a date (as a string) query parameter. It takes the gin context as param to build error if queryParam is not formatted correctly and a default value to set value if the parameter is optional and not set. The dateLayout will define if the date is valid or not

func GetStringQueryParam

func GetStringQueryParam(c *gin.Context, queryParam string, acceptedValues []string, defaultValue string) (string, bool)

GetStringQueryParam allow to retrieve a string query parameter. It takes the gin context as param to build error if queryParam is not formatted correctly and a default value to set value if the parameter is optional and not set. the accepted values list will define if the value is valid or not

Types

type ApiError

type ApiError interface {
}

ApiError interface for all API error messages

type ApiErrors

type ApiErrors struct {
	Errors []ApiError
}

ApiErrors carry the list of errors returned by the API from a request

func BuildRequestError

func BuildRequestError(err error) (int, ApiErrors)

BuildRequestError build a usable JSON error object from an error string generated by the structure validator

func BuildResponseError

func BuildResponseError(err *servicehelper.Error) (status int, apiErrors ApiErrors)

BuildResponseError apply the right status to the http response and build the error JSON object

type Error

type Error struct {
	Param   string `json:"param"`
	Detail  string `json:"detail"`
	Message string `json:"message"`
	// contains filtered or unexported fields
}

Error is the default error message structure the API returns

Jump to

Keyboard shortcuts

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