api

package
v0.0.0-...-6b2826c Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: AGPL-3.0 Imports: 6 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind(w http.ResponseWriter, r *http.Request, target interface{}) (ok bool)

Bind parses and bind the request body to the given target Bind wil also validates the received data with a validator instance. If the data does not match the target constraints, an ErrorResponse will be sent back. See gopkg.in/go-playground/validator.v9 for more informations about data validation.

func DataResponse

func DataResponse(w http.ResponseWriter, status int, data interface{})

func ErrorResponse

func ErrorResponse(w http.ResponseWriter, status int, code ErrorCode, data interface{})

Types

type Error

type Error struct {
	Code ErrorCode   `json:"code"`
	Data interface{} `json:"data,omitempty"`
}

Error is a JSON encoded error

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode string
const (
	ErrCodeMalformedRequest  ErrorCode = "malformed-request"
	ErrCodeInvalidRequest    ErrorCode = "invalid-request"
	ErrCodeInvalidFieldValue ErrorCode = "invalid-field-value"
	ErrCodeNotFound          ErrorCode = "not-found"
	ErrCodeUnknownError      ErrorCode = "unknown-error"
	ErrCodeUnauthorized      ErrorCode = "unauthorized"
	ErrCodeForbidden         ErrorCode = "forbidden"
)

type Response

type Response struct {
	Error *Error      `json:"error,omitempty"`
	Data  interface{} `json:"data,omitempty"`
}

Response is a JSON encoded HTTP response body

Jump to

Keyboard shortcuts

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