Documentation ¶
Index ¶
- Variables
- func HandleErrorsResponse(err error, w http.ResponseWriter, defaultSuccessStatus int, ...)
- func HandlePutResult(result any, err error, w http.ResponseWriter, logger logrus.FieldLogger)
- func LimitBodySize(maxBytes int64) route.Middleware
- func SendJson(writer http.ResponseWriter, body any, successStatus int, ...)
- type MalformedRequestError
- func ParseAllRequestVariables[T any](r *http.Request, params httprouter.Params, paramsStruct *T, ...) (*T, *MalformedRequestError)
- func ParseAndValidateBody[T any](request *http.Request, bodyStruct *T, logger logrus.FieldLogger) (*T, *MalformedRequestError)
- func ParseRequestVariables[T any](params httprouter.Params, paramsStruct *T, logger logrus.FieldLogger) (*T, *MalformedRequestError)
- func ParseVariablesAndBody[V any, B any](r *http.Request, params httprouter.Params, varsStruct *V, bodyStruct *B, ...) (*V, *B, *MalformedRequestError)
- func ValidateParsedStruct[T any](parsedStruct *T, logger logrus.FieldLogger) *MalformedRequestError
- type PageResult
- type PaginationInfo
- type Router
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyTaken = errors.New("the unique data you are trying to get it's already taken")
ErrAlreadyTaken is used if a user tries to get something it's someone else's and must be unique
var ErrDuplicated = database.ErrDuplicated
ErrDuplicated is used if an item was already added in a set
var ErrMedia = errors.New("wrong media content supplied")
ErrMedia indicates a wrong media type
var ErrNotFound = errors.New("subject resource not found")
ErrNotFound is used if the object of an operation cannot be found
var ErrOthersData = errors.New("you are only allowed to operate on data of yours")
ErrOthersData indicates the current operation can only operate on data owned by the user performing it
var ErrSelfOperation = errors.New("operation not allowed on yourself")
ErrSelfOperation is used to indicate a user is performing an operation both as subject and object, and that is not possible in this circumstance.
var ErrThirdParty = errors.New("a third-party service required to fulfill the request is not available")
ErrThirdParty indicates the current operation cannot be fulfilled because, even if this server works as expected, it needs a third-party service which is currently not working.
var ErrUserBanned = errors.New("forbidden because of user ban")
ErrUserBanned is used in case the current user has no permission to read the requested information because he is banned by the owner of that data.
var ErrWrongCursor = errors.New("wrong page cursor format")
ErrWrongCursor is used to indicate the given pageCursor cannot be interpreted
var ErrWrongUUID = errors.New("wrong UUID supplied")
ErrWrongUUID is used to indicate the given ID cannot be interpreted as a UUID
Functions ¶
func HandleErrorsResponse ¶
func HandleErrorsResponse(err error, w http.ResponseWriter, defaultSuccessStatus int, logger logrus.FieldLogger)
func HandlePutResult ¶
func HandlePutResult(result any, err error, w http.ResponseWriter, logger logrus.FieldLogger)
HandlePutResult handles the error ErrDuplicated in an idempotent PUT operation.
func LimitBodySize ¶
func LimitBodySize(maxBytes int64) route.Middleware
LimitBodySize prevents spending too much time responding to too long (potentially bad) requests
func SendJson ¶
func SendJson(writer http.ResponseWriter, body any, successStatus int, logger logrus.FieldLogger)
Types ¶
type MalformedRequestError ¶
func ParseAllRequestVariables ¶
func ParseAllRequestVariables[T any](r *http.Request, params httprouter.Params, paramsStruct *T, logger logrus.FieldLogger) (*T, *MalformedRequestError)
func ParseAndValidateBody ¶
func ParseAndValidateBody[T any](request *http.Request, bodyStruct *T, logger logrus.FieldLogger) (*T, *MalformedRequestError)
func ParseRequestVariables ¶
func ParseRequestVariables[T any](params httprouter.Params, paramsStruct *T, logger logrus.FieldLogger) (*T, *MalformedRequestError)
func ParseVariablesAndBody ¶
func ParseVariablesAndBody[V any, B any](r *http.Request, params httprouter.Params, varsStruct *V, bodyStruct *B, logger logrus.FieldLogger) (*V, *B, *MalformedRequestError)
func ValidateParsedStruct ¶
func ValidateParsedStruct[T any](parsedStruct *T, logger logrus.FieldLogger) *MalformedRequestError
func (*MalformedRequestError) Error ¶
func (err *MalformedRequestError) Error() string
type PageResult ¶
type PaginationInfo ¶
type PaginationInfo struct {
PageCursorOrEmpty string `json:"pageCursor" validate:"omitempty,max=80,base64url"`
}
type Router ¶
type Router interface { // Handler returns an HTTP handler for APIs provided in this package Handler() http.Handler // Register a new route Register(route route.Route) error // RegisterAll controllers in the app, all at once, being library agnostic, as always RegisterAll(controllers []route.Controller) error // RegisterStatic handles requests for static files RegisterStatic(localPath string, httpPath string) // Close terminates any resource used in the package Close() error }
Router is the package API interface representing an API handler builder
func NewRouter ¶
func NewRouter(authMiddleware route.AuthMiddleware, middlewares []route.Middleware, logger logrus.FieldLogger) Router
NewRouter returns a new Router instance