本文整理汇总了Golang中github.com/qor/inflection.Plural函数的典型用法代码示例。如果您正苦于以下问题:Golang Plural函数的具体用法?Golang Plural怎么用?Golang Plural使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Plural函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestPlural
func TestPlural(t *testing.T) {
for key, value := range inflections {
if v := inflection.Plural(strings.ToUpper(key)); v != strings.ToUpper(value) {
t.Errorf("%v's plural should be %v, but got %v", strings.ToUpper(key), strings.ToUpper(value), v)
}
if v := inflection.Plural(strings.Title(key)); v != strings.Title(value) {
t.Errorf("%v's plural should be %v, but got %v", strings.Title(key), strings.Title(value), v)
}
if v := inflection.Plural(key); v != value {
t.Errorf("%v's plural should be %v, but got %v", key, value, v)
}
}
}
开发者ID:lue828,项目名称:osinstall-server,代码行数:15,代码来源:inflections_test.go
示例2: AddResource
func (admin *Admin) AddResource(value interface{}, config ...*Config) *Resource {
res := admin.NewResource(value, config...)
if !res.Config.Invisible {
// TODO: move Menu out of res.Config, make the API looks better
menu := &Menu{rawPath: res.ToParam(), Name: inflection.Plural(res.Name)}
admin.menus = appendMenu(admin.menus, res.Config.Menu, menu)
}
admin.resources = append(admin.resources, res)
return res
}
开发者ID:trigrass2,项目名称:qor,代码行数:12,代码来源:admin.go
示例3: 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), ".") },
}
}
开发者ID:sunfengqi,项目名称:qor,代码行数:15,代码来源:base.go
示例4: AddResource
func (admin *Admin) AddResource(value interface{}, config ...*Config) *Resource {
res := admin.NewResource(value, config...)
if !res.Config.Invisible {
var menuName string
if res.Config.Singleton {
menuName = res.Name
} else {
menuName = inflection.Plural(res.Name)
}
menu := &Menu{rawPath: res.ToParam(), Name: menuName}
admin.menus = appendMenu(admin.menus, res.Config.Menu, menu)
}
admin.resources = append(admin.resources, res)
return res
}
开发者ID:NeoChow,项目名称:qor,代码行数:18,代码来源:admin.go
示例5: GetModelStruct
func (scope *Scope) GetModelStruct() *ModelStruct {
var modelStruct ModelStruct
reflectValue := reflect.Indirect(reflect.ValueOf(scope.Value))
if !reflectValue.IsValid() {
return &modelStruct
}
if reflectValue.Kind() == reflect.Slice {
reflectValue = reflect.Indirect(reflect.New(reflectValue.Type().Elem()))
}
scopeType := reflectValue.Type()
if scopeType.Kind() == reflect.Ptr {
scopeType = scopeType.Elem()
}
if value := modelStructsMap.Get(scopeType); value != nil {
return value
}
modelStruct.ModelType = scopeType
if scopeType.Kind() != reflect.Struct {
return &modelStruct
}
if tabler, ok := reflect.New(scopeType).Interface().(interface {
TableName() string
}); ok {
modelStruct.defaultTableName = tabler.TableName()
} else {
name := ToDBName(scopeType.Name())
if scope.db == nil || !scope.db.parent.singularTable {
name = inflection.Plural(name)
}
modelStruct.defaultTableName = name
}
// Get all fields
fields := []*StructField{}
for i := 0; i < scopeType.NumField(); i++ {
if fieldStruct := scopeType.Field(i); ast.IsExported(fieldStruct.Name) {
field := &StructField{
Struct: fieldStruct,
Name: fieldStruct.Name,
Names: []string{fieldStruct.Name},
Tag: fieldStruct.Tag,
}
if fieldStruct.Tag.Get("sql") == "-" {
field.IsIgnored = true
} else {
sqlSettings := parseTagSetting(field.Tag.Get("sql"))
gormSettings := parseTagSetting(field.Tag.Get("gorm"))
if _, ok := gormSettings["PRIMARY_KEY"]; ok {
field.IsPrimaryKey = true
modelStruct.PrimaryFields = append(modelStruct.PrimaryFields, field)
}
if _, ok := sqlSettings["DEFAULT"]; ok {
field.HasDefaultValue = true
}
if value, ok := gormSettings["COLUMN"]; ok {
field.DBName = value
} else {
field.DBName = ToDBName(fieldStruct.Name)
}
}
fields = append(fields, field)
}
}
var finished = make(chan bool)
go func(finished chan bool) {
for _, field := range fields {
if !field.IsIgnored {
fieldStruct := field.Struct
indirectType := fieldStruct.Type
if indirectType.Kind() == reflect.Ptr {
indirectType = indirectType.Elem()
}
if _, isScanner := reflect.New(indirectType).Interface().(sql.Scanner); isScanner {
field.IsScanner, field.IsNormal = true, true
}
if _, isTime := reflect.New(indirectType).Interface().(*time.Time); isTime {
field.IsNormal = true
}
if !field.IsNormal {
gormSettings := parseTagSetting(field.Tag.Get("gorm"))
toScope := scope.New(reflect.New(fieldStruct.Type).Interface())
getForeignField := func(column string, fields []*StructField) *StructField {
for _, field := range fields {
if field.Name == column || field.DBName == ToDBName(column) {
//.........这里部分代码省略.........
开发者ID:rasata,项目名称:gorm,代码行数:101,代码来源:model_struct.go
示例6: ToParam
func (res Resource) ToParam() string {
if res.Config.Singleton == true {
return utils.ToParamString(res.Name)
}
return utils.ToParamString(inflection.Plural(res.Name))
}
开发者ID:NeoChow,项目名称:qor,代码行数:6,代码来源:resource.go
示例7: ToParam
func (res Resource) ToParam() string {
return utils.ToParamString(inflection.Plural(res.Name))
}
开发者ID:kennylixi,项目名称:qor,代码行数:3,代码来源:resource.go
示例8: Plural
func Plural(s string) string {
return inflection.Plural(s)
}
开发者ID:lamproae,项目名称:scaffold,代码行数:3,代码来源:fns.go
注:本文中的github.com/qor/inflection.Plural函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论