adsa-cms: Index | Files

package resource

import ""


Package Files

crud.go meta.go meta_value.go processor.go resource.go schema.go


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

func Decode Uses

func Decode(context *qor.Context, result interface{}, res Resourcer) error

Decode decode context to result according to resource definition

func DecodeToResource Uses

func DecodeToResource(res Resourcer, result interface{}, metaValues *MetaValues, context *qor.Context) *processor

DecodeToResource decode meta values to resource result

type ConfigureMetaBeforeInitializeInterface Uses

type ConfigureMetaBeforeInitializeInterface interface {

ConfigureMetaBeforeInitializeInterface if a struct's field's type implemented this interface, it will be called when initializing a meta

type ConfigureMetaInterface Uses

type ConfigureMetaInterface interface {

ConfigureMetaInterface if a struct's field's type implemented this interface, it will be called after configed

type ConfigureResourceBeforeInitializeInterface Uses

type ConfigureResourceBeforeInitializeInterface interface {

ConfigureResourceBeforeInitializeInterface if a struct implemented this interface, it will be called before everything when create a resource with the struct

type ConfigureResourceInterface Uses

type ConfigureResourceInterface interface {

ConfigureResourceInterface if a struct implemented this interface, it will be called after configured by user

type Meta Uses

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
    Resource        Resourcer
    Permission      *roles.Permission

Meta meta struct definition

func (Meta) GetBaseResource Uses

func (meta Meta) GetBaseResource() Resourcer

GetBaseResource get base resource from meta

func (Meta) GetFieldName Uses

func (meta Meta) GetFieldName() string

GetFieldName get meta's field name

func (*Meta) GetFormattedValuer Uses

func (meta *Meta) GetFormattedValuer() func(interface{}, *qor.Context) interface{}

GetFormattedValuer get formatted valuer from meta

func (Meta) GetName Uses

func (meta Meta) GetName() string

GetName get meta's name

func (Meta) GetSetter Uses

func (meta Meta) GetSetter() func(resource interface{}, metaValue *MetaValue, context *qor.Context)

GetSetter get setter from meta

func (Meta) GetValuer Uses

func (meta Meta) GetValuer() func(interface{}, *qor.Context) interface{}

GetValuer get valuer from meta

func (Meta) HasPermission Uses

func (meta Meta) HasPermission(mode roles.PermissionMode, context *qor.Context) bool

HasPermission check has permission or not

func (*Meta) Initialize Uses

func (meta *Meta) Initialize() error

Initialize initialize meta, will set valuer, setter if haven't configure it

func (*Meta) PreInitialize Uses

func (meta *Meta) PreInitialize() error

PreInitialize when will be run before initialize, used to fill some basic necessary information

func (*Meta) SetFieldName Uses

func (meta *Meta) SetFieldName(name string)

SetFieldName set meta's field name

func (*Meta) SetFormattedValuer Uses

func (meta *Meta) SetFormattedValuer(fc func(interface{}, *qor.Context) interface{})

SetFormattedValuer set formatted valuer for meta

func (*Meta) SetPermission Uses

func (meta *Meta) SetPermission(permission *roles.Permission)

SetPermission set permission for meta

func (*Meta) SetSetter Uses

func (meta *Meta) SetSetter(fc func(resource interface{}, metaValue *MetaValue, context *qor.Context))

SetSetter set setter to meta

func (*Meta) SetValuer Uses

func (meta *Meta) SetValuer(fc func(interface{}, *qor.Context) interface{})

SetValuer set valuer for meta

type MetaConfig Uses

type MetaConfig struct {

MetaConfig base meta config struct

func (MetaConfig) ConfigureQorMeta Uses

func (MetaConfig) ConfigureQorMeta(Metaor)

ConfigureQorMeta implement the MetaConfigInterface

type MetaConfigInterface Uses

type MetaConfigInterface interface {

MetaConfigInterface meta configuration interface

type MetaValue Uses

type MetaValue struct {
    Name       string
    Value      interface{}
    MetaValues *MetaValues
    Meta       Metaor
    // contains filtered or unexported fields

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 Uses

type MetaValues struct {
    Values []*MetaValue

MetaValues is slice of MetaValue

func ConvertFormToMetaValues Uses

func ConvertFormToMetaValues(request *http.Request, metaors []Metaor, prefix string) (*MetaValues, error)

ConvertFormToMetaValues convert form to meta values

func ConvertJSONToMetaValues Uses

func ConvertJSONToMetaValues(reader io.Reader, metaors []Metaor) (*MetaValues, error)

ConvertJSONToMetaValues convert json to meta values

func (MetaValues) Get Uses

func (mvs MetaValues) Get(name string) *MetaValue

Get get meta value from MetaValues with name

type Metaor Uses

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
    HasPermission(roles.PermissionMode, *qor.Context) bool

Metaor interface

type Resource Uses

type Resource struct {
    Name            string
    Value           interface{}
    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      []func(interface{}, *MetaValues, *qor.Context) error
    Processors      []func(interface{}, *MetaValues, *qor.Context) error
    // contains filtered or unexported fields

Resource is a struct that including basic definition of qor resource

func New Uses

func New(value interface{}) *Resource

New initialize qor resource

func (*Resource) AddProcessor Uses

func (res *Resource) AddProcessor(fc func(interface{}, *MetaValues, *qor.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 Uses

func (res *Resource) AddValidator(fc func(interface{}, *MetaValues, *qor.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 Uses

func (res *Resource) CallDelete(result interface{}, context *qor.Context) error

CallDelete call delete method

func (*Resource) CallFindMany Uses

func (res *Resource) CallFindMany(result interface{}, context *qor.Context) error

CallFindMany call find many method

func (*Resource) CallFindOne Uses

func (res *Resource) CallFindOne(result interface{}, metaValues *MetaValues, context *qor.Context) error

CallFindOne call find one method

func (*Resource) CallSave Uses

func (res *Resource) CallSave(result interface{}, context *qor.Context) error

CallSave call save method

func (*Resource) GetMetas Uses

func (res *Resource) GetMetas([]string) []Metaor

GetMetas get defined metas, to match interface `Resourcer`

func (*Resource) GetResource Uses

func (res *Resource) GetResource() *Resource

GetResource return itself to match interface `Resourcer`

func (*Resource) HasPermission Uses

func (res *Resource) HasPermission(mode roles.PermissionMode, context *qor.Context) bool

HasPermission check permission of resource

func (*Resource) NewSlice Uses

func (res *Resource) NewSlice() interface{}

NewSlice initialize a slice of struct for the Resource

func (*Resource) NewStruct Uses

func (res *Resource) NewStruct() interface{}

NewStruct initialize a struct for the Resource

func (*Resource) PrimaryDBName Uses

func (res *Resource) PrimaryDBName() (name string)

PrimaryDBName return db column name of the resource's primary field

func (*Resource) PrimaryField Uses

func (res *Resource) PrimaryField() *gorm.Field

PrimaryField return gorm's primary field

func (*Resource) PrimaryFieldName Uses

func (res *Resource) PrimaryFieldName() (name string)

PrimaryFieldName return struct column name of the resource's primary field

type Resourcer Uses

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

Package resource imports 17 packages (graph) and is imported by 17 packages. Updated 2017-06-08. Refresh now. Tools for package owners.