service

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 27 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 IsJSONArray added in v1.0.1

func IsJSONArray(data []byte) bool

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 ParseJSONBody

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

func ParseJSONBytes

func ParseJSONBytes(ctx context.Context, body []byte, obj 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(ctx context.Context, 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(ctx context.Context) (*AuthInfo, error)

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 Cursor added in v0.57.0

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

func NewCursor added in v0.57.0

func NewCursor(id string, value interface{}) *Cursor

func NewCursorFromBase64String added in v0.57.0

func NewCursorFromBase64String(base64CursorStr string, listParamParser ListParamParser, sortBy string) (*Cursor, error)

func (Cursor) ID added in v0.57.0

func (cursor Cursor) ID() string

func (Cursor) MarshalJSON added in v0.57.0

func (cursor Cursor) MarshalJSON() ([]byte, error)

func (Cursor) String added in v0.57.0

func (cursor Cursor) String() string

func (Cursor) ToBase64String added in v0.57.0

func (cursor Cursor) ToBase64String() (string, error)

func (Cursor) Value added in v0.57.0

func (cursor Cursor) Value() interface{}

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 Env

type Env interface {
	DB() database.Database
}

type Error

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

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 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       `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

type Middleware func(http.Handler) http.Handler

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 Service

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

type SortOrder added in v0.14.0

type SortOrder string
const (
	SortOrderAsc  SortOrder = "ASC"
	SortOrderDesc SortOrder = "DESC"
)

func (SortOrder) String added in v0.14.0

func (so SortOrder) String() string

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 {
	*GenericError
}

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

Jump to

Keyboard shortcuts

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