本文整理汇总了Golang中gnd/la/util/structs.Tag.Has方法的典型用法代码示例。如果您正苦于以下问题:Golang Tag.Has方法的具体用法?Golang Tag.Has怎么用?Golang Tag.Has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnd/la/util/structs.Tag
的用法示例。
在下文中一共展示了Tag.Has方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: isPrimaryKey
func (d *Driver) isPrimaryKey(fields *driver.Fields, idx int, tag *structs.Tag) bool {
if tag.Has("primary_key") {
return true
}
for _, v := range fields.CompositePrimaryKey {
if v == idx {
return true
}
}
return false
}
示例2: DecomposeField
func (ormStructConfigurator) DecomposeField(s *structs.Struct, typ reflect.Type, tag *structs.Tag) bool {
// Don't decompose fields with a codec
if tag.Has("codec") {
return false
}
// Avoid decomposing time.Time
if typ.Name() == "Time" && typ.PkgPath() == "time" {
return false
}
return true
}
示例3: ScanByteSlice
func (b *SqlBackend) ScanByteSlice(val []byte, goVal *reflect.Value, t *structs.Tag) error {
if goVal.Kind() == reflect.String {
goVal.SetString(string(val))
return nil
}
if len(val) > 0 && !t.Has("raw") {
b := make([]byte, len(val))
copy(b, val)
val = b
}
goVal.Set(reflect.ValueOf(val))
return nil
}
示例4: defaultsToNullEmpty
// returns wheter the kind defaults to nullempty option
func defaultsToNullEmpty(typ reflect.Type, t *structs.Tag) bool {
if t.Has("references") || t.Has("codec") || (t.Has("notnull") && typ.Kind() != reflect.Bool) {
return true
}
switch typ.Kind() {
case reflect.Slice, reflect.Ptr, reflect.Interface, reflect.String:
return true
case reflect.Struct:
return typ == timeType
}
return false
}
示例5: FieldType
func (b *Backend) FieldType(typ reflect.Type, t *structs.Tag) (string, error) {
if c := codec.FromTag(t); c != nil {
// TODO: Use type JSON on Postgresql >= 9.2 for JSON encoded fields
if c.Binary || t.PipeName() != "" {
return "BYTEA", nil
}
return "TEXT", nil
}
var ft string
switch typ.Kind() {
case reflect.Bool:
ft = "BOOL"
case reflect.Int8, reflect.Uint8, reflect.Int16:
ft = "INT2"
case reflect.Uint16, reflect.Int32:
ft = "INT4"
case reflect.Int, reflect.Uint, reflect.Uint32, reflect.Int64, reflect.Uint64:
ft = "INT8"
case reflect.Float32:
ft = "FLOAT4"
case reflect.Float64:
ft = "FLOAT8"
case reflect.String:
if t.Has("macaddr") {
ft = "MACADDR"
} else if t.Has("inet") {
ft = "INET"
} else {
if ml, ok := t.MaxLength(); ok {
ft = fmt.Sprintf("VARCHAR (%d)", ml)
} else if fl, ok := t.Length(); ok {
ft = fmt.Sprintf("CHAR (%d)", fl)
} else {
ft = "TEXT"
}
}
case reflect.Slice:
etyp := typ.Elem()
if etyp.Kind() == reflect.Uint8 {
// []byte
ft = "BYTEA"
// TODO: database/sql does not support array types. Enable this code
// if that changes in the future
// } else if typ.Elem().Kind() != reflect.Struct {
// et, err := b.FieldType(typ.Elem(), tag)
// if err != nil {
// return "", err
// }
// t = et + "[]"
}
case reflect.Struct:
if typ.Name() == "Time" && typ.PkgPath() == "time" {
ft = "TIMESTAMP WITHOUT TIME ZONE"
}
}
if t.Has("auto_increment") {
if strings.HasPrefix(ft, "INT") {
ft = strings.Replace(ft, "INT", "SERIAL", -1)
} else {
return "", fmt.Errorf("postgres does not support auto incrementing %v", typ)
}
}
if ft != "" {
return ft, nil
}
return "", fmt.Errorf("can't map field type %v to a database type", typ)
}
示例6: defaultsToOmitEmpty
func defaultsToOmitEmpty(typ reflect.Type, t *structs.Tag) bool {
return t.Has("auto_increment") || (t.Has("default") && typ.Kind() != reflect.Bool)
}