hook

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cargo

type Cargo struct {
	Payload interface{}
}

Cargo is payload between hookpoints

type Data

type Data struct {
	// Ms is the slice of IModels
	Ms []mdl.IModel
	// DB is the DB handle
	DB *gorm.DB
	// Cargo between Before and After hookpoints (not used in AfterRead since there is before read hookpoint.)
	Cargo *Cargo
	// Role of this user in relation to this data, only available during read
	Roles []userrole.UserRole
}

Data is the data send to batch model hookpoints

type EndPoint

type EndPoint struct {
	// TypeString
	TypeString string `json:"typeString"`

	URL         string           `json:"url"`
	Op          rest.Op          `json:"op"`
	Cardinality rest.Cardinality `json:"cardinality"`

	// URL parameters
	URLParams map[urlparam.Param]interface{} `json:"urlParams"`

	// Who is operating this CRUPD right now
	Who mdlutil.UserIDFetchable `json:"who"`
}

Endpoint information

type IAfter

type IAfter interface {
	After(data *Data, ep *EndPoint) *webrender.RetError
}

IAfter supports method to be called after data is after all operations except delete

type IAfterTransact

type IAfterTransact interface {
	AfterTransact(data *Data, ep *EndPoint)
}

IAfterTransact is the method to be called after data is after the entire database transaction is done. No error is returned because database transaction is already committed.

type IBefore

type IBefore interface {
	Before(data *Data, ep *EndPoint) *webrender.RetError
}

IBefore supports method to be called before data is fetched for all operations except Read

type IBeforeApply

type IBeforeApply interface {
	BeforeApply(data *Data, ep *EndPoint) *webrender.RetError
}

IBeforeApply before patching operation occurred. Only called for Patch. This comes before patch is applied. Before "Before"

type ICache added in v0.10.1

type ICache interface {
	// Get data by info. If exists, can be implemented to avoid hitting the database in read endpoints
	// if boolean is false, it means it is not handled and database query will be proceeded
	// unless another hook which implemented this takes over.
	// A maximum of one handler is used at a time, the hook writer has to make sure they are mutally exclusive
	// if found is false, it means it was not found in the database (only used for query with cardinality of 1)
	GetFromCache(ep *EndPoint) (handled bool, found bool, ms []mdl.IModel, roles []userrole.UserRole, no *int, retErr *webrender.RetError)

	// A maximum of one handler is used at a time, the hook writer has to make sure they are mutally exclusive
	// if found is false, it means it was not found in the database and the negative result is to be cached.
	AddToCache(ep *EndPoint, found bool, ms []mdl.IModel, roles []userrole.UserRole, no *int) (handled bool, retErr *webrender.RetError)
}

ICache supports cache.

type IHook

type IHook interface {
	// Init data for this REST operation
	// (TODO: But role doesn't exists yet before read, and I can't seem to find any use for any of these data)
	Init(data *InitData, args ...interface{})
}

type IRender

type IRender interface {
	Render(c *gin.Context, data *Data, ep *EndPoint, total *int) bool
}

IRender is for formatting IModel with a custom function basically do your own custom output If return false, use the default JSON output A maximum of one handler is used at a time, the hook writer has to make sure they are mutally exclusive

type IRoleSorter added in v0.10.7

type IRoleSorter interface {

	// Permit is for any other hook (read, update, patch, delete)
	// if user is permitted, return a RetError
	PermitOnCreate(mapperType mappertype.MapperType, data *Data, ep *EndPoint) *webrender.RetError

	// Returns permitted role as a map key.
	// If a role is not in it, it means it's denied.
	// If a role is in it but the map value is not nil, it means it is rejected with a custom error.
	// If error occurs while trying to generate the map, returns an error
	Permitted(mapperType mappertype.MapperType, ep *EndPoint) (map[userrole.UserRole]*webrender.RetError, error)
}

type InitData

type InitData struct {
	// Role of this user in relation to this data, only available during read
	// TODO: To be removed
	Roles []userrole.UserRole

	// Info is endpoint information
	Ep *EndPoint
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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