resource

package
v0.0.0-...-2ef9421 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProcessorRecordNotFound = errors.New("resource: record not found")
	ErrProcessorSkipLeft       = errors.New("resource: skip left")
)
View Source
var DefaultDeleter = func(result interface{}, context *qor.Context) error {
	if !context.GetDB().First(result, context.ResourceID).RecordNotFound() {
		return context.GetDB().Delete(result).Error
	} else {
		return gorm.RecordNotFound
	}
}
View Source
var DefaultFinder = func(result interface{}, metaValues *MetaValues, context *qor.Context) error {
	if metaValues == nil && context.ResourceID != "" {
		return context.GetDB().First(result, context.ResourceID).Error
	}
	return errors.New("failed to find")
}
View Source
var DefaultSaver = func(result interface{}, context *qor.Context) error {
	return context.GetDB().Save(result).Error
}
View Source
var DefaultSearcher = func(result interface{}, context *qor.Context) error {
	return context.GetDB().Set("gorm:order_by_primary_key", "DESC").Find(result).Error
}

Functions

func Decode

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

func DecodeToResource

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

Types

type MetaValue

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

type MetaValues

type MetaValues struct {
	Values []*MetaValue
}

func ConvertFormToMetaValues

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

func ConvertJSONToMetaValues

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

func (MetaValues) Get

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

type Metaor

type Metaor interface {
	GetName() string
	GetFieldName() string
	GetMetas() []Metaor
	GetResource() Resourcer
	GetSetter() func(resource interface{}, metaValue *MetaValue, context *qor.Context)
	HasPermission(roles.PermissionMode, *qor.Context) bool
}

type Resource

type Resource struct {
	Name       string
	StructType string

	Value           interface{}
	FindManyHandler func(interface{}, *qor.Context) error
	FindOneHandler  func(interface{}, *MetaValues, *qor.Context) error
	Saver           func(interface{}, *qor.Context) error
	Deleter         func(interface{}, *qor.Context) error
	// contains filtered or unexported fields
}

func New

func New(value interface{}) *Resource

func (*Resource) AddProcessor

func (res *Resource) AddProcessor(fc func(interface{}, *MetaValues, *qor.Context) error)

func (*Resource) AddValidator

func (res *Resource) AddValidator(fc func(interface{}, *MetaValues, *qor.Context) error)

func (*Resource) CallDeleter

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

func (*Resource) CallFindMany

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

func (*Resource) CallFindOne

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

func (*Resource) CallSaver

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

func (*Resource) GetMetas

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

func (*Resource) GetResource

func (res *Resource) GetResource() *Resource

func (*Resource) NewSlice

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

func (*Resource) NewStruct

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

func (*Resource) PrimaryDBName

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

func (*Resource) PrimaryField

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

func (*Resource) PrimaryFieldName

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

type Resourcer

type Resourcer interface {
	GetResource() *Resource
	GetMetas([]string) []Metaor
	CallFindMany(interface{}, *qor.Context) error
	CallFindOne(interface{}, *MetaValues, *qor.Context) error
	CallSaver(interface{}, *qor.Context) error
	CallDeleter(interface{}, *qor.Context) error
	NewSlice() interface{}
	NewStruct() interface{}
}

Jump to

Keyboard shortcuts

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