本文整理汇总了Golang中github.com/ardielle/ardielle-go/rdl.TypeRegistry.FindType方法的典型用法代码示例。如果您正苦于以下问题:Golang TypeRegistry.FindType方法的具体用法?Golang TypeRegistry.FindType怎么用?Golang TypeRegistry.FindType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ardielle/ardielle-go/rdl.TypeRegistry
的用法示例。
在下文中一共展示了TypeRegistry.FindType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: javaGenerateStructTypeConstructor
func javaGenerateStructTypeConstructor(reg rdl.TypeRegistry, t *rdl.StructTypeDef) string {
s := fmt.Sprintf(" sb.structType(%q", t.Name)
if t.Type != "Struct" {
s += fmt.Sprintf(", %q)", t.Type)
} else {
s += ")"
}
if t.Comment != "" {
s += fmt.Sprintf("\n .comment(%q)", t.Comment)
}
for _, f := range t.Fields {
if f.Keys != "" {
fkeys := string(f.Keys) //javaType(reg, f.Keys, false, "", "")
fitems := string(f.Items) //javaType(reg, f.Items, false, "", "")
s += fmt.Sprintf("\n .mapField(%q, %q, %q, %v, %q)", f.Name, fkeys, fitems, f.Optional, f.Comment)
} else if f.Items != "" {
fitems := string(f.Items) //javaType(reg, f.Items, false, "", "")
s += fmt.Sprintf("\n .arrayField(%q, %q, %v, %q)", f.Name, fitems, f.Optional, f.Comment)
} else {
ftype := string(f.Type) //javaType(reg, f.Type, f.Optional, "", "")
if f.Default != nil {
ft := reg.FindType(f.Type)
ss := "null"
if ft != nil {
ss = javaLiteral(ft, f.Default)
}
s += fmt.Sprintf("\n .field(%q, %q, %v, %q, %s)", f.Name, ftype, false, f.Comment, ss)
} else {
s += fmt.Sprintf("\n .field(%q, %q, %v, %q)", f.Name, ftype, f.Optional, f.Comment)
}
}
}
return s + ";"
}
示例2: annotate
func annotate(registry rdl.TypeRegistry, typename rdl.TypeRef) string {
t := registry.FindType(typename)
if t != nil {
tName, tType, _ := rdl.TypeInfo(t)
if tType != rdl.TypeRef(tName) {
return "[" + string(typename) + "](#" + strings.ToLower(string(typename)) + ")"
}
}
return string(typename)
}
示例3: typeStack
func typeStack(registry rdl.TypeRegistry, typeDef *rdl.Type) []*rdl.Type {
var types []*rdl.Type
types = append(types, typeDef)
tName, tType, _ := rdl.TypeInfo(typeDef)
for tName != rdl.TypeName(tType) {
supertype := registry.FindType(tType)
types = append(types, supertype)
tName, tType, _ = rdl.TypeInfo(supertype)
}
return types
}
示例4: addFields
func addFields(reg rdl.TypeRegistry, dst []*rdl.StructFieldDef, t *rdl.Type) []*rdl.StructFieldDef {
switch t.Variant {
case rdl.TypeVariantStructTypeDef:
st := t.StructTypeDef
if st.Type != "Struct" {
dst = addFields(reg, dst, reg.FindType(st.Type))
}
for _, f := range st.Fields {
dst = append(dst, f)
}
}
return dst
}
示例5: javaGenerateResourceConstructor
func javaGenerateResourceConstructor(reg rdl.TypeRegistry, rez *rdl.Resource) string {
rTypeName := rez.Type
if rez.Method == "PUT" || rez.Method == "POST" {
for _, ri := range rez.Inputs {
if !ri.PathParam && ri.QueryParam == "" && ri.Header == "" {
rTypeName = ri.Type
break
}
}
}
s := fmt.Sprintf(" sb.resource(%q, %q, %q)", rTypeName, rez.Method, rez.Path)
if rez.Comment != "" {
s += fmt.Sprintf("\n .comment(%q)", rez.Comment)
}
for _, ri := range rez.Inputs {
def := "null"
if ri.Default != nil {
ft := reg.FindType(ri.Type)
if ft != nil {
def = javaLiteral(ft, ri.Default)
}
}
if ri.PathParam {
s += fmt.Sprintf("\n .pathParam(%q, %q, %q)", ri.Name, ri.Type, ri.Comment)
} else if ri.QueryParam != "" {
s += fmt.Sprintf("\n .queryParam(%q, %q, %q, %s, %q)", ri.QueryParam, ri.Name, ri.Type, def, ri.Comment)
} else if ri.Header != "" {
s += fmt.Sprintf("\n .headerParam(%q, %q, %q, %s, %q)", ri.Header, ri.Name, ri.Type, def, ri.Comment)
} else {
s += fmt.Sprintf("\n .input(%q, %q, %q)", ri.Name, ri.Type, ri.Comment)
}
}
for _, ro := range rez.Outputs {
s += fmt.Sprintf("\n .output(%q, %q, %q, %q)", ro.Header, ro.Name, ro.Type, ro.Comment)
}
if rez.Auth != nil {
if rez.Auth.Domain != "" {
s += fmt.Sprintf("\n .auth(%q, %q, %v, %q)", rez.Auth.Action, rez.Auth.Resource, rez.Auth.Authenticate, rez.Auth.Domain)
} else if rez.Auth.Authenticate {
s += fmt.Sprintf("\n .auth(%q, %q, true)", rez.Auth.Action, rez.Auth.Resource)
} else {
s += fmt.Sprintf("\n .auth(%q, %q)", rez.Auth.Action, rez.Auth.Resource)
}
}
s += fmt.Sprintf("\n .expected(%q)", rez.Expected)
//build a sorted order for the exceptions, to make them predictable. Go randomizes the order otherwise.
var syms []string
for sym, _ := range rez.Exceptions {
syms = append(syms, sym)
}
sort.Strings(syms)
for _, sym := range syms {
re := rez.Exceptions[sym]
s += fmt.Sprintf("\n .exception(%q, %q, %q)\n", sym, re.Type, re.Comment)
}
if rez.Async != nil {
if *rez.Async {
s += fmt.Sprintf("\n .async()\n")
}
}
return s + ";"
}
示例6: goParamInit
func goParamInit(reg rdl.TypeRegistry, qname string, pname string, ptype rdl.TypeRef, pdefault interface{}, poptional bool, precise bool, prefixEnums bool) string {
s := ""
gtype := goType(reg, ptype, false, "", "", precise, true)
switch gtype {
/*
case "string":
if pdefault == nil {
s += "\t" + pname + " := rdl.OptionalStringParam(request, \"" + qname + "\")\n"
} else {
def := fmt.Sprintf("%v", pdefault)
s += "\tvar " + pname + "Optional " + gtype + " = " + def + "\n"
s += "\t" + pname + ", _ := rdl.StringParam(request, \"" + qname + "\", " + pname + "Optional)\n"
}
case "bool":
if pdefault == nil {
s += "\t" + pname + ", err := rdl.OptionalBoolParam(request, \"" + qname + "\")\n"
s += "\tif err != nil {\n"
s += "\t\trdl.JSONResponse(writer, 400, err)\n"
s += "\t\treturn\n"
s += "\t}\n"
} else {
def := fmt.Sprintf("%v", pdefault)
s += "\tvar " + pname + "Optional " + gtype + " = " + def + "\n"
s += "\t" + pname + " := rdl.BoolParam(request, \"" + qname + "\", " + pname + "Optional)\n"
}
case "int32", "int64", "int16", "int8":
if pdefault == nil {
s += "\t" + pname + ", err := rdl.OptionalInt32Param(request, \"" + qname + "\")\n"
s += "\tif err != nil {\n\t\trdl.JSONResponse(writer, 400, err)\n\t\treturn\n\t}\n"
} else {
def := "0"
switch v := pdefault.(type) {
case float64:
def = fmt.Sprintf("%v", v)
default:
fmt.Println("fix me:", pdefault)
panic("fix me")
}
if precise {
s += "\t" + pname + "_, err := rdl.Int32Param(request, \"" + qname + "\", " + def + ")\n"
} else {
s += "\t" + pname + ", err := rdl.Int32Param(request, \"" + qname + "\", " + def + ")\n"
}
s += "\tif err != nil {\n\t\trdl.JSONResponse(writer, 400, err)\n\t\treturn\n\t}\n"
if precise {
s += "\t" + pname + " := " + gtype + "(" + pname + "_)\n"
}
}
*/
default:
t := reg.FindType(ptype)
bt := reg.BaseType(t)
switch bt {
case rdl.BaseTypeString:
if pdefault == nil {
if precise && gtype != "string" {
s += "\t" + pname + " := " + gtype + "(rdl.OptionalStringParam(request, \"" + qname + "\"))\n"
} else {
s += "\t" + pname + " := rdl.OptionalStringParam(request, \"" + qname + "\")\n"
}
} else {
def := fmt.Sprintf("%q", pdefault)
if precise && gtype != "string" {
s += "\t" + pname + "Val, _ := rdl.StringParam(request, \"" + qname + "\", " + def + ")\n"
s += "\t" + pname + " := " + gtype + "(" + pname + "Val)\n"
} else {
s += "\t" + pname + ", _ := rdl.StringParam(request, \"" + qname + "\", " + def + ")\n"
}
}
case rdl.BaseTypeInt32, rdl.BaseTypeInt16, rdl.BaseTypeInt8, rdl.BaseTypeInt64, rdl.BaseTypeFloat32, rdl.BaseTypeFloat64:
stype := fmt.Sprint(bt)
if pdefault == nil {
s += "\t" + pname + ", err := rdl.Optional" + stype + "Param(request, \"" + qname + "\")\n" //!
s += "\tif err != nil {\n\t\trdl.JSONResponse(writer, 400, err)\n\t\treturn\n\t}\n"
} else {
def := "0"
switch v := pdefault.(type) {
case float64:
def = fmt.Sprintf("%v", v)
default:
fmt.Println("fix me:", pdefault)
panic("fix me")
}
if precise {
s += "\t" + pname + "_, err := rdl." + stype + "Param(request, \"" + qname + "\", " + def + ")\n"
} else {
s += "\t" + pname + ", err := rdl." + stype + "Param(request, \"" + qname + "\", " + def + ")\n"
}
s += "\tif err != nil {\n\t\trdl.JSONResponse(writer, 400, err)\n\t\treturn\n\t}\n"
if precise {
s += "\t" + pname + " := " + gtype + "(" + pname + "_)\n"
}
}
case rdl.BaseTypeBool:
if pdefault == nil {
s += "\t" + pname + ", err := rdl.OptionalBoolParam(request, \"" + qname + "\")\n"
s += "\tif err != nil {\n"
s += "\t\trdl.JSONResponse(writer, 400, err)\n"
s += "\t\treturn\n"
s += "\t}\n"
//.........这里部分代码省略.........
示例7: javaType
func javaType(reg rdl.TypeRegistry, rdlType rdl.TypeRef, optional bool, items rdl.TypeRef, keys rdl.TypeRef) string {
t := reg.FindType(rdlType)
if t == nil || t.Variant == 0 {
panic("Cannot find type '" + rdlType + "'")
}
bt := reg.BaseType(t)
switch bt {
case rdl.BaseTypeAny:
return "Object"
case rdl.BaseTypeString:
return "String"
case rdl.BaseTypeSymbol, rdl.BaseTypeTimestamp, rdl.BaseTypeUUID:
return string(rdlType)
case rdl.BaseTypeBool:
if optional {
return "Boolean"
}
return "boolean"
case rdl.BaseTypeInt8:
if optional {
return "Byte"
}
return "byte"
case rdl.BaseTypeInt16:
if optional {
return "Short"
}
return "short"
case rdl.BaseTypeInt32:
if optional {
return "Integer"
}
return "int"
case rdl.BaseTypeInt64:
if optional {
return "Long"
}
return "long"
case rdl.BaseTypeFloat32:
if optional {
return "Float"
}
return "float"
case rdl.BaseTypeFloat64:
if optional {
return "Double"
}
return "double"
case rdl.BaseTypeArray:
i := rdl.TypeRef("Any")
switch t.Variant {
case rdl.TypeVariantArrayTypeDef:
i = t.ArrayTypeDef.Items
default:
if items != "" && items != "Any" {
i = items
}
}
gitems := javaType(reg, rdl.TypeRef(i), false, "", "")
//return gitems + "[]" //if arrays, not lists
return "List<" + gitems + ">"
case rdl.BaseTypeMap:
k := rdl.TypeRef("Any")
i := rdl.TypeRef("Any")
switch t.Variant {
case rdl.TypeVariantMapTypeDef:
k = t.MapTypeDef.Keys
i = t.MapTypeDef.Items
default:
if keys != "" && keys != "Any" {
k = keys
}
if items != "" && items != "Any" {
i = items
}
}
gkeys := javaType(reg, k, false, "", "")
gitems := javaType(reg, i, false, "", "")
return "Map<" + gkeys + ", " + gitems + ">"
case rdl.BaseTypeStruct:
if strings.HasPrefix(string(rdlType), "rdl.") {
return string(rdlType)[4:]
}
switch t.Variant {
case rdl.TypeVariantStructTypeDef:
if t.StructTypeDef.Name == "Struct" {
return "Object"
}
}
return string(rdlType)
default:
return string(rdlType)
}
}
示例8: 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)
}
}
//.........这里部分代码省略.........
示例9: makeSwaggerTypeDef
func makeSwaggerTypeDef(reg rdl.TypeRegistry, t *rdl.Type) *SwaggerType {
st := new(SwaggerType)
bt := reg.BaseType(t)
switch t.Variant {
case rdl.TypeVariantStructTypeDef:
typedef := t.StructTypeDef
st.Description = typedef.Comment
props := make(map[string]*SwaggerType)
var required []string
if len(typedef.Fields) > 0 {
for _, f := range typedef.Fields {
if f.Optional {
required = append(required, string(f.Name))
}
ft := reg.FindType(f.Type)
fbt := reg.BaseType(ft)
prop := new(SwaggerType)
prop.Description = f.Comment
switch fbt {
case rdl.BaseTypeArray:
prop.Type = "array"
if f.Items != "" {
fitems := string(f.Items)
items := new(SwaggerType)
switch fitems {
case "String":
items.Type = strings.ToLower(fitems)
case "Int32", "Int64", "Int16":
items.Type = "integer"
items.Format = strings.ToLower(fitems)
default:
items.Ref = "#/definitions/" + fitems
}
prop.Items = items
}
case rdl.BaseTypeString:
prop.Type = strings.ToLower(fbt.String())
case rdl.BaseTypeInt32, rdl.BaseTypeInt64, rdl.BaseTypeInt16:
prop.Type = "integer"
prop.Format = strings.ToLower(fbt.String())
case rdl.BaseTypeStruct:
prop.Type = "#/definitions/" + string(f.Type)
case rdl.BaseTypeMap:
prop.Type = "object"
if f.Items != "" {
fitems := string(f.Items)
items := new(SwaggerType)
switch f.Items {
case "String":
items.Type = strings.ToLower(fitems)
case "Int32", "Int64", "Int16":
items.Type = "integer"
items.Format = strings.ToLower(fitems)
default:
items.Ref = "#/definitions/" + fitems
}
prop.AdditionalProperties = items
}
default:
prop.Type = "_" + string(f.Type) + "_" //!
}
props[string(f.Name)] = prop
}
}
st.Properties = props
if len(required) > 0 {
st.Required = required
}
case rdl.TypeVariantArrayTypeDef:
typedef := t.ArrayTypeDef
st.Type = bt.String()
if typedef.Items != "Any" {
items := new(SwaggerType)
switch reg.FindBaseType(typedef.Items) {
case rdl.BaseTypeString:
items.Type = strings.ToLower(string(typedef.Items))
case rdl.BaseTypeInt32, rdl.BaseTypeInt64, rdl.BaseTypeInt16:
items.Type = "integer"
items.Format = strings.ToLower(string(typedef.Items))
default:
items.Ref = "#/definitions/" + string(typedef.Items)
}
st.Items = items
}
case rdl.TypeVariantEnumTypeDef:
typedef := t.EnumTypeDef
var tmp []string
for _, el := range typedef.Elements {
tmp = append(tmp, string(el.Symbol))
}
st.Enum = tmp
case rdl.TypeVariantUnionTypeDef:
typedef := t.UnionTypeDef
fmt.Println("[" + typedef.Name + ": Swagger doesn't support unions]")
default:
switch bt {
case rdl.BaseTypeString, rdl.BaseTypeInt16, rdl.BaseTypeInt32, rdl.BaseTypeInt64, rdl.BaseTypeFloat32, rdl.BaseTypeFloat64:
return nil
default:
panic(fmt.Sprintf("whoops: %v", t))
//.........这里部分代码省略.........