dsl

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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).

func (*Auth) Prepare

func (auth *Auth) Prepare()

Prepare installs default values in the auth.

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

type ConnectionFields struct {
	Host     string
	Port     uint16
	Username string
	Password string
}

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.

func (*Global) Prepare

func (global *Global) Prepare()

Prepare installs the default values in the global settings.

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
)

type Resources

type Resources map[string]Resource

Resources belong to a mapping.

type Settings

type Settings struct {
	Debug      bool
	Connection Connection
	Global     Global              `validate:"dive"`
	Auth       Auth                `validate:"dive"`
	Resources  map[string]Resource `validate:"dive,keys,mdb-name,endkeys,dive"`
}

Settings stands for the main entry point of our DSL.

func (*Settings) Prepare

func (settings *Settings) Prepare() *Settings

Prepare prepares the default values of all the members.

type TableRef

type TableRef struct {
	Db         string `validate:"mdb-name"`
	Collection string `validate:"mdb-name"`
}

TableRef stands for the db and name of a given table (e.g. "global" and "auth").

Jump to

Keyboard shortcuts

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