本文整理汇总了Golang中github.com/jinzhu/gorm.Scope.GetModelStruct方法的典型用法代码示例。如果您正苦于以下问题:Golang Scope.GetModelStruct方法的具体用法?Golang Scope.GetModelStruct怎么用?Golang Scope.GetModelStruct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jinzhu/gorm.Scope
的用法示例。
在下文中一共展示了Scope.GetModelStruct方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: isLocalizable
func isLocalizable(scope *gorm.Scope) (isLocalizable bool) {
if scope.GetModelStruct().ModelType == nil {
return false
}
_, isLocalizable = reflect.New(scope.GetModelStruct().ModelType).Interface().(l10nInterface)
return
}
示例2: syncColumns
func syncColumns(scope *gorm.Scope) (columns []string) {
for _, field := range scope.GetModelStruct().StructFields {
if isSyncField(field) {
columns = append(columns, field.DBName)
}
}
return
}
示例3: beforeCreate
func beforeCreate(scope *gorm.Scope) {
if isLocalizable(scope) {
if locale, ok := getLocale(scope); ok { // is locale
if isLocaleCreateable(scope) || !scope.PrimaryKeyZero() {
setLocale(scope, locale)
} else {
err := fmt.Errorf("the resource %v cannot be created in %v", scope.GetModelStruct().ModelType.Name(), locale)
scope.Err(err)
}
} else {
setLocale(scope, Global)
}
}
}
示例4: getFuncMap
func getFuncMap(scope *gorm.Scope, field *gorm.Field, filename string) template.FuncMap {
hash := func() string { return strings.Replace(time.Now().Format("20060102150506.000000000"), ".", "", -1) }
return template.FuncMap{
"class": func() string { return strings.ToLower(inflection.Plural(scope.GetModelStruct().ModelType.Name())) },
"primary_key": func() string { return fmt.Sprintf("%v", scope.PrimaryKeyValue()) },
"column": func() string { return field.Name },
"filename": func() string { return filename },
"basename": func() string { return strings.TrimSuffix(path.Base(filename), path.Ext(filename)) },
"hash": hash,
"filename_with_hash": func() string {
return fmt.Sprintf("%v.%v%v", strings.TrimSuffix(filename, path.Ext(filename)), hash(), path.Ext(filename))
},
"extension": func() string { return strings.TrimPrefix(path.Ext(filename), ".") },
}
}
示例5: Stringify
func Stringify(object interface{}) string {
if obj, ok := object.(interface {
Stringify() string
}); ok {
return obj.Stringify()
}
scope := gorm.Scope{Value: object}
for _, column := range []string{"Name", "Title"} {
if field, ok := scope.FieldByName(column); ok {
return fmt.Sprintf("%v", field.Field.Interface())
}
}
if scope.PrimaryKeyZero() {
return ""
} else {
return fmt.Sprintf("%v#%v", scope.GetModelStruct().ModelType.Name(), scope.PrimaryKeyValue())
}
}
示例6: stringify
func stringify(object interface{}) string {
if obj, ok := object.(interface {
Stringify() string
}); ok {
return obj.Stringify()
}
scope := gorm.Scope{Value: object}
for _, column := range []string{"Description", "Name", "Title", "Code"} {
if field, ok := scope.FieldByName(column); ok {
return fmt.Sprintf("%v", field.Field.Interface())
}
}
if scope.PrimaryField() != nil {
if scope.PrimaryKeyZero() {
return ""
}
return fmt.Sprintf("%v#%v", scope.GetModelStruct().ModelType.Name(), scope.PrimaryKeyValue())
}
return fmt.Sprint(reflect.Indirect(reflect.ValueOf(object)).Interface())
}
示例7: isLocaleCreateable
func isLocaleCreateable(scope *gorm.Scope) (ok bool) {
_, ok = reflect.New(scope.GetModelStruct().ModelType).Interface().(LocaleCreateableInterface)
return
}
示例8: Label
// Label is a label including model type, primary key and column name
func (err Error) Label() string {
scope := gorm.Scope{Value: err.Resource}
return fmt.Sprintf("%v_%v_%v", scope.GetModelStruct().ModelType.Name(), scope.PrimaryKeyValue(), err.Column)
}