app

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorJSONHandler

func ErrorJSONHandler(message *ErrorAPIResponse) func(w http.ResponseWriter, r *http.Request)

ErrorJSONHandler handle error for Gorilla mux router

func FilterResponseJSONData

func FilterResponseJSONData(data []byte, refFields, fields []string) []byte

FilterResponseJSONData filters fields from JSON

func HandleJSONResponse

func HandleJSONResponse(w http.ResponseWriter, data Response, refFields []string, filters ...string)

HandleJSONResponse handle JSON API response

Types

type Error

type Error struct {
	Message     string      `json:"message"`
	Details     interface{} `json:"details"`
	Description string      `json:"description"`
	Code        string      `json:"code"`
}

Error is a generic Application error struct

func FormatAppError added in v0.0.3

func FormatAppError(msg, code, desc string, details interface{}) *Error

FormatAppError generates a new Error struct from params

func (Error) Error added in v0.5.2

func (e Error) Error() string

type ErrorAPIResponse added in v0.0.5

type ErrorAPIResponse struct {
	*Error
	HTTPResponse *HTTPResponse `json:"http_response"`
}

ErrorAPIResponse is an Error response struct

func FormatAPIError added in v0.0.5

func FormatAPIError(err *Error, httpCode int) *ErrorAPIResponse

FormatAPIError is a helper function to generate error response

func (*ErrorAPIResponse) GetHTTPCode added in v0.0.5

func (ear *ErrorAPIResponse) GetHTTPCode() int

GetHTTPCode return HTTP code

type HTTPResponse added in v0.0.5

type HTTPResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

HTTPResponse is a light HTTP response struct

type Response

type Response interface {
	GetHTTPCode() int
}

Response if an interface to get HTTP code

type SuccessAPIResponse added in v0.0.5

type SuccessAPIResponse struct {
	Data         interface{}   `json:"data"`
	HTTPResponse *HTTPResponse `json:"http_response"`
}

SuccessAPIResponse is a Success response struct

func FormatAPISuccess added in v0.0.5

func FormatAPISuccess(data interface{}, httpCode int) *SuccessAPIResponse

FormatAPISuccess is a helper function to generate success response

func (*SuccessAPIResponse) GetHTTPCode added in v0.0.5

func (sar *SuccessAPIResponse) GetHTTPCode() int

GetHTTPCode return HTTP code

Jump to

Keyboard shortcuts

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