Documentation ¶
Index ¶
- Constants
- func ModelType[T any]() interface{}
- func ValidateVerbs(fl validator.FieldLevel) bool
- type Auth
- type Connection
- type ConnectionFields
- type Global
- type Index
- type ItemMethod
- type ItemMethodHandler
- type MethodType
- type ModelTypeFunction
- type Resource
- type ResourceMethod
- type ResourceMethodHandler
- type ResourceType
- type ResourceVerb
- type Resources
- type Settings
- type TableRef
Constants ¶
const DefaultListMaxSize int64 = 20
Variables ¶
This section is empty.
Functions ¶
func ModelType ¶
func ModelType[T any]() interface{}
ModelType can be used to instantiate any struct. It should be used in the DSL of a resource.
func ValidateVerbs ¶
func ValidateVerbs(fl validator.FieldLevel) bool
ValidateVerbs does a custom validation function on the verbs: If the resource is of list type ListResource then allow all the verbs. Otherwise, allow all but the List verb.
Types ¶
type Auth ¶
type Auth struct {
TableRef
}
Auth is a table reference used for authentication purposes (API Keys).
type Connection ¶
type Connection struct { Url string Args ConnectionFields Timeout int64 // contains filtered or unexported fields }
Connection stands for the connection attempt, which might specify arguments (see: Args field) or might specify a direct URL (perhaps not mongodb://).
func (*Connection) Client ¶
func (c *Connection) Client() *mongo.Client
Client returns the underlying client, if any.
func (*Connection) Connect ¶
func (c *Connection) Connect() (*mongo.Client, error)
Connect attempts a new connection.
func (*Connection) Disconnect ¶
func (c *Connection) Disconnect() error
Disconnect disconnects the current connection, if any.
func (*Connection) Prepare ¶
func (c *Connection) Prepare()
Prepare installs default values in the connection.
type ConnectionFields ¶
ConnectionFields stands for the arguments needed to make a connection. This is just an alternative of arguments for the connection.
type Global ¶
type Global struct {
ListMaxResults int64
}
Global stands for settings for ALL the resources.
type Index ¶
type Index struct { Unique bool Fields []string `validate:"required,dive,required,mdb-index-entry"` }
Index is the description of a MongoDB index.
type ItemMethod ¶
type ItemMethod struct { Type MethodType `validate:"min=0,max=1"` Handler ItemMethodHandler `validate:"required"` }
ItemMethod stands for a method entry which involves a handler and also telling whether it is a view or an operator. This handler is related to a particular item.
type ItemMethodHandler ¶
type ItemMethodHandler func( context echo.Context, client *mongo.Client, resource, method string, collection *mongo.Collection, validatorMaker func() *validator.Validate, filter bson.M, id primitive.ObjectID, ) error
ItemMethodHandler is a method that handles a specific collection and some filtering data, now related to an item in particular.
type MethodType ¶
type MethodType uint
MethodType is the method operation type (implies the method to use).
const ( View MethodType = iota Operation )
type ModelTypeFunction ¶
type ModelTypeFunction func() interface{}
ModelTypeFunction is a function that returns the model to use.
type Resource ¶
type Resource struct { TableRef `validate:"dive"` Type ResourceType `validate:"min=0,max=1"` Sort bson.D Filter bson.M ItemProjection bson.M `validate:"excluded_if=Type 1"` Projection bson.M ItemMethods map[string]ItemMethod `validate:"excluded_if=Type 1,dive,keys,method-name,endkeys,dive"` Methods map[string]ResourceMethod `validate:"dive,keys,method-name,endkeys,dive"` ModelType ModelTypeFunction `validate:"required"` Verbs []ResourceVerb `validate:"dive,verbs"` SoftDelete bool ListMaxResults uint Indexes map[string]Index `validate:"dive,keys,mdb-name,endkeys"` }
Resource stands for the rules regarding a particular resource (in the end, a collection).
type ResourceMethod ¶
type ResourceMethod struct { Type MethodType `validate:"min=0,max=1"` Handler ResourceMethodHandler `validate:"required"` }
ResourceMethod stands for a method entry which involves a handler and also telling whether it is a view or an operator. This handler is related to the whole list.
type ResourceMethodHandler ¶
type ResourceMethodHandler func( context echo.Context, client *mongo.Client, resource, method string, collection *mongo.Collection, validatorMaker func() *validator.Validate, filter bson.M, ) error
ResourceMethodHandler is a method that handles a specific collection and some filtering data, related to the whole collection. For simple resources, this will imply the only record existing in it.
type ResourceType ¶
type ResourceType uint
ResourceType is an enumeration to tell whether it is a list resource (standard) or one with just one record.
const ( ListResource ResourceType = iota SimpleResource )
type ResourceVerb ¶
type ResourceVerb uint
ResourceVerb is an enumeration to tell the allowed verbs into these resources: list, create, read, replace, update, delete.
const ( ListVerb ResourceVerb = iota CreateVerb ReadVerb ReplaceVerb UpdateVerb DeleteVerb LastVerb = DeleteVerb )