service

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

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"
	ErrorUnauthorized             = "unauthorized"
	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 ApiKeyAndSessionAuthMiddleware(cfg config.Config, next http.Handler) (http.Handler, error)

func ApiKeyAuthMiddleware added in v0.13.0

func ApiKeyAuthMiddleware(cfg config.Config, next http.Handler) (http.Handler, error)

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 GetClientIpAddress(r *http.Request) string

func IsArray

func IsArray(data []byte) bool

func ListMiddleware added in v0.14.0

func ListMiddleware[T ListParamParser](next http.Handler) http.Handler

func NewGenericError

func NewGenericError(tag string, code string, status int, msg string) *genericError

func NewRouter

func NewRouter(config config.Config, pathPrefix string, routes []Route, authMiddleware AuthMiddlewareFunc, routerMiddlewares []Middleware, requestMiddlewares []Middleware) (*mux.Router, error)

func ParseId added in v0.14.0

func ParseId(val string) (string, error)

func ParseJSONBody

func ParseJSONBody(body io.Reader, obj interface{}) error

func ParseJSONBytes

func ParseJSONBytes(body []byte, obj interface{}) error

func ParseLimit added in v0.14.0

func ParseLimit(val string) (int, error)

func ParsePage added in v0.14.0

func ParsePage(val string) (int, error)

func ParseSortBy added in v0.14.0

func ParseSortBy(val string, listParamParser ListParamParser) (string, error)

func ParseValue added in v0.14.0

func ParseValue(val string, sortBy string, listParamParser ListParamParser) (interface{}, error)

func PassthroughAuthMiddleware added in v0.13.0

func PassthroughAuthMiddleware(cfg config.Config, next http.Handler) (http.Handler, error)

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

func ValidateStruct(obj interface{}) error

Types

type AuthInfo added in v0.7.0

type AuthInfo struct {
	UserId   string
	TenantId string
}

func GetAuthInfoFromRequestContext added in v0.7.0

func GetAuthInfoFromRequestContext(context context.Context) *AuthInfo

GetAuthInfoFromRequestContext returns the AuthInfo object from the given context

type AuthMiddlewareFunc added in v0.9.0

type AuthMiddlewareFunc func(config config.Config, next http.Handler) (http.Handler, error)

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 DuplicateRecordError

type DuplicateRecordError struct {
	Type string      `json:"type"`
	Key  interface{} `json:"key"`
	// contains filtered or unexported fields
}

DuplicateRecordError type

func NewDuplicateRecordError

func NewDuplicateRecordError(recordType string, recordKey interface{}, reason string) *DuplicateRecordError

func (DuplicateRecordError) Error

func (err DuplicateRecordError) Error() string

func (DuplicateRecordError) GetStatus

func (err DuplicateRecordError) GetStatus() int

func (DuplicateRecordError) GetTag

func (err DuplicateRecordError) GetTag() string

type Env

type Env interface {
	DB() database.Database
	EventDB() database.Database
}

type Error

type Error interface {
	GetTag() string
	GetStatus() int
}

type ForbiddenError

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

ForbiddenError type

func NewForbiddenError

func NewForbiddenError(msg string) *ForbiddenError

func (ForbiddenError) Error

func (err ForbiddenError) Error() string

func (ForbiddenError) GetStatus

func (err ForbiddenError) GetStatus() int

func (ForbiddenError) GetTag

func (err ForbiddenError) 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 {
	// contains filtered or unexported fields
}

InternalError type

func NewInternalError

func NewInternalError(msg string) *InternalError

func (InternalError) Error

func (err InternalError) Error() string

func (InternalError) GetStatus

func (err InternalError) GetStatus() int

func (InternalError) GetTag

func (err InternalError) GetTag() string

type InvalidParameterError

type InvalidParameterError struct {
	Parameter string `json:"parameter"`
	// contains filtered or unexported fields
}

InvalidParameterError type

func NewInvalidParameterError

func NewInvalidParameterError(paramName string, msg string) *InvalidParameterError

func (*InvalidParameterError) Error

func (err *InvalidParameterError) Error() string

func (InvalidParameterError) GetStatus

func (err InvalidParameterError) GetStatus() int

func (InvalidParameterError) GetTag

func (err InvalidParameterError) GetTag() string

type InvalidRequestError

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

InvalidRequestError type

func NewInvalidRequestError

func NewInvalidRequestError(msg string) *InvalidRequestError

func (InvalidRequestError) Error

func (err InvalidRequestError) Error() string

func (InvalidRequestError) GetStatus

func (err InvalidRequestError) GetStatus() int

func (InvalidRequestError) GetTag

func (err InvalidRequestError) GetTag() string

type ListParamParser added in v0.14.0

type ListParamParser interface {
	GetDefaultSortBy() string
	GetSupportedSortBys() []string
	ParseValue(val string, sortBy string) (interface{}, error)
}

type ListParams added in v0.14.0

type ListParams struct {
	Page        int
	Limit       int
	Query       *string
	SortBy      string
	SortOrder   SortOrder
	AfterId     *string
	BeforeId    *string
	AfterValue  interface{}
	BeforeValue interface{}
	// 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

type Middleware added in v0.14.0

type Middleware func(http.Handler) http.Handler

Middleware defines the type of all middleware

type MissingRequiredParameterError

type MissingRequiredParameterError struct {
	Parameter string `json:"parameter"`
	// contains filtered or unexported fields
}

MissingRequiredParameterError type

func NewMissingRequiredParameterError

func NewMissingRequiredParameterError(parameterName string) *MissingRequiredParameterError

func (MissingRequiredParameterError) Error

func (err MissingRequiredParameterError) Error() string

func (MissingRequiredParameterError) GetStatus

func (err MissingRequiredParameterError) GetStatus() int

func (MissingRequiredParameterError) GetTag

func (err MissingRequiredParameterError) GetTag() string

type RecordNotFoundError

type RecordNotFoundError struct {
	Type string      `json:"type"`
	Key  interface{} `json:"key"`
	// contains filtered or unexported fields
}

RecordNotFoundError type

func NewRecordNotFoundError

func NewRecordNotFoundError(recordType string, recordKey interface{}) *RecordNotFoundError

func (RecordNotFoundError) Error

func (err RecordNotFoundError) Error() string

func (RecordNotFoundError) GetStatus

func (err RecordNotFoundError) GetStatus() int

func (RecordNotFoundError) GetTag

func (err RecordNotFoundError) GetTag() string

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 Service

type Service interface {
	Routes() ([]Route, error)
	Env() Env
}

type SortOrder added in v0.14.0

type SortOrder int
const (
	SortOrderAsc  SortOrder = iota
	SortOrderDesc SortOrder = iota
)

func ParseSortOrder added in v0.14.0

func ParseSortOrder(val string) (SortOrder, error)

func (SortOrder) String added in v0.14.0

func (so SortOrder) String() string

type TokenExpiredError

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

TokenExpiredError type

func NewTokenExpiredError

func NewTokenExpiredError() *TokenExpiredError

func (TokenExpiredError) Error

func (err TokenExpiredError) Error() string

func (TokenExpiredError) GetStatus

func (err TokenExpiredError) GetStatus() int

func (TokenExpiredError) GetTag

func (err TokenExpiredError) GetTag() string

type TooManyRequestsError

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

TooManyRequestsError type

func NewTooManyRequestsError

func NewTooManyRequestsError() *TooManyRequestsError

func (TooManyRequestsError) Error

func (err TooManyRequestsError) Error() string

func (TooManyRequestsError) GetStatus

func (err TooManyRequestsError) GetStatus() int

func (TooManyRequestsError) GetTag

func (err TooManyRequestsError) GetTag() string

type UnauthorizedError

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

UnauthorizedError type

func NewUnauthorizedError

func NewUnauthorizedError(msg string) *UnauthorizedError

func (UnauthorizedError) Error

func (err UnauthorizedError) Error() string

func (UnauthorizedError) GetStatus

func (err UnauthorizedError) GetStatus() int

func (UnauthorizedError) GetTag

func (err UnauthorizedError) GetTag() string

type UnknownOriginError

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

UnknownOriginError type

func NewUnknownOriginError

func NewUnknownOriginError(origin string) *UnknownOriginError

func (UnknownOriginError) Error

func (err UnknownOriginError) Error() string

func (UnknownOriginError) GetStatus

func (err UnknownOriginError) GetStatus() int

func (UnknownOriginError) GetTag

func (err UnknownOriginError) GetTag() string

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

Jump to

Keyboard shortcuts

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