Documentation ¶
Index ¶
- Constants
- func ApiKeyAndSessionAuthMiddleware(cfg config.Config, next http.Handler) (http.Handler, error)
- func ApiKeyAuthMiddleware(cfg config.Config, next http.Handler) (http.Handler, error)
- func ChainMiddleware(handler http.Handler, middlewares ...Middleware) http.Handler
- func GetClientIpAddress(r *http.Request) string
- func IsJSONArray(data []byte) bool
- func ListMiddleware[T ListParamParser](next http.Handler) http.Handler
- func NewRouter(config config.Config, pathPrefix string, routes []Route, ...) (*mux.Router, error)
- func ParseJSONBody(ctx context.Context, body io.Reader, obj interface{}) error
- func ParseJSONBytes(ctx context.Context, body []byte, obj interface{}) error
- func PassthroughAuthMiddleware(cfg config.Config, next http.Handler) (http.Handler, error)
- func SendErrorResponse(res http.ResponseWriter, err error)
- func SendJSONResponse(res http.ResponseWriter, body interface{})
- func ValidateStruct(ctx context.Context, obj interface{}) error
- type AuthInfo
- type AuthMiddlewareFunc
- type BaseService
- type Cursor
- type DuplicateRecordError
- type Env
- type Error
- type ForbiddenError
- type GenericError
- type GetDefaultSortByFunc
- type GetSupportedSortBys
- type InternalError
- type InvalidParameterError
- type InvalidRequestError
- type ListParamParser
- type ListParams
- func (lp *ListParams) DefaultSortBy() string
- func (lp *ListParams) String() string
- func (lp *ListParams) UseCursorPagination() bool
- func (lp *ListParams) WithLimit(limit int)
- func (lp *ListParams) WithNextCursor(nextCursor *Cursor)
- func (lp *ListParams) WithPage(page int)
- func (lp *ListParams) WithPrevCursor(prevCursor *Cursor)
- func (lp *ListParams) WithQuery(query *string)
- func (lp *ListParams) WithSortBy(sortBy string)
- func (lp *ListParams) WithSortOrder(sortOrder SortOrder)
- type Middleware
- type MissingRequiredParameterError
- type RecordNotFoundError
- type Route
- type RouteHandler
- type Service
- type SortOrder
- type TokenExpiredError
- type TooManyRequestsError
- type UnauthorizedError
- type UnknownOriginError
- type WarrantRoute
Constants ¶
View Source
const ( AuthTypeApiKey = "ApiKey" AuthTypeBearer = "Bearer" )
View Source
const ( ErrorDuplicateRecord = "duplicate_record" ErrorForbidden = "forbidden" ErrorInternalError = "internal_error" ErrorInvalidRequest = "invalid_request" ErrorInvalidParameter = "invalid_parameter" ErrorMissingRequiredParameter = "missing_required_parameter" ErrorNotFound = "not_found" ErrorTokenExpired = "token_expired" ErrorTooManyRequests = "too_many_requests" ErrorUnknownOrigin = "unknown_origin" )
View Source
const ( ObjectIdPattern = `^[a-zA-Z0-9_\-\.@\|:]+$` ObjectTypePattern = `^[a-zA-Z0-9_\-]+$` RelationPattern = `^[a-zA-Z0-9_\-]+$` )
View Source
const FirebasePublicKeyUrl = "https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com"
Variables ¶
This section is empty.
Functions ¶
func ApiKeyAndSessionAuthMiddleware ¶ added in v0.13.0
func ApiKeyAuthMiddleware ¶ added in v0.13.0
func ChainMiddleware ¶ added in v0.14.0
func ChainMiddleware(handler http.Handler, middlewares ...Middleware) http.Handler
ChainMiddleware a top-level middleware which applies the given middlewares in order from inner to outer (order of execution)
func GetClientIpAddress ¶
func IsJSONArray ¶ added in v1.0.1
func ListMiddleware ¶ added in v0.14.0
func ListMiddleware[T ListParamParser](next http.Handler) http.Handler
func NewRouter ¶
func NewRouter(config config.Config, pathPrefix string, routes []Route, authMiddleware AuthMiddlewareFunc, routerMiddlewares []Middleware, requestMiddlewares []Middleware) (*mux.Router, error)
func PassthroughAuthMiddleware ¶ added in v0.13.0
func SendErrorResponse ¶
func SendErrorResponse(res http.ResponseWriter, err error)
SendErrorResponse sends a JSON error response with the given error
func SendJSONResponse ¶
func SendJSONResponse(res http.ResponseWriter, body interface{})
SendJSONResponse sends a JSON response with the given body
func ValidateStruct ¶
Types ¶
type AuthMiddlewareFunc ¶ added in v0.9.0
type BaseService ¶
type BaseService struct {
// contains filtered or unexported fields
}
func NewBaseService ¶
func NewBaseService(env Env) BaseService
func (BaseService) Env ¶
func (svc BaseService) Env() Env
type Cursor ¶ added in v0.57.0
type Cursor struct {
// contains filtered or unexported fields
}
func NewCursorFromBase64String ¶ added in v0.57.0
func NewCursorFromBase64String(base64CursorStr string, listParamParser ListParamParser, sortBy string) (*Cursor, error)
func (Cursor) MarshalJSON ¶ added in v0.57.0
func (Cursor) ToBase64String ¶ added in v0.57.0
type DuplicateRecordError ¶
type DuplicateRecordError struct { *GenericError Type string `json:"type"` Key interface{} `json:"key"` }
DuplicateRecordError type
func NewDuplicateRecordError ¶
func NewDuplicateRecordError(recordType string, recordKey interface{}, reason string) *DuplicateRecordError
type ForbiddenError ¶
type ForbiddenError struct {
*GenericError
}
ForbiddenError type
func NewForbiddenError ¶
func NewForbiddenError(msg string) *ForbiddenError
type GenericError ¶ added in v0.59.0
type GenericError struct { Tag string `json:"-"` Code string `json:"code"` Status int `json:"-"` Message string `json:"message"` }
func NewGenericError ¶
func NewGenericError(tag string, code string, status int, msg string) *GenericError
func (*GenericError) Error ¶ added in v0.59.0
func (err *GenericError) Error() string
func (*GenericError) GetStatus ¶ added in v0.59.0
func (err *GenericError) GetStatus() int
func (*GenericError) GetTag ¶ added in v0.59.0
func (err *GenericError) GetTag() string
type GetDefaultSortByFunc ¶ added in v0.14.0
type GetDefaultSortByFunc func() string
type GetSupportedSortBys ¶ added in v0.14.0
type GetSupportedSortBys func() []string
type InternalError ¶
type InternalError struct {
*GenericError
}
InternalError type
func NewInternalError ¶
func NewInternalError(msg string) *InternalError
type InvalidParameterError ¶
type InvalidParameterError struct { *GenericError Parameter string `json:"parameter"` }
InvalidParameterError type
func NewInvalidParameterError ¶
func NewInvalidParameterError(paramName string, msg string) *InvalidParameterError
func (*InvalidParameterError) Error ¶
func (err *InvalidParameterError) Error() string
type InvalidRequestError ¶
type InvalidRequestError struct {
*GenericError
}
InvalidRequestError type
func NewInvalidRequestError ¶
func NewInvalidRequestError(msg string) *InvalidRequestError
type ListParamParser ¶ added in v0.14.0
type ListParams ¶ added in v0.14.0
type ListParams struct { Page int `json:"-"` Limit int `json:"limit,omitempty"` Query *string `json:"q,omitempty"` SortBy string `json:"sortBy,omitempty"` SortOrder SortOrder `json:"sortOrder,omitempty"` PrevCursor *Cursor `json:"prevCursor,omitempty"` NextCursor *Cursor `json:"nextCursor,omitempty"` // contains filtered or unexported fields }
func DefaultListParams ¶ added in v0.40.0
func DefaultListParams(listParamParser ListParamParser) ListParams
func GetListParamsFromContext ¶ added in v0.14.0
func GetListParamsFromContext[T ListParamParser](ctx context.Context) ListParams
func (*ListParams) DefaultSortBy ¶ added in v0.36.0
func (lp *ListParams) DefaultSortBy() string
func (*ListParams) String ¶ added in v0.47.0
func (lp *ListParams) String() string
func (*ListParams) UseCursorPagination ¶ added in v0.14.0
func (lp *ListParams) UseCursorPagination() bool
func (*ListParams) WithLimit ¶ added in v1.8.1
func (lp *ListParams) WithLimit(limit int)
func (*ListParams) WithNextCursor ¶ added in v1.8.1
func (lp *ListParams) WithNextCursor(nextCursor *Cursor)
func (*ListParams) WithPage ¶ added in v1.8.1
func (lp *ListParams) WithPage(page int)
func (*ListParams) WithPrevCursor ¶ added in v1.8.1
func (lp *ListParams) WithPrevCursor(prevCursor *Cursor)
func (*ListParams) WithQuery ¶ added in v1.8.1
func (lp *ListParams) WithQuery(query *string)
func (*ListParams) WithSortBy ¶ added in v1.8.1
func (lp *ListParams) WithSortBy(sortBy string)
func (*ListParams) WithSortOrder ¶ added in v1.8.1
func (lp *ListParams) WithSortOrder(sortOrder SortOrder)
type Middleware ¶ added in v0.14.0
Middleware defines the type of all middleware
type MissingRequiredParameterError ¶
type MissingRequiredParameterError struct { *GenericError Parameter string `json:"parameter"` }
MissingRequiredParameterError type
func NewMissingRequiredParameterError ¶
func NewMissingRequiredParameterError(parameterName string) *MissingRequiredParameterError
type RecordNotFoundError ¶
type RecordNotFoundError struct { *GenericError Type string `json:"type"` Key interface{} `json:"key"` }
RecordNotFoundError type
func NewRecordNotFoundError ¶
func NewRecordNotFoundError(recordType string, recordKey interface{}) *RecordNotFoundError
type Route ¶
type Route interface { GetPattern() string GetMethod() string GetHandler() http.Handler GetOverrideAuthMiddlewareFunc() AuthMiddlewareFunc }
type RouteHandler ¶
type RouteHandler[T Service] struct { // contains filtered or unexported fields }
func NewRouteHandler ¶
func NewRouteHandler[T Service](svc T, handler func(svc T, w http.ResponseWriter, r *http.Request) error) RouteHandler[T]
func (RouteHandler[T]) ServeHTTP ¶
func (rh RouteHandler[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)
type TokenExpiredError ¶
type TokenExpiredError struct {
*GenericError
}
TokenExpiredError type
func NewTokenExpiredError ¶
func NewTokenExpiredError() *TokenExpiredError
type TooManyRequestsError ¶
type TooManyRequestsError struct {
*GenericError
}
TooManyRequestsError type
func NewTooManyRequestsError ¶
func NewTooManyRequestsError() *TooManyRequestsError
type UnauthorizedError ¶
type UnauthorizedError struct {
}UnauthorizedError type
func NewUnauthorizedError ¶
func NewUnauthorizedError(msg string) *UnauthorizedError
type UnknownOriginError ¶
type UnknownOriginError struct {
*GenericError
}
UnknownOriginError type
func NewUnknownOriginError ¶
func NewUnknownOriginError(origin string) *UnknownOriginError
type WarrantRoute ¶ added in v0.13.0
type WarrantRoute struct { Pattern string Method string Handler http.Handler OverrideAuthMiddlewareFunc AuthMiddlewareFunc }
func (WarrantRoute) GetHandler ¶ added in v0.13.0
func (route WarrantRoute) GetHandler() http.Handler
func (WarrantRoute) GetMethod ¶ added in v0.13.0
func (route WarrantRoute) GetMethod() string
func (WarrantRoute) GetOverrideAuthMiddlewareFunc ¶ added in v0.13.0
func (route WarrantRoute) GetOverrideAuthMiddlewareFunc() AuthMiddlewareFunc
func (WarrantRoute) GetPattern ¶ added in v0.13.0
func (route WarrantRoute) GetPattern() string
Click to show internal directories.
Click to hide internal directories.