api

package
v0.0.0-...-1967991 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

View Source
var ErrDuplicated = database.ErrDuplicated

ErrDuplicated is used if an item was already added in a set

View Source
var ErrMedia = errors.New("wrong media content supplied")

ErrMedia indicates a wrong media type

View Source
var ErrNotFound = errors.New("subject resource not found")

ErrNotFound is used if the object of an operation cannot be found

View Source
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

View Source
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.

View Source
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.

View Source
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.

View Source
var ErrWrongCursor = errors.New("wrong page cursor format")

ErrWrongCursor is used to indicate the given pageCursor cannot be interpreted

View Source
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

type MalformedRequestError struct {
	StatusCode int
	Message    string
}

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 PageResult[T any] struct {
	NextPageCursor *string `json:"nextPageCursor"`
	PageData       []T     `json:"pageData"`
}

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

Directories

Path Synopsis
Package route contains the request context.
Package route contains the request context.

Jump to

Keyboard shortcuts

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