Documentation ¶
Index ¶
- Constants
- Variables
- func Decode(context *qor.Context, result interface{}, res Resourcer) error
- func DecodeToResource(res Resourcer, result interface{}, metaValues *MetaValues, ...) *processor
- func GenCompositePrimaryKey(id interface{}, versionName string) string
- func HandleBelongsTo(context *qor.Context, record reflect.Value, field reflect.Value, ...)
- func HandleManyToMany(context *qor.Context, scope *gorm.Scope, meta *Meta, record interface{}, ...)
- func HandleNormalManyToMany(context *qor.Context, field reflect.Value, metaValue *MetaValue, ...)
- func HandleVersionedManyToMany(context *qor.Context, field reflect.Value, ...)
- func HandleVersioningBelongsTo(context *qor.Context, record reflect.Value, field reflect.Value, ...)
- type CompositePrimaryKeyField
- type CompositePrimaryKeyStruct
- type ConfigureMetaBeforeInitializeInterface
- type ConfigureMetaInterface
- type ConfigureResourceBeforeInitializeInterface
- type ConfigureResourceInterface
- type Meta
- func (meta Meta) GetBaseResource() Resourcer
- func (meta Meta) GetFieldName() string
- func (meta *Meta) GetFormattedValuer() func(interface{}, *qor.Context) interface{}
- func (meta Meta) GetName() string
- func (meta Meta) GetSetter() func(resource interface{}, metaValue *MetaValue, context *qor.Context)
- func (meta Meta) GetValuer() func(interface{}, *qor.Context) interface{}
- func (meta Meta) HasPermission(mode roles.PermissionMode, context *qor.Context) bool
- func (meta *Meta) Initialize() error
- func (meta *Meta) PreInitialize() error
- func (meta *Meta) SetFieldName(name string)
- func (meta *Meta) SetFormattedValuer(fc func(interface{}, *qor.Context) interface{})
- func (meta *Meta) SetPermission(permission *roles.Permission)
- func (meta *Meta) SetSetter(fc func(resource interface{}, metaValue *MetaValue, context *qor.Context))
- func (meta *Meta) SetValuer(fc func(interface{}, *qor.Context) interface{})
- type MetaConfig
- type MetaConfigInterface
- type MetaValue
- type MetaValues
- type Metaor
- type Processor
- type Resource
- func (res *Resource) AddProcessor(processor *Processor)
- func (res *Resource) AddValidator(validator *Validator)
- func (res *Resource) CallDelete(result interface{}, context *qor.Context) error
- func (res *Resource) CallFindMany(result interface{}, context *qor.Context) error
- func (res *Resource) CallFindOne(result interface{}, metaValues *MetaValues, context *qor.Context) error
- func (res *Resource) CallSave(result interface{}, context *qor.Context) error
- func (res *Resource) GetMetas([]string) []Metaor
- func (res *Resource) GetResource() *Resource
- func (res *Resource) HasPermission(mode roles.PermissionMode, context *qor.Context) bool
- func (res *Resource) NewSlice() interface{}
- func (res *Resource) NewStruct() interface{}
- func (res *Resource) SetPrimaryFields(fields ...string) error
- func (res *Resource) ToPrimaryQueryParams(primaryValue string, context *qor.Context) (string, []interface{})
- func (res *Resource) ToPrimaryQueryParamsFromMetaValue(metaValues *MetaValues, context *qor.Context) (string, []interface{})
- type Resourcer
- type Validator
Constants ¶
const CompositePrimaryKeyFieldName = "CompositePrimaryKeyField"
CompositePrimaryKey the string that represents the composite primary key
const CompositePrimaryKeySeparator = "^|^"
CompositePrimaryKeySeparator to separate composite primary keys like ID and version_name
Variables ¶
var ErrProcessorSkipLeft = errors.New("resource: skip left")
ErrProcessorSkipLeft skip left processors error, if returned this error in validation, before callbacks, then qor will stop process following processors
Functions ¶
func DecodeToResource ¶
func DecodeToResource(res Resourcer, result interface{}, metaValues *MetaValues, context *qor.Context) *processor
DecodeToResource decode meta values to resource result
func GenCompositePrimaryKey ¶
GenCompositePrimaryKey generates composite primary key in a specific format
func HandleBelongsTo ¶
func HandleManyToMany ¶
func HandleNormalManyToMany ¶
func HandleNormalManyToMany(context *qor.Context, field reflect.Value, metaValue *MetaValue, fieldHasVersion bool, compositePKeyConvertErr error)
HandleNormalManyToMany not only handle normal many_to_many relationship, it also handled the situation that user set the association to blank
func HandleVersionedManyToMany ¶
func HandleVersionedManyToMany(context *qor.Context, field reflect.Value, compositePKeys []CompositePrimaryKeyStruct)
HandleVersionedManyToMany handle id+version_name composite primary key, query and set the correct result to the "Many" field e.g. Collection.Products This doesn't handle compositePKeys is blank logic, if it is, this function should not be invoked
Types ¶
type CompositePrimaryKeyField ¶
type CompositePrimaryKeyField struct {
CompositePrimaryKey string `gorm:"-"`
}
CompositePrimaryKeyField to embed into the struct that requires composite primary key in select many
type CompositePrimaryKeyStruct ¶
type CompositePrimaryKeyStruct struct { ID uint `json:"id"` VersionName string `json:"version_name"` }
CompositePrimaryKeyStruct container for store id & version combination temporarily
func CollectPrimaryKeys ¶
func CollectPrimaryKeys(metaValueForCompositePrimaryKeys []string) (compositePKeys []CompositePrimaryKeyStruct, compositePKeyConvertErr error)
type ConfigureMetaBeforeInitializeInterface ¶
type ConfigureMetaBeforeInitializeInterface interface {
ConfigureQorMetaBeforeInitialize(Metaor)
}
ConfigureMetaBeforeInitializeInterface if a struct's field's type implemented this interface, it will be called when initializing a meta
type ConfigureMetaInterface ¶
type ConfigureMetaInterface interface {
ConfigureQorMeta(Metaor)
}
ConfigureMetaInterface if a struct's field's type implemented this interface, it will be called after configed
type ConfigureResourceBeforeInitializeInterface ¶
type ConfigureResourceBeforeInitializeInterface interface {
ConfigureQorResourceBeforeInitialize(Resourcer)
}
ConfigureResourceBeforeInitializeInterface if a struct implemented this interface, it will be called before everything when create a resource with the struct
type ConfigureResourceInterface ¶
type ConfigureResourceInterface interface {
ConfigureQorResource(Resourcer)
}
ConfigureResourceInterface if a struct implemented this interface, it will be called after configured by user
type Meta ¶
type Meta struct { Name string FieldName string FieldStruct *gorm.StructField Setter func(resource interface{}, metaValue *MetaValue, context *qor.Context) Valuer func(interface{}, *qor.Context) interface{} FormattedValuer func(interface{}, *qor.Context) interface{} Config MetaConfigInterface BaseResource Resourcer Resource Resourcer Permission *roles.Permission }
Meta meta struct definition
func (Meta) GetBaseResource ¶
GetBaseResource get base resource from meta
func (Meta) GetFieldName ¶
GetFieldName get meta's field name
func (*Meta) GetFormattedValuer ¶
GetFormattedValuer get formatted valuer from meta
func (Meta) HasPermission ¶
HasPermission check has permission or not
func (*Meta) Initialize ¶
Initialize initialize meta, will set valuer, setter if haven't configure it
func (*Meta) PreInitialize ¶
PreInitialize when will be run before initialize, used to fill some basic necessary information
func (*Meta) SetFieldName ¶
SetFieldName set meta's field name
func (*Meta) SetFormattedValuer ¶
SetFormattedValuer set formatted valuer for meta
func (*Meta) SetPermission ¶
func (meta *Meta) SetPermission(permission *roles.Permission)
SetPermission set permission for meta
type MetaConfig ¶
type MetaConfig struct { }
MetaConfig base meta config struct
func (MetaConfig) ConfigureQorMeta ¶
func (MetaConfig) ConfigureQorMeta(Metaor)
ConfigureQorMeta implement the MetaConfigInterface
type MetaConfigInterface ¶
type MetaConfigInterface interface { ConfigureMetaInterface }
MetaConfigInterface meta configuration interface
type MetaValue ¶
type MetaValue struct { Name string Value interface{} Index int Meta Metaor MetaValues *MetaValues }
MetaValue a struct used to hold information when convert inputs from HTTP form, JSON, CSV files and so on to meta values It will includes field name, field value and its configured Meta, if it is a nested resource, will includes nested metas in its MetaValues
type MetaValues ¶
type MetaValues struct {
Values []*MetaValue
}
MetaValues is slice of MetaValue
func ConvertFormToMetaValues ¶
func ConvertFormToMetaValues(request *http.Request, metaors []Metaor, prefix string) (*MetaValues, error)
ConvertFormToMetaValues convert form to meta values
func ConvertJSONToMetaValues ¶
func ConvertJSONToMetaValues(reader io.Reader, metaors []Metaor) (*MetaValues, error)
ConvertJSONToMetaValues convert json to meta values
func (MetaValues) Get ¶
func (mvs MetaValues) Get(name string) *MetaValue
Get get meta value from MetaValues with name
type Metaor ¶
type Metaor interface { GetName() string GetFieldName() string GetSetter() func(resource interface{}, metaValue *MetaValue, context *qor.Context) GetFormattedValuer() func(interface{}, *qor.Context) interface{} GetValuer() func(interface{}, *qor.Context) interface{} GetResource() Resourcer GetMetas() []Metaor SetPermission(*roles.Permission) HasPermission(roles.PermissionMode, *qor.Context) bool }
Metaor interface
type Processor ¶
type Processor struct { Name string Handler func(interface{}, *MetaValues, *qor.Context) error }
Processor processor struct
type Resource ¶
type Resource struct { Name string Value interface{} PrimaryFields []*gorm.StructField FindManyHandler func(interface{}, *qor.Context) error FindOneHandler func(interface{}, *MetaValues, *qor.Context) error SaveHandler func(interface{}, *qor.Context) error DeleteHandler func(interface{}, *qor.Context) error Permission *roles.Permission Validators []*Validator Processors []*Processor // contains filtered or unexported fields }
Resource is a struct that including basic definition of qor resource
func (*Resource) AddProcessor ¶
AddProcessor add processor to resource, it is used to process data before creating, updating, will rollback the change if it return any error
func (*Resource) AddValidator ¶
AddValidator add validator to resource, it will invoked when creating, updating, and will rollback the change if validator return any error
func (*Resource) CallDelete ¶
CallDelete call delete method
func (*Resource) CallFindMany ¶
CallFindMany call find many method
func (*Resource) CallFindOne ¶
func (res *Resource) CallFindOne(result interface{}, metaValues *MetaValues, context *qor.Context) error
CallFindOne call find one method
func (*Resource) GetResource ¶
GetResource return itself to match interface `Resourcer`
func (*Resource) HasPermission ¶
HasPermission check permission of resource
func (*Resource) NewSlice ¶
func (res *Resource) NewSlice() interface{}
NewSlice initialize a slice of struct for the Resource
func (*Resource) NewStruct ¶
func (res *Resource) NewStruct() interface{}
NewStruct initialize a struct for the Resource
func (*Resource) SetPrimaryFields ¶
SetPrimaryFields set primary fields
func (*Resource) ToPrimaryQueryParams ¶
func (res *Resource) ToPrimaryQueryParams(primaryValue string, context *qor.Context) (string, []interface{})
ToPrimaryQueryParams generate query params based on primary key, multiple primary value are linked with a comma
func (*Resource) ToPrimaryQueryParamsFromMetaValue ¶
func (res *Resource) ToPrimaryQueryParamsFromMetaValue(metaValues *MetaValues, context *qor.Context) (string, []interface{})
ToPrimaryQueryParamsFromMetaValue generate query params based on MetaValues
type Resourcer ¶
type Resourcer interface { GetResource() *Resource GetMetas([]string) []Metaor CallFindMany(interface{}, *qor.Context) error CallFindOne(interface{}, *MetaValues, *qor.Context) error CallSave(interface{}, *qor.Context) error CallDelete(interface{}, *qor.Context) error NewSlice() interface{} NewStruct() interface{} }
Resourcer interface