Documentation ¶
Index ¶
- Variables
- func CreateBetterRESTTable()
- func GetTableNameFromTypeString(typeString string) string
- func NewFromTypeString(typeString string) mdl.IModel
- func NewOrgModelFromOrgResourceTypeString(typeString string) mdl.IModel
- func NewOrgOwnershipModelFromOrgResourceTypeString(typeString string) mdl.IModel
- func NewOwnershipModelFromOwnershipResourceTypeString(typeString string) mdl.IModel
- func NewSliceFromDBByType(modelType reflect.Type, f func(interface{}, ...interface{}) *gorm.DB) ([]mdl.IModel, error)
- func NewSliceFromDBByTypeString(typeString string, f func(interface{}, ...interface{}) *gorm.DB) ([]mdl.IModel, error)
- func NewSliceStructFromTypeString(typeString string) []mdl.IModel
- func OrgModelNameFromOrgResourceTypeString(typeString string) string
- func OrgModelTypeFromOrgResourceTypeString(typeString string) reflect.Type
- func OrgOwnershipModelNameFromOrgResourceTypeString(typeString string) string
- func OwnershipTableNameFromOwnershipResourceTypeString(typeString string) string
- func RegRoleSorter(sorter hook.IRoleSorter)
- type BetterRESTTable
- type Reg
- type RegOptions
- type Registrar
- func (r *Registrar) CustomCreate(modelObj mdl.IModel, f func(db *gorm.DB) (*gorm.DB, error)) *Registrar
- func (r *Registrar) Guard(guard func(ep *hook.EndPoint) *webrender.RetError) *Registrar
- func (r *Registrar) Hook(hdlr hook.IHook, method string, args ...interface{}) *Registrar
- func (r *Registrar) Model(modelObj mdl.IModel) *Registrar
- func (r *Registrar) ModelWithOption(modelObj mdl.IModel, options RegOptions) *Registrar
Constants ¶
This section is empty.
Variables ¶
var ModelRegistry = make(map[string]*Reg)
ModelRegistry is model registry
var RoleSorter hook.IRoleSorter
var UserTyp reflect.Type
UserTyp is the model of the User table
Functions ¶
func GetTableNameFromTypeString ¶
GetTableNameFromTypeString get table name from typeString
func NewFromTypeString ¶
NewFromTypeString instantiate a new mdl.IModel object from type registry
func NewOrgModelFromOrgResourceTypeString ¶
NewOrgModelFromOrgResourceTypeString gets Organization object If you're a resource under hooked up by Organization
func NewOrgOwnershipModelFromOrgResourceTypeString ¶
NewOrgOwnershipModelFromOrgResourceTypeString gets the joining table from the resource's organization model to the user
func NewOwnershipModelFromOwnershipResourceTypeString ¶
NewOwnershipModelFromOwnershipResourceTypeString returns the model object of the ownership table (the table that links from this resource represented by the type string to the user)
func NewSliceFromDBByType ¶
func NewSliceFromDBByType(modelType reflect.Type, f func(interface{}, ...interface{}) *gorm.DB) ([]mdl.IModel, error)
NewSliceFromDBByType queries the database for an array of mdl based on modelType func(dest interface{}) *gorm.DB
func NewSliceFromDBByTypeString ¶
func NewSliceFromDBByTypeString(typeString string, f func(interface{}, ...interface{}) *gorm.DB) ([]mdl.IModel, error)
NewSliceFromDBByTypeString queries the database for an array of mdl based on typeString func(dest interface{}) *gorm.DB
func NewSliceStructFromTypeString ¶
NewSliceStructFromTypeString : return something originally like this obj := make(map[string][]Room) obj["content"] = make([]Room, 0, 0) https://stackoverflow.com/questions/50233285/create-a-map-in-go-using-reflection func NewSliceStructFromTypeString(typeString string) map[string][]mdl.IModel {
func OrgModelNameFromOrgResourceTypeString ¶
OrgModelNameFromOrgResourceTypeString given org resource typeString, returns organization table name
func OrgModelTypeFromOrgResourceTypeString ¶
------------------------- OrgModelTypeFromOrgResourceTypeString given org resource typeString returns the reflect type of the organization
func OrgOwnershipModelNameFromOrgResourceTypeString ¶
OrgOwnershipModelNameFromOrgResourceTypeString given org resource typeString, returns name of organization table's linking table (ownership table) to user
func OwnershipTableNameFromOwnershipResourceTypeString ¶
OwnershipTableNameFromOwnershipResourceTypeString given ownership resource typeStirng returns name of ownership table to the user
func RegRoleSorter ¶ added in v0.10.7
func RegRoleSorter(sorter hook.IRoleSorter)
Types ¶
type BetterRESTTable ¶
type BetterRESTTable struct { ID *datatype.UUID `gorm:"type:uuid;primary_key;" json:"id"` CreatedAt time.Time `json:"createdAt" json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` // Name is table name Name string `gorm:"unique_index:name"` // Version is table version Version string }
BetterRESTTable store the information on all other mdl
type Reg ¶
type Reg struct { Typ reflect.Type TypVersion string // TypVersion is the Version of this model // CreateObj is by default the one passed in when calling RegModel* // It could be overriden with RegCustomCreate() CreateObj mdl.IModel // If type is link to user type, store type of ownership table (the one // that links to user) OwnershipType reflect.Type OwnershipTableName *string // If custom ownership table is registered, store here OwnershipModelObjPtr mdl.IModel OrgTypeString string // If type has link to organization type, store organization typestring // CreateMethod can be defined with RegCustomCreate() CreateMethod func(db *gorm.DB) (*gorm.DB, error) GuardMethods []func(ep *hook.EndPoint) *webrender.RetError BatchMethods string // Batch endpoints, "CRUD" for create, batch read, batch update, batch delete IdvMethods string // ID end points, "RUD" for read one, update one, and delete one Mapper mappertype.MapperType // Custmized mapper, default to datamapper.SharedOwnershipMapper // HandlerMap is the new method where we keep handlers // You can register any number of hook to handle the rest process. // When each conncection is intantiated, the hook remain in memory until the REST op is returned // If there are two hook which handles the same method and the same hook, they will both be called. // The calling order is not guaranteed. HandlerMap *handlermap.HandlerMap }
Reg is a registry item
type RegOptions ¶
type RegOptions struct { BatchMethods string // Batch endpoints, "CRUD" for create, batch read, batch update, batch delete IdvMethods string // ID end points, "RUD" for read one, update one, and delete one Mapper mappertype.MapperType }
RegOptions is options when you want to add a model to registry
type Registrar ¶
type Registrar struct {
// contains filtered or unexported fields
}
Registrar has registration methods for mdl
func NewRegistrar ¶
func (*Registrar) CustomCreate ¶
func (r *Registrar) CustomCreate(modelObj mdl.IModel, f func(db *gorm.DB) (*gorm.DB, error)) *Registrar
CustomCreate register custom create table funtion
func (*Registrar) Hook ¶ added in v0.9.5
Hook adds the handler (contains one or more hooks) to be instantiate when a REST op occurs. If any hook exists, old model-based hookpoints and batch hookpoints are not called
func (*Registrar) Model ¶
Model adds a New function for an mdl.IModel (convenient function of RegModelWithOption)
func (*Registrar) ModelWithOption ¶
func (r *Registrar) ModelWithOption(modelObj mdl.IModel, options RegOptions) *Registrar
ModelWithOption adds a New function for an mdl.IModel