Documentation ¶
Index ¶
- Variables
- func Decode(context *TM_EC.Context, result interface{}, res Resourcer) error
- func DecodeToResource(res Resourcer, result interface{}, metaValues *MetaValues, ...) *processor
- 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{}, *TM_EC.Context) interface{}
- func (meta Meta) GetName() string
- func (meta Meta) GetSetter() func(resource interface{}, metaValue *MetaValue, context *TM_EC.Context)
- func (meta Meta) GetValuer() func(interface{}, *TM_EC.Context) interface{}
- func (meta Meta) HasPermission(mode roles.PermissionMode, context *TM_EC.Context) bool
- func (meta *Meta) Initialize() error
- func (meta *Meta) PerInitialize() error
- func (meta *Meta) SetFieldName(name string)
- func (meta *Meta) SetFormattedValuer(fc func(interface{}, *TM_EC.Context) interface{})
- func (meta *Meta) SetPermission(permission *roles.Permission)
- func (meta *Meta) SetSetter(fc func(resource interface{}, metaValue *MetaValue, context *TM_EC.Context))
- func (meta *Meta) SetValuer(fc func(interface{}, *TM_EC.Context) interface{})
- type MetaConfig
- type MetaConfigInterface
- type MetaValue
- type MetaValues
- type Metaor
- type Resource
- func (res *Resource) AddProcessor(fc func(interface{}, *MetaValues, *TM_EC.Context) error)
- func (res *Resource) AddValidator(fc func(interface{}, *MetaValues, *TM_EC.Context) error)
- func (res *Resource) CallDelete(result interface{}, context *TM_EC.Context) error
- func (res *Resource) CallFindMany(result interface{}, context *TM_EC.Context) error
- func (res *Resource) CallFindOne(result interface{}, metaValues *MetaValues, context *TM_EC.Context) error
- func (res *Resource) CallSave(result interface{}, context *TM_EC.Context) error
- func (res *Resource) GetMetas([]string) []Metaor
- func (res *Resource) GetResource() *Resource
- func (res *Resource) HasPermission(mode roles.PermissionMode, context *TM_EC.Context) bool
- func (res *Resource) NewSlice() interface{}
- func (res *Resource) NewStruct() interface{}
- func (res *Resource) PrimaryDBName() (name string)
- func (res *Resource) PrimaryField() *gorm.Field
- func (res *Resource) PrimaryFieldName() (name string)
- type Resourcer
Constants ¶
This section is empty.
Variables ¶
var ErrProcessorSkipLeft = errors.New("resource: skip left")
'ErrProcessorSkipLeft' skip left processors error, if returned this error in validation, beform callbacks, then EC will stop process following processers
Functions ¶
func DecodeToResource ¶
func DecodeToResource(res Resourcer, result interface{}, metaValues *MetaValues, context *TM_EC.Context) *processor
'DecodeToResource' decode meta values to resource result
Types ¶
type ConfigureMetaBeforeInitializeInterface ¶
type ConfigureMetaBeforeInitializeInterface interface {
ConfigureECMetaBeforeInitialize(Metaor)
}
'ConfigureMetaBeforeInitializeInterface' if a strust's field's type implemented this interface, it will be called when initializing a meta
type ConfigureMetaInterface ¶
type ConfigureMetaInterface interface {
ConfigureECMeta(Metaor)
}
'ConfigureMetaInterface' if a struct's field's type implemented this interface, it will be called after configed
type ConfigureResourceBeforeInitializeInterface ¶
type ConfigureResourceBeforeInitializeInterface interface {
ConfigureECResourceBeforeInitialize(Resourcer)
}
'ConfigureReouseceBeforeInitializeInterface' if a struct implemented this interface, it will be called before everything when create a resource with the struct
type ConfigureResourceInterface ¶
type ConfigureResourceInterface interface {
ConfigureECResource(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 *TM_EC.Context) Valuer func(interface{}, *TM_EC.Context) interface{} FormattedValuer func(interface{}, *TM_EC.Context) interface{} Config MetaConfigInterface 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 form meta
func (Meta) GetSetter ¶
func (meta Meta) GetSetter() func(resource interface{}, metaValue *MetaValue, context *TM_EC.Context)
'GetSetter' get meta's setter
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) PerInitialize ¶
'PerInitialize' when will be run beform initialize, used to fill some basic necessary information
func (*Meta) SetFieldName ¶
'SetFieldName' set meta's field name
func (*Meta) SetFormattedValuer ¶
'SetFormattedValuer' set formatted valuer form 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) ConfigureECMeta ¶
func (MetaConfig) ConfigureECMeta(Metaor)
'ConfigureECMeta' implement the MetaConfigInterface
type MetaConfigInterface ¶
type MetaConfigInterface interface { ConfigureMetaInterface }
'MetaConfigInterface' meta configuration interface
type MetaValue ¶
type MetaValue struct { Name string Value interface{} Index int MetaValues *MetaValues Meta Metaor // contains filtered or unexported fields }
'MetaValue' a struct used to hold inforamtion when convert inputs from HTTP form, JSON, CSV fields and so on to meta values It will includes file name, field value and it's configured Meta, if it is a nested resource, will includeds nested metas in it's MetaValues
type MetaValues ¶
type MetaValues struct {
Values []*MetaValue
}
'MetaValues' a 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
type Metaor ¶
type Metaor interface { GetName() string GetFieldName() string GetSetter() func(resource interface{}, metaValue *MetaValue, context *TM_EC.Context) GetFormattedValuer() func(interface{}, *TM_EC.Context) interface{} GetValuer() func(interface{}, *TM_EC.Context) interface{} GetResource() Resourcer GetMetas() []Metaor HasPermission(roles.PermissionMode, *TM_EC.Context) bool }
'Metaor' interface
type Resource ¶
type Resource struct { Name string Value interface{} FindManyHandler func(interface{}, *TM_EC.Context) error FindOneHandler func(interface{}, *MetaValues, *TM_EC.Context) error SaveHandler func(interface{}, *TM_EC.Context) error DeleteHandler func(interface{}, *TM_EC.Context) error Permission *roles.Permission Validatiors []func(interface{}, *MetaValues, *TM_EC.Context) error Processors []func(interface{}, *MetaValues, *TM_EC.Context) error // contains filtered or unexported fields }
'Resource' is a struct that including basic definition of EC resource
func (*Resource) AddProcessor ¶
func (res *Resource) AddProcessor(fc func(interface{}, *MetaValues, *TM_EC.Context) error)
'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 ¶
func (res *Resource) AddValidator(fc func(interface{}, *MetaValues, *TM_EC.Context) error)
'AddValidator' add validator to resource, it will invoked when creating, updating, and will rollback the change if validator return any error
func (*Resource) CallDelete ¶
func (*Resource) CallFindMany ¶
func (*Resource) CallFindOne ¶
func (res *Resource) CallFindOne(result interface{}, metaValues *MetaValues, context *TM_EC.Context) error
func (*Resource) GetResource ¶
'GetResource' return isself to match interface 'Resourcer'
func (*Resource) HasPermission ¶
'HasPermission' check permission of resource
func (*Resource) NewSlice ¶
func (res *Resource) NewSlice() interface{}
'NewSlice' initializ a slice of struct for the resource
func (*Resource) NewStruct ¶
func (res *Resource) NewStruct() interface{}
'NewStruct' initialize a struct for the resource
func (*Resource) PrimaryDBName ¶
'PrimaryDBName' return db column name of the resource's primary field
func (*Resource) PrimaryField ¶
'PrimaryField' return gorm's primary field
func (*Resource) PrimaryFieldName ¶
'PrimaryFieldName' return struct column name of the resource's primary field
type Resourcer ¶
type Resourcer interface { GetResource() *Resource GetMetas([]string) []Metaor CallFindMany(interface{}, *TM_EC.Context) error CallFindOne(interface{}, *MetaValues, *TM_EC.Context) error CallSave(interface{}, *TM_EC.Context) error CallDelete(interface{}, *TM_EC.Context) error NewSlice() interface{} NewStruct() interface{} }
'Resourcer' interface