本文整理汇总了Golang中gnd/la/util/structs.Tag.Length方法的典型用法代码示例。如果您正苦于以下问题:Golang Tag.Length方法的具体用法?Golang Tag.Length怎么用?Golang Tag.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnd/la/util/structs.Tag
的用法示例。
在下文中一共展示了Tag.Length方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FieldType
func (b *Backend) FieldType(typ reflect.Type, t *structs.Tag) (string, error) {
if c := codec.FromTag(t); c != nil {
if c.Binary || t.PipeName() != "" {
return "BLOB", nil
}
return "TEXT", nil
}
var ft string
switch typ.Kind() {
case reflect.Bool:
ft = "BOOL"
case reflect.Int8:
ft = "TINYINT"
case reflect.Uint8:
ft = "TINYINT UNSIGNED"
case reflect.Int16:
ft = "SMALLINT"
case reflect.Uint16:
ft = "SMALLINT UNSIGNED"
case reflect.Int32:
ft = "INT"
case reflect.Uint32:
ft = "INT UNSIGNED"
case reflect.Int, reflect.Int64:
ft = "BIGINT"
case reflect.Uint, reflect.Uint64:
ft = "BIGINT UNSIGNED"
case reflect.Float32:
ft = "FLOAT"
case reflect.Float64:
ft = "DOUBLE"
case reflect.String:
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 = "BLOB"
}
case reflect.Struct:
if typ.Name() == "Time" && typ.PkgPath() == "time" {
ft = "DATETIME"
}
}
if ft != "" {
return ft, nil
}
return "", fmt.Errorf("can't map field type %v to a database type", typ)
}