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
- type BetterRESTTable
- type MapperType
- type Reg
- type RegOptions
- type Registrar
- func (r *Registrar) BatchAfterTransactHook(hook func(bhpData mdlutil.BatchHookPointData, op mdlutil.CRUPDOp)) *Registrar
- func (r *Registrar) BatchCRUPDHooks(before func(bhpData mdlutil.BatchHookPointData, op mdlutil.CRUPDOp) error, ...) *Registrar
- func (r *Registrar) BatchCreateHooks(before func(bhpData mdlutil.BatchHookPointData) error, ...) *Registrar
- func (r *Registrar) BatchDeleteHooks(before func(bhpData mdlutil.BatchHookPointData) error, ...) *Registrar
- func (r *Registrar) BatchPatchHooks(beforeApply func(bhpData mdlutil.BatchHookPointData) error, ...) *Registrar
- func (r *Registrar) BatchReadHooks(after func(bhpData mdlutil.BatchHookPointData) error) *Registrar
- func (r *Registrar) BatchRenderer(...) *Registrar
- func (r *Registrar) BatchUpdateHooks(before func(bhpData mdlutil.BatchHookPointData) error, ...) *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 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
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 MapperType ¶
type MapperType int
MapperType is the mapper type
const ( // MapperTypeViaOwnership is for type which user owns something MapperTypeViaOwnership MapperType = iota // MapperTypeUser is user itself MapperTypeUser // MapperTypeViaOrganization is for type where an organization owns something MapperTypeViaOrganization // MapperTypeViaOrgPartition is for type where an organization owns something and it's in partitioned table MapperTypeViaOrgPartition // MapperTypeGlobal is for type where data is public to all MapperTypeGlobal // MapperTypeLinkTable is for table linking user and regular mdl MapperTypeLinkTable )
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 // Custmized mapper, default to datamapper.SharedOwnershipMapper // Begin deprecated BeforeCUPD func(bhpData mdlutil.BatchHookPointData, op mdlutil.CRUPDOp) error // no R since model doens't exist yet AfterCRUPD func(bhpData mdlutil.BatchHookPointData, op mdlutil.CRUPDOp) error AfterTransact func(bhpData mdlutil.BatchHookPointData, op mdlutil.CRUPDOp) AfterRead func(bhpData mdlutil.BatchHookPointData) error BeforeCreate func(bhpData mdlutil.BatchHookPointData) error AfterCreate func(bhpData mdlutil.BatchHookPointData) error BeforeUpdate func(bhpData mdlutil.BatchHookPointData) error AfterUpdate func(bhpData mdlutil.BatchHookPointData) error BeforePatchApply func(bhpData mdlutil.BatchHookPointData) error // This comes before patch is applied. Before "BeforePatch" BeforePatch func(bhpData mdlutil.BatchHookPointData) error AfterPatch func(bhpData mdlutil.BatchHookPointData) error BeforeDelete func(bhpData mdlutil.BatchHookPointData) error AfterDelete func(bhpData mdlutil.BatchHookPointData) error BatchRenderer func(c *gin.Context, ms []mdl.IModel, bhpdata *mdlutil.BatchHookPointData, op mdlutil.CRUPDOp) bool // 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 }
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) BatchAfterTransactHook ¶
func (r *Registrar) BatchAfterTransactHook( hook func(bhpData mdlutil.BatchHookPointData, op mdlutil.CRUPDOp)) *Registrar
BatchCRUPDHooks adds hookpoints which are called before CUPD (no read) and after batch CRUPD. Either one can be left as nil
func (*Registrar) BatchCRUPDHooks ¶
func (r *Registrar) BatchCRUPDHooks( before func(bhpData mdlutil.BatchHookPointData, op mdlutil.CRUPDOp) error, after func(bhpData mdlutil.BatchHookPointData, op mdlutil.CRUPDOp) error) *Registrar
BatchCRUPDHooks adds hookpoints which are called before CUPD (no read) and after batch CRUPD. Either one can be left as nil
func (*Registrar) BatchCreateHooks ¶
func (r *Registrar) BatchCreateHooks( before func(bhpData mdlutil.BatchHookPointData) error, after func(bhpData mdlutil.BatchHookPointData) error) *Registrar
BatchCreateHooks adds hookpoints which are called before and after batch update. Either one can be left as nil
func (*Registrar) BatchDeleteHooks ¶
func (r *Registrar) BatchDeleteHooks( before func(bhpData mdlutil.BatchHookPointData) error, after func(bhpData mdlutil.BatchHookPointData) error) *Registrar
BatchDeleteHooks adds hookpoints which are called before and after batch delete. Either one can be left as nil
func (*Registrar) BatchPatchHooks ¶
func (r *Registrar) BatchPatchHooks( beforeApply func(bhpData mdlutil.BatchHookPointData) error, before func(bhpData mdlutil.BatchHookPointData) error, after func(bhpData mdlutil.BatchHookPointData) error) *Registrar
BatchPatchHooks adds hookpoints which are called before and after batch update. Either one can be left as nil
func (*Registrar) BatchReadHooks ¶
func (r *Registrar) BatchReadHooks(after func(bhpData mdlutil.BatchHookPointData) error) *Registrar
BatchReadHooks adds hookpoints which are called after and read, can be left as nil
func (*Registrar) BatchRenderer ¶
func (r *Registrar) BatchRenderer(renderer func(c *gin.Context, ms []mdl.IModel, bhpdata *mdlutil.BatchHookPointData, op mdlutil.CRUPDOp) bool) *Registrar
Deprecated BatchRenderer register custom batch renderer (do your own output, not necessarily JSON)
func (*Registrar) BatchUpdateHooks ¶
func (r *Registrar) BatchUpdateHooks( before func(bhpData mdlutil.BatchHookPointData) error, after func(bhpData mdlutil.BatchHookPointData) error) *Registrar
BatchUpdateHooks adds hookpoints which are called before and after batch update. Either one can be left as nil
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