utils

package
v0.0.0-...-92b63b8 Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIncorrectBody error
	ErrIncorrectBody = xerrors.New("Incorrect body")
	// ErrIncorectFormFields error
	ErrIncorectFormFields = xerrors.New("Incorrect form fields")
)

Functions

func Error

func Error(w http.ResponseWriter, response JSONErrorResponse)

Error writes error response

func Ok

func Ok(w http.ResponseWriter, data interface{})

Ok writes error response

func Unauthorized

func Unauthorized(w http.ResponseWriter)

Unauthorized writes unauthorized response

func UnmarshalForm

func UnmarshalForm(w http.ResponseWriter, r *http.Request, to interface{}) error

UnmarshalForm from body and validate it. If error occurs, writes error message to response writer

Types

type APIResponse

type APIResponse interface {
	Check()
}

APIResponse struct to prevent incorrect data in response

type JSONErrorResponse

type JSONErrorResponse struct {
	Status        int    `json:"status"`
	Message       string `json:"message"`
	ClientMessage string `json:"client_message"`
}

JSONErrorResponse presents general structure of error response

func InternalErrorResponse

func InternalErrorResponse(message string) JSONErrorResponse

InternalErrorResponse template with custom message

Jump to

Keyboard shortcuts

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