本文整理汇总了Golang中github.com/ardielle/ardielle-go/rdl.TypeRegistry.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang TypeRegistry.Name方法的具体用法?Golang TypeRegistry.Name怎么用?Golang TypeRegistry.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ardielle/ardielle-go/rdl.TypeRegistry
的用法示例。
在下文中一共展示了TypeRegistry.Name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: goType
func goType(reg rdl.TypeRegistry, rdlType rdl.TypeRef, optional bool, items rdl.TypeRef, keys rdl.TypeRef, precise bool, reference bool) string {
rdlPrefix := "rdl."
if reg.Name() == "rdl" {
rdlPrefix = ""
}
cleanType := string(rdlType)
if !strings.HasPrefix(cleanType, "rdl.") {
cleanType = capitalize(strings.Replace(string(rdlType), ".", "_", -1))
}
prefix := ""
if optional {
prefix = "*"
}
t := reg.FindType(rdlType)
if t.Variant == 0 {
panic("Cannot find type '" + rdlType + "'")
}
lrdlType := strings.ToLower(string(rdlType))
if precise {
switch lrdlType {
case "string":
return "string"
case "symbol":
return rdlPrefix + "Symbol"
case "bool", "int32", "int64", "int16", "int8", "float64", "float32":
return prefix + strings.ToLower(cleanType)
default:
bt := reg.BaseType(t)
switch bt {
case rdl.BaseTypeString, rdl.BaseTypeSymbol:
return cleanType
case rdl.BaseTypeInt8, rdl.BaseTypeInt16, rdl.BaseTypeInt32, rdl.BaseTypeInt64, rdl.BaseTypeFloat32, rdl.BaseTypeFloat64, rdl.BaseTypeBool:
return prefix + cleanType
case rdl.BaseTypeTimestamp, rdl.BaseTypeUUID:
fullTypeName := rdlPrefix + cleanType
return prefix + fullTypeName
default:
if lrdlType == "struct" {
fullTypeName := rdlPrefix + cleanType
return prefix + fullTypeName
}
}
}
} else {
switch lrdlType {
case "timestamp":
return prefix + rdlPrefix + "Timestamp"
case "uuid":
return prefix + rdlPrefix + "UUID"
case "struct":
return prefix + rdlPrefix + "Struct"
}
}
bt := reg.BaseType(t)
switch bt {
case rdl.BaseTypeAny:
return "interface{}"
case rdl.BaseTypeString:
return "string"
case rdl.BaseTypeSymbol:
return rdlPrefix + "Symbol"
case rdl.BaseTypeBool:
return prefix + "bool"
case rdl.BaseTypeInt8, rdl.BaseTypeInt16, rdl.BaseTypeInt32, rdl.BaseTypeInt64, rdl.BaseTypeFloat32, rdl.BaseTypeFloat64:
return prefix + strings.ToLower(bt.String())
case rdl.BaseTypeArray:
if reference {
name := "Array"
if t.ArrayTypeDef != nil {
name = string(t.ArrayTypeDef.Name)
}
if name != "Array" {
return name
}
}
i := rdl.TypeRef("Any")
switch t.Variant {
case rdl.TypeVariantArrayTypeDef:
i = t.ArrayTypeDef.Items
default:
if items != "" {
i = items
}
}
gitems := goType(reg, i, false, "", "", precise, reference)
return "[]" + gitems
case rdl.BaseTypeMap:
if reference {
//we check if we have defined a type, i.e. the type name is not "Map"
name := rdl.TypeName("Map")
if t.MapTypeDef != nil {
name = t.MapTypeDef.Name
} else if t.AliasTypeDef != nil {
name = t.AliasTypeDef.Name
}
if name != "Map" {
return string(name)
}
}
//.........这里部分代码省略.........