Documentation ¶
Index ¶
- Variables
- func CreateBetterRESTTable()
- func FieldNameToColumn(modelObj IModel, fieldName string) (string, error)
- func FieldNameToJSONName(modelObj IModel, fieldName string) (string, error)
- func GetFieldNameFromModelByTagKey(modelObj interface{}, valueKey string) *string
- func GetFieldTypeFromModelByTagKeyBetterRestAndValueKey(modelObj IModel, valueKey string, recurseIntoEmbedded bool) reflect.Type
- func GetFieldValueFromModelByTagKeyBetterRestAndValueKey(modelObj IModel, valueKey string) interface{}
- func GetModelFieldTypeInModelIfValid(modelObj IModel, field string) (reflect.Type, error)
- func GetModelTableNameInModelIfValid(modelObj IModel, field string) (string, error)
- func GetModelTypeNameFromIModel(model IModel) string
- func GetTableNameFromIModel(model IModel) string
- func GetTableNameFromType(typ reflect.Type) string
- func GetTableNameFromTypeString(typeString string) string
- func GetTagValueFromModelByTagKeyBetterRestAndValueKey(modelObj interface{}, valueKey string) *string
- func IsFieldInModel(modelObj IModel, field string) bool
- func JSONKeysToFieldName(modelObj IModel, key string) (string, error)
- func OrgModelNameFromOrgResourceTypeString(typeString string) string
- func OrgModelTypeFromOrgResourceTypeString(typeString string) reflect.Type
- func OrgOwnershipModelNameFromOrgResourceTypeString(typeString string) string
- func OwnershipTableNameFromOwnershipResourceTypeString(typeString string) string
- func TranslateValidationErrorMessage(errs validator.ValidationErrors, modelObj IModel) (string, error)
- func ValidateModel(modelObj IModel) error
- type BaseModel
- func (b *BaseModel) BeforeCreate(scope *gorm.Scope) error
- func (b *BaseModel) GetCreatedAt() *time.Time
- func (b *BaseModel) GetDeletedAt() *time.Time
- func (b *BaseModel) GetID() *datatypes.UUID
- func (b *BaseModel) GetUpdatedAt() *time.Time
- func (b *BaseModel) SetID(id *datatypes.UUID)
- func (b *BaseModel) Validate() error
- type BatchHookCargo
- type BatchHookPointData
- type BetterRESTTable
- type CRUPDOp
- type FieldNotInModelError
- type HTTP
- type HookPointData
- type IAfterCRUPD
- type IAfterCreate
- type IAfterDelete
- type IAfterPatch
- type IAfterRead
- type IAfterTransact
- type IAfterUpdate
- type IBeforeCUPD
- type IBeforeCreate
- type IBeforeDelete
- type IBeforePatch
- type IBeforePatchApply
- type IBeforeUpdate
- type IDoRealDelete
- type IGuardAPIEntry
- type IHasPermissions
- type IHasRenderer
- type IHasTableName
- type IModel
- func GetInnerModelIfValid(modelObj IModel, field string) (IModel, error)
- func NewFromTypeString(typeString string) IModel
- func NewOrgModelFromOrgResourceTypeString(typeString string) IModel
- func NewOrgOwnershipModelFromOrgResourceTypeString(typeString string) IModel
- func NewOwnershipModelFromOwnershipResourceTypeString(typeString string) IModel
- func NewSliceFromDBByType(modelType reflect.Type, f func(interface{}, ...interface{}) *gorm.DB) ([]IModel, error)
- func NewSliceFromDBByTypeString(typeString string, f func(interface{}, ...interface{}) *gorm.DB) ([]IModel, error)
- func NewSliceStructFromTypeString(typeString string) []IModel
- type IOwnership
- type IValidate
- type JSONIDPatch
- type MapperType
- type ModelCargo
- type ModelHasOwnership
- type OwnershipModelBase
- type OwnershipModelWithIDBase
- func (b *OwnershipModelWithIDBase) GetCreatedAt() *time.Time
- func (o *OwnershipModelWithIDBase) GetID() *datatypes.UUID
- func (o *OwnershipModelWithIDBase) GetModelID() *datatypes.UUID
- func (b *OwnershipModelWithIDBase) GetUpdatedAt() *time.Time
- func (o *OwnershipModelWithIDBase) GetUserID() *datatypes.UUID
- func (o *OwnershipModelWithIDBase) SetID(id *datatypes.UUID)
- func (o *OwnershipModelWithIDBase) SetModelID(id *datatypes.UUID)
- func (o *OwnershipModelWithIDBase) SetUserID(id *datatypes.UUID)
- type Reg
- type RegOptions
- type Registrar
- func (r *Registrar) BatchAfterTransactHook(hook func(bhpData BatchHookPointData, op CRUPDOp)) *Registrar
- func (r *Registrar) BatchCRUPDHooks(before func(bhpData BatchHookPointData, op CRUPDOp) error, ...) *Registrar
- func (r *Registrar) BatchCreateHooks(before func(bhpData BatchHookPointData) error, ...) *Registrar
- func (r *Registrar) BatchDeleteHooks(before func(bhpData BatchHookPointData) error, ...) *Registrar
- func (r *Registrar) BatchPatchHooks(beforeApply func(bhpData BatchHookPointData) error, ...) *Registrar
- func (r *Registrar) BatchReadHooks(after func(bhpData BatchHookPointData) error) *Registrar
- func (r *Registrar) BatchRenderer(...) *Registrar
- func (r *Registrar) BatchUpdateHooks(before func(bhpData BatchHookPointData) error, ...) *Registrar
- func (r *Registrar) Controller(controller interface{})
- func (r *Registrar) CustomCreate(modelObj IModel, f func(db *gorm.DB) (*gorm.DB, error)) *Registrar
- func (r *Registrar) Model(modelObj IModel) *Registrar
- func (r *Registrar) ModelWithOption(modelObj IModel, options RegOptions) *Registrar
- type UserIDFetchable
- type UserRole
Constants ¶
This section is empty.
Variables ¶
var ( Validate *validator.Validate Trans ut.Translator )
use a single instance , it caches struct info
var ModelRegistry = make(map[string]*Reg)
ModelRegistry is model registry
var UserTyp reflect.Type
UserTyp is the model of the User table
Functions ¶
func CreateBetterRESTTable ¶ added in v0.4.5
func CreateBetterRESTTable()
CreateBetterRESTTable registers models
func FieldNameToColumn ¶ added in v0.5.11
func FieldNameToJSONName ¶ added in v0.5.11
func GetFieldNameFromModelByTagKey ¶ added in v0.4.0
GetFieldNameFromModelByTagKey get's the name of the tagged field If it's a slice, it returns the element type It's an interface{} because it's not necessarily IModel
func GetFieldTypeFromModelByTagKeyBetterRestAndValueKey ¶ added in v0.4.0
func GetFieldTypeFromModelByTagKeyBetterRestAndValueKey(modelObj IModel, valueKey string, recurseIntoEmbedded bool) reflect.Type
GetFieldTypeFromModelByTagKeyBetterRestAndValueKey fetches the datatype of the variable tagged in tag
func GetFieldValueFromModelByTagKeyBetterRestAndValueKey ¶ added in v0.4.0
func GetFieldValueFromModelByTagKeyBetterRestAndValueKey(modelObj IModel, valueKey string) interface{}
GetFieldValueFromModelByTagKeyBetterRestAndValueKey fetches value of the variable tagged in tag
func GetModelFieldTypeInModelIfValid ¶ added in v0.5.11
Never returns the pointer value Since what we want is reflec.New() and it would be a pointer
func GetModelTableNameInModelIfValid ¶ added in v0.5.11
func GetModelTypeNameFromIModel ¶ added in v0.4.36
func GetTableNameFromIModel ¶ added in v0.1.20
GetTableNameFromIModel gets table name from an IModel
func GetTableNameFromType ¶ added in v0.1.39
GetTableNameFromType get table name from the model reflect.type
func GetTableNameFromTypeString ¶ added in v0.1.39
GetTableNameFromTypeString get table name from typeString
func GetTagValueFromModelByTagKeyBetterRestAndValueKey ¶ added in v0.4.5
func IsFieldInModel ¶ added in v0.5.11
func JSONKeysToFieldName ¶ added in v0.5.11
JSONKeyToColumnName transforms json name to column name if not found, return err By doing this we don't need model check?
func OrgModelNameFromOrgResourceTypeString ¶ added in v0.4.0
OrgModelNameFromOrgResourceTypeString given org resource typeString, returns organization table name
func OrgModelTypeFromOrgResourceTypeString ¶ added in v0.4.0
OrgModelTypeFromOrgResourceTypeString given org resource typeString returns the reflect type of the organization
func OrgOwnershipModelNameFromOrgResourceTypeString ¶ added in v0.4.0
OrgOwnershipModelNameFromOrgResourceTypeString given org resource typeString, returns name of organization table's linking table (ownership table) to user
func OwnershipTableNameFromOwnershipResourceTypeString ¶ added in v0.4.0
OwnershipTableNameFromOwnershipResourceTypeString given ownership resource typeStirng returns name of ownership table to the user
func TranslateValidationErrorMessage ¶ added in v0.5.11
func ValidateModel ¶ added in v0.5.11
Types ¶
type BaseModel ¶
type BaseModel struct { // For Postgres ID *datatypes.UUID `gorm:"type:uuid;primary_key;" json:"id"` CreatedAt time.Time `sql:"index" json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` DeletedAt *time.Time `sql:"index" json:"deletedAt"` }
BaseModel is the base class domain model which has standard ID
func (*BaseModel) BeforeCreate ¶
BeforeCreate sets a UUID if no ID is set (this is Gorm's hookpoint)
func (*BaseModel) GetCreatedAt ¶ added in v0.8.0
GetCreatedAt gets the time stamp the record is created
func (*BaseModel) GetDeletedAt ¶ added in v0.8.0
GetUpdatedAt gets the time stamp the record is deleted (which we don't use)
func (*BaseModel) GetUpdatedAt ¶ added in v0.8.0
GetUpdatedAt gets the time stamp the record is updated
type BatchHookCargo ¶
type BatchHookCargo struct {
Payload interface{}
}
BatchHookCargo is payload between batch update and batch delete hookpoints
type BatchHookPointData ¶ added in v0.2.0
type BatchHookPointData struct { // Ms is the slice of IModels Ms []IModel // DB is the DB handle DB *gorm.DB // Who is operating this CRUPD right now Who UserIDFetchable // TypeString TypeString string // Cargo between Before and After hookpoints (not used in AfterRead since there is before read hookpoint.) Cargo *BatchHookCargo // Role of this user in relation to this data, only available during read Roles []UserRole // URL parameters URLParams map[urlparam.Param]interface{} }
BatchHookPointData is the data send to batch model hookpoints
type BetterRESTTable ¶ added in v0.4.5
type BetterRESTTable struct { ID *datatypes.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 models
type CRUPDOp ¶ added in v0.4.2
type CRUPDOp int
CRUPDOp designates the type of operations for BeforeCRUPD and AfterCRUPD hookpoints
func HTTPMethodToCRUDOp ¶ added in v0.5.13
type FieldNotInModelError ¶ added in v0.5.11
type FieldNotInModelError struct {
Msg string
}
FieldNotInModelError is for GetModelFieldTypeIfValid. if field doesn't exist in the model, return this error We want to go ahead and skip it since this field may be other options that user can read in hookpoints
func (*FieldNotInModelError) Error ¶ added in v0.5.11
func (r *FieldNotInModelError) Error() string
type HookPointData ¶ added in v0.2.0
type HookPointData struct { // DB handle (not available for AfterTransact) DB *gorm.DB // Who is the user information, who is operating this CRUPD right now Who UserIDFetchable // TypeString is the typeString (model string) of this model TypeString string // Cargo between Before and After hookpoints (not used in IAfterRead since there is no IBeforeRead.) // Currently not supported in the AfterTransact hookpoint Cargo *ModelCargo // Role of this user in relation to this data, only available during read Role *UserRole // URL parameters URLParams map[urlparam.Param]interface{} }
HookPointData is the data send to single model hookpoints
type IAfterCRUPD ¶ added in v0.4.2
type IAfterCRUPD interface {
AfterCRUPDDB(hpdata HookPointData, op CRUPDOp) error
}
IAfterCRUPD supprots method to be called after data is after all CRUPD operations This is called before the individual ops
type IAfterCreate ¶ added in v0.3.2
type IAfterCreate interface {
AfterCreateDB(hpdata HookPointData) error
}
IAfterCreate supports method to be called after data is inserted (created) into the database
type IAfterDelete ¶
type IAfterDelete interface {
AfterDeleteDB(hpdata HookPointData) error
}
IAfterDelete supports method to be called after data is deleted from the database
type IAfterPatch ¶
type IAfterPatch interface {
AfterPatchDB(hpdata HookPointData) error
}
IAfterPatch supports method to be called before data is patched in the database
type IAfterRead ¶ added in v0.1.18
type IAfterRead interface {
AfterReadDB(hpdata HookPointData) error
}
IAfterRead supports method to be called after data is read from the database
type IAfterTransact ¶ added in v0.4.36
type IAfterTransact interface {
AfterTransact(hpdata HookPointData, op CRUPDOp)
}
IAfterTransact is the method to be called after data is after the entire CRUPD transaction is done.
type IAfterUpdate ¶
type IAfterUpdate interface {
AfterUpdateDB(hpdata HookPointData) error
}
IAfterUpdate supports method to be called after data is updated in the database
type IBeforeCUPD ¶ added in v0.4.3
type IBeforeCUPD interface {
BeforeCUPDDB(hpdata HookPointData, op CRUPDOp) error
}
IBeforeCUPD supprots method to be called before data is after all CRUPD operations This is called before the individual ops
type IBeforeCreate ¶ added in v0.3.2
type IBeforeCreate interface {
BeforeCreateDB(hpdata HookPointData) error
}
IBeforeCreate supports method to be called before data is inserted (created) into the database
type IBeforeDelete ¶
type IBeforeDelete interface {
BeforeDeleteDB(hpdata HookPointData) error
}
IBeforeDelete supports method to be called before data is deleted from the database
type IBeforePatch ¶
type IBeforePatch interface {
BeforePatchDB(hpdata HookPointData) error
}
IBeforePatch supports method to be called before data is patched in the database
type IBeforePatchApply ¶ added in v0.4.6
type IBeforePatchApply interface {
BeforePatchApplyDB(hpdata HookPointData) error
}
IBeforePatchApply supports method to be called before data is patched in the database And also before the patch is applied. This comes before BeforePatchDB
type IBeforeUpdate ¶
type IBeforeUpdate interface {
BeforeUpdateDB(hpdata HookPointData) error
}
IBeforeUpdate supports method to be called before data is updated in the database
type IDoRealDelete ¶ added in v0.1.4
type IDoRealDelete interface {
DoRealDelete() bool
}
IDoRealDelete is an interface to customize specification for real db delete
type IGuardAPIEntry ¶ added in v0.1.25
IGuardAPIEntry supports method which guard access to API based on scope
type IHasPermissions ¶ added in v0.4.0
type IHasPermissions interface {
Permissions(role UserRole, who UserIDFetchable) (jsontrans.Permission, jsontrans.JSONFields)
}
IHasPermissions is for IModel with a custom permission field to cherry pick json fields default is to return all but the dates
type IHasRenderer ¶ added in v0.4.4
type IHasRenderer interface {
Render(c *gin.Context, hpdata *HookPointData, op CRUPDOp) bool
}
IHasRenderer is for formatting IModel with a custom function basically do your own custom output If return false, use the default JSON output For batch renderer, register a Render(r UserRole, who models.UserIDFetchable, modelObjs []IModel) bool
type IHasTableName ¶ added in v0.1.18
type IHasTableName interface {
TableName() string
}
IHasTableName we know if there is Gorm's defined custom TableName
type IModel ¶
type IModel interface { // The following two avoids having to use reflection to access ID GetID() *datatypes.UUID SetID(id *datatypes.UUID) GetCreatedAt() *time.Time GetUpdatedAt() *time.Time }
IModel is the interface for all domain models
func GetInnerModelIfValid ¶ added in v0.5.11
func NewFromTypeString ¶
NewFromTypeString instantiate a new IModel object from type registry
func NewOrgModelFromOrgResourceTypeString ¶ added in v0.4.0
NewOrgModelFromOrgResourceTypeString gets Organization object If you're a resource under hooked up by Organization
func NewOrgOwnershipModelFromOrgResourceTypeString ¶ added in v0.4.0
NewOrgOwnershipModelFromOrgResourceTypeString gets the joining table from the resource's organization model to the user
func NewOwnershipModelFromOwnershipResourceTypeString ¶ added in v0.4.0
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 ¶ added in v0.1.28
func NewSliceFromDBByType(modelType reflect.Type, f func(interface{}, ...interface{}) *gorm.DB) ([]IModel, error)
NewSliceFromDBByType queries the database for an array of models based on modelType func(dest interface{}) *gorm.DB
func NewSliceFromDBByTypeString ¶ added in v0.1.28
func NewSliceFromDBByTypeString(typeString string, f func(interface{}, ...interface{}) *gorm.DB) ([]IModel, error)
NewSliceFromDBByTypeString queries the database for an array of models 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][]IModel {
type IOwnership ¶ added in v0.1.18
type IOwnership interface { GetRole() UserRole SetRole(UserRole) GetUserID() *datatypes.UUID SetUserID(*datatypes.UUID) GetModelID() *datatypes.UUID SetModelID(*datatypes.UUID) GetID() *datatypes.UUID SetID(*datatypes.UUID) }
IOwnership is what OwnershipModelBase tables should satisfy. Except OwnershipType, that's for struct which embed OwnershipModelBase
type IValidate ¶
type IValidate interface {
Validate(who UserIDFetchable, http HTTP) error
}
IValidate supports validation with govalidator
type JSONIDPatch ¶ added in v0.3.1
type JSONIDPatch struct { ID *datatypes.UUID `json:"id"` Patch json.RawMessage `json:"patch"` // json.RawMessage is actually just typedefed to []byte }
JSONIDPatch is the stuff inside "content" for PatchMany operation
type MapperType ¶ added in v0.1.28
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 // MapperTypeGlobal is for type where data is public to all MapperTypeGlobal // MapperTypeLinkTable is for table linking user and regular models MapperTypeLinkTable )
type ModelCargo ¶
type ModelCargo struct {
Payload interface{}
}
ModelCargo is payload between hookpoints
type ModelHasOwnership ¶ added in v0.4.5
type ModelHasOwnership struct { BaseModel Ownerships []OwnershipModelWithIDBase `gorm:"PRELOAD:false" json:"-" betterrest:"ownership"` }
ModelHasOwnership is the standard domain model to embed when creating an ownership type. If you need a customized linking table, Embed a BaseModel instead, and define a gorm "PRELOAD:false", json "-", and betterrest:"ownership"
type OwnershipModelBase ¶ added in v0.1.3
type OwnershipModelBase struct { ID *datatypes.UUID `gorm:"type:uuid;primary_key;" json:"id"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` DeletedAt *time.Time `sql:"index" json:"deletedAt"` Role UserRole `json:"role"` // an int }
OwnershipModelBase has a role. Intended to be embedded by table serving as link from resource to user
func (*OwnershipModelBase) BeforeCreate ¶ added in v0.3.0
func (o *OwnershipModelBase) BeforeCreate(scope *gorm.Scope) error
BeforeCreate sets a UUID if no ID is set (this is Gorm's hookpoint)
func (*OwnershipModelBase) GetID ¶ added in v0.3.0
func (o *OwnershipModelBase) GetID() *datatypes.UUID
GetID Get the ID field of the model (useful when using interface)
func (*OwnershipModelBase) GetRole ¶ added in v0.1.3
func (o *OwnershipModelBase) GetRole() UserRole
GetRole gets the role field of the model, comforms to IOwnership
func (*OwnershipModelBase) SetID ¶ added in v0.3.0
func (o *OwnershipModelBase) SetID(id *datatypes.UUID)
SetID Set the ID field of the model (useful when using interface)
func (*OwnershipModelBase) SetRole ¶ added in v0.1.3
func (o *OwnershipModelBase) SetRole(r UserRole)
SetRole sets the role field of the model, comforms to IOwnership
type OwnershipModelWithIDBase ¶ added in v0.3.0
type OwnershipModelWithIDBase struct { OwnershipModelBase UserID *datatypes.UUID `gorm:"index" json:"userID"` // I guess the user's table has to be named "User" then. ModelID *datatypes.UUID `gorm:"index" json:"modelID"` }
OwnershipModelWithIDBase is one with ID, if you don't need unique index for userID and modelID (if you don't expose the link table via LinkTableMapper) You can use this.
func (*OwnershipModelWithIDBase) GetCreatedAt ¶ added in v0.8.0
func (b *OwnershipModelWithIDBase) GetCreatedAt() *time.Time
GetCreatedAt gets the time stamp the record is created
func (*OwnershipModelWithIDBase) GetID ¶ added in v0.4.0
func (o *OwnershipModelWithIDBase) GetID() *datatypes.UUID
GetID Get the ID field of the model (useful when using interface)
func (*OwnershipModelWithIDBase) GetModelID ¶ added in v0.3.0
func (o *OwnershipModelWithIDBase) GetModelID() *datatypes.UUID
GetModelID gets the id of the model, comforms to IOwnership
func (*OwnershipModelWithIDBase) GetUpdatedAt ¶ added in v0.8.0
func (b *OwnershipModelWithIDBase) GetUpdatedAt() *time.Time
GetUpdatedAt gets the time stamp the record is updated
func (*OwnershipModelWithIDBase) GetUserID ¶ added in v0.3.0
func (o *OwnershipModelWithIDBase) GetUserID() *datatypes.UUID
GetUserID gets the user id of the model, comforms to IOwnership
func (*OwnershipModelWithIDBase) SetID ¶ added in v0.4.0
func (o *OwnershipModelWithIDBase) SetID(id *datatypes.UUID)
SetID Set the ID field of the model (useful when using interface)
func (*OwnershipModelWithIDBase) SetModelID ¶ added in v0.3.0
func (o *OwnershipModelWithIDBase) SetModelID(id *datatypes.UUID)
SetModelID sets the id of the model, comforms to IOwnership
func (*OwnershipModelWithIDBase) SetUserID ¶ added in v0.3.0
func (o *OwnershipModelWithIDBase) SetUserID(id *datatypes.UUID)
SetUserID sets the user id of the model, comforms to IOwnership
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 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 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) 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 BeforeCUPD func(bhpData BatchHookPointData, op CRUPDOp) error // no R since model doens't exist yet AfterCRUPD func(bhpData BatchHookPointData, op CRUPDOp) error AfterTransact func(bhpData BatchHookPointData, op CRUPDOp) AfterRead func(bhpData BatchHookPointData) error BeforeCreate func(bhpData BatchHookPointData) error AfterCreate func(bhpData BatchHookPointData) error BeforeUpdate func(bhpData BatchHookPointData) error AfterUpdate func(bhpData BatchHookPointData) error BeforePatchApply func(bhpData BatchHookPointData) error // This comes before patch is applied. Before "BeforePatch" BeforePatch func(bhpData BatchHookPointData) error AfterPatch func(bhpData BatchHookPointData) error BeforeDelete func(bhpData BatchHookPointData) error AfterDelete func(bhpData BatchHookPointData) error BatchRenderer func(c *gin.Context, ms []IModel, bhpdata *BatchHookPointData, op CRUPDOp) bool Controller interface{} }
Reg is a registry item
type RegOptions ¶ added in v0.4.0
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 ¶ added in v0.8.0
type Registrar struct {
// contains filtered or unexported fields
}
Registrar has registration methods for models
func NewRegistrar ¶ added in v0.8.0
func (*Registrar) BatchAfterTransactHook ¶ added in v0.8.0
func (r *Registrar) BatchAfterTransactHook( hook func(bhpData BatchHookPointData, op 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 ¶ added in v0.8.0
func (r *Registrar) BatchCRUPDHooks( before func(bhpData BatchHookPointData, op CRUPDOp) error, after func(bhpData BatchHookPointData, op 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 ¶ added in v0.8.0
func (r *Registrar) BatchCreateHooks( before func(bhpData BatchHookPointData) error, after func(bhpData BatchHookPointData) error) *Registrar
BatchCreateHooks adds hookpoints which are called before and after batch update. Either one can be left as nil
func (*Registrar) BatchDeleteHooks ¶ added in v0.8.0
func (r *Registrar) BatchDeleteHooks( before func(bhpData BatchHookPointData) error, after func(bhpData BatchHookPointData) error) *Registrar
BatchDeleteHooks adds hookpoints which are called before and after batch delete. Either one can be left as nil
func (*Registrar) BatchPatchHooks ¶ added in v0.8.0
func (r *Registrar) BatchPatchHooks( beforeApply func(bhpData BatchHookPointData) error, before func(bhpData BatchHookPointData) error, after func(bhpData BatchHookPointData) error) *Registrar
BatchPatchHooks adds hookpoints which are called before and after batch update. Either one can be left as nil
func (*Registrar) BatchReadHooks ¶ added in v0.8.0
func (r *Registrar) BatchReadHooks(after func(bhpData BatchHookPointData) error) *Registrar
BatchReadHooks adds hookpoints which are called after and read, can be left as nil
func (*Registrar) BatchRenderer ¶ added in v0.8.0
func (r *Registrar) BatchRenderer(renderer func(c *gin.Context, ms []IModel, bhpdata *BatchHookPointData, op CRUPDOp) bool) *Registrar
BatchRenderer register custom batch renderer (do your own output, not necessarily JSON)
func (*Registrar) BatchUpdateHooks ¶ added in v0.8.0
func (r *Registrar) BatchUpdateHooks( before func(bhpData BatchHookPointData) error, after func(bhpData BatchHookPointData) error) *Registrar
BatchUpdateHooks adds hookpoints which are called before and after batch update. Either one can be left as nil
func (*Registrar) Controller ¶ added in v0.8.0
func (r *Registrar) Controller(controller interface{})
Controller adds the subject for new hookpoints If controller is added, other hookpoint is not called
func (*Registrar) CustomCreate ¶ added in v0.8.0
CustomCreate register custom create table funtion
func (*Registrar) Model ¶ added in v0.8.0
Model adds a New function for an IModel (convenient function of RegModelWithOption)
func (*Registrar) ModelWithOption ¶ added in v0.8.0
func (r *Registrar) ModelWithOption(modelObj IModel, options RegOptions) *Registrar
ModelWithOption adds a New function for an IModel
type UserIDFetchable ¶ added in v0.7.0
type UserRole ¶
type UserRole int
UserRole type with enum
const ( // UserRoleAny not for value in db, but for permission where any is fine (link table) UserRoleAny UserRole = -2 // UserRoleInvalid is invalid for this resource UserRoleInvalid UserRole = -1 // UserRoleAdmin is admin UserRole UserRoleAdmin UserRole = 0 // UserRoleGuest is guest UserRole (screw go-lint man) UserRoleGuest UserRole = 1 // UserRolePublic to all (global object) UserRolePublic UserRole = 2 // UserRoleTableBased is like admin but permission is subject to table control // Cannot delete site or alter permissions UserRoleTableBased UserRole = 3 )