utils

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON(r *http.Request, v interface{}) ([]byte, error)

DecodeJSON decodes JSON request body into the provided struct

func ErrorHandler added in v1.2.0

func ErrorHandler(h ErrorReturningHandler) http.HandlerFunc

func RespondJSON

func RespondJSON(w http.ResponseWriter, r *http.Request, status int, payload interface{}) error

RespondJSON sends a JSON response with proper headers

func ValidateContentType

func ValidateContentType(r *http.Request, contentType string) bool

ValidateContentType checks if the request has the required content type

Types

type ApiError added in v1.2.0

type ApiError struct {
	// contains filtered or unexported fields
}

func BadRequestErr added in v1.2.0

func BadRequestErr(err error) *ApiError

func InternalServerErr added in v1.2.0

func InternalServerErr(err error) *ApiError

func NewApiError added in v1.2.0

func NewApiError(err error, code int) *ApiError

func UnauthorizedErr added in v1.2.0

func UnauthorizedErr(err error) *ApiError

func (*ApiError) Error added in v1.2.0

func (e *ApiError) Error() string

type ErrorResponse added in v1.2.0

type ErrorResponse struct {
	Error string `json:"error"`
	Code  int    `json:"code"`
}

type ErrorReturningHandler added in v1.2.0

type ErrorReturningHandler func(w http.ResponseWriter, r *http.Request) *ApiError

Directories

Path Synopsis
optional module
set module

Jump to

Keyboard shortcuts

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