Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDBContextKey ¶
func SetDBContextKey(_dbContextKey string)
SetDBContextKey for users and roles
Types ¶
type CrudOptions ¶
type CrudOptions struct {
// IDParameterName is the name of the GET parameter which is used
// for getting and deleting documents
IDParameterName string
// Database is the name of the database which contains the documents to be modified (will be passed to all service-calls)
Database string
// ListEndpoint is the http-endpoint-name for list queries
// If == nil there will be no list-enpoint
ListEndpoint *string
ListPreprocess func(context.Context) error
ListPermission *uauthPermissions.Permission
ListOthersPermission *uauthPermissions.Permission
ListRequiredGet params.R
ListOptionalGet params.R
// GetEndpoint is the http-endpoint-name for get queries
// If == nil there will be no get-enpoint
GetEndpoint *string
GetPreprocess func(context.Context) error
GetPermission *uauthPermissions.Permission
GetOthersPermission *uauthPermissions.Permission
GetRequiredGet params.R
GetOptionalGet params.R
// CreateEndpoint is the http-endpoint-name for create queries
// If == nil there will be no create-enpoint
CreateEndpoint *string
CreatePreprocess func(context.Context) error
CreatePermission *uauthPermissions.Permission
CreateOthersPermission *uauthPermissions.Permission
CreateRequiredGet params.R
CreateOptionalGet params.R
// UpdateEndpoint is the http-endpoint-name for update queries
// If == nil there will be no update-enpoint
UpdateEndpoint *string
UpdatePreprocess func(context.Context) error
UpdatePermission *uauthPermissions.Permission
UpdateOthersPermission *uauthPermissions.Permission
UpdateRequiredGet params.R
UpdateOptionalGet params.R
// DeleteEndpoint is the http-endpoint-name for delete queries
// If == nil there will be no delete-enpoint
DeleteEndpoint *string
DeletePreprocess func(context.Context) error
DeletePermission *uauthPermissions.Permission
DeleteOthersPermission *uauthPermissions.Permission
DeleteRequiredGet params.R
DeleteOptionalGet params.R
// ModelService will be called upon for all database interactions
ModelService ModelService
// Model will be used to parse and validate models given to create/update handlers
Model WithID
}
func (CrudOptions) CreateEndpoints ¶
func (o CrudOptions) CreateEndpoints()
CreateEndpoints adds all handlers configured in CrudOptions using the uhttp-framework
type ModelService ¶
type ModelService interface {
// CopyAndInit allows us to clone a service
CopyAndInit(db *mongo.Client, database string) ModelService
// Validate should validate the model which is created/updated
// - called from the createHandler, before it calls service.Create
// - called from the updateHandler, before it calls service.Update
Validate(interface{}) bool
// Get retrieves a document by its ID (typically a string or ObjectID etc.)
// If limitToUser is true the service should only return documents which belong to the user
Get(ID string, user *uauthModels.User, limitToUser bool, ctx context.Context) (interface{}, error)
// List retrieves all documents which this user has access to
// If limitToUser is true the service should only return documents which belong to the user
// ctx will contain the request-context. This way we can pass on filters from the reuqest
// into the service
List(user *uauthModels.User, limitToUser bool, ctx context.Context) (interface{}, error)
// Create creates a document in the database and returns the new document
// If permissions are implemented, the service should make this created document belong to the
// user passed into this method
Create(obj interface{}, user *uauthModels.User, ctx context.Context) (interface{}, error)
// Update updates a document. It is up to the implementer to get the ID-property, etc.
// It returns the updated document
// If limitToUser is true the service should check if this user is allowed to modify this document
Update(obj interface{}, user *uauthModels.User, limitToUser bool, ctx context.Context) (interface{}, error)
// Delete deletes a document by its ID (typically a string or ObjectID etc.)
// If limitToUser is true the service should check if this user is allowed to delete this document
Delete(ID string, user *uauthModels.User, limitToUser bool, ctx context.Context) error
}
ModelService is an interface which all CRUD-http-handlers will use
Click to show internal directories.
Click to hide internal directories.