• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang idl.Type类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/babelrpc/babel/idl.Type的典型用法代码示例。如果您正苦于以下问题:Golang Type类的具体用法?Golang Type怎么用?Golang Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Type类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: ParseType

// ParseType processes a type string and returns the IDL type for it
func ParseType(s string) (*idl.Type, error) {
	var err error
	var t idl.Type
	var m []string
	if m = mapRE.FindStringSubmatch(s); m != nil {
		i := findSplit(m[1])
		if i < 0 {
			return nil, errors.New("Unable to break key/value: " + s)
		}
		t.Name = "map"
		t.KeyType, err = ParseType(m[1][:i])
		if err != nil {
			return nil, err
		}
		if !t.KeyType.IsPrimitive() {
			return nil, errors.New("Key type must be a primitive type: " + s)
		}
		t.ValueType, err = ParseType(m[1][i+1:])
		if err != nil {
			return nil, err
		}
	} else if m = listRE.FindStringSubmatch(s); m != nil {
		t.Name = "list"
		t.ValueType, err = ParseType(m[1])
		if err != nil {
			return nil, err
		}
	} else if m = basicRE.FindStringSubmatch(s); m != nil {
		t.Name = m[1]
	} else {
		return nil, errors.New("Uanble to parse type: " + s)
	}
	return &t, nil
}
开发者ID:babelrpc,项目名称:babel,代码行数:35,代码来源:parsetype.go


示例2: getTypeKey

// getTypeKey return the correct JSON key for the specific type, ie type,ref,or enumRef
func (gen *testGenerator) getTypeKey(t *idl.Type) string {
	var s string
	if t.IsEnum(gen.tplRootIdl) {
		s = "enumRef"
	} else if t.IsStruct(gen.tplRootIdl) {
		s = "ref"
	} else {
		s = "type"
	}
	return s
}
开发者ID:babelrpc,项目名称:babel,代码行数:12,代码来源:test.go


示例3: returnsToSchema

func returnsToSchema(pidl *idl.Idl, t *idl.Type) *swagger2.Schema {
	sc := new(swagger2.Schema)
	// sc.Title = f.Name
	if t.IsVoid() {
		// nil schema means the operation returns no content
		return nil
	} else {
		it := typeToItems(pidl, t)
		sc.Ref = it.Ref
		sc.Type = it.Type
		sc.Format = it.Format
		sc.ItemsDef.Items = it.Items
		sc.Enum = it.Enum
		sc.AdditionalProperties = it.AdditionalProperties
	}
	return sc
}
开发者ID:babelrpc,项目名称:babel,代码行数:17,代码来源:helpers.go


示例4: formatType

// formatType returns the Type as a string in format suitable for C#.
func (gen *csharpGenerator) formatType(t *idl.Type) string {
	var s string
	ms, ok := csharpTypes[t.Name]
	if !ok {
		ms = t.Name
	}
	if t.Name == "list" {
		s = fmt.Sprintf(ms, gen.formatType(t.ValueType))
	} else if t.Name == "map" {
		s = fmt.Sprintf(ms, csharpTypes[t.KeyType.Name], gen.formatType(t.ValueType))
	} else if t.IsPrimitive() && t.Name != "string" {
		s = ms + "?"
	} else if t.IsEnum(gen.tplRootIdl) {
		s = ms + "?"
	} else {
		s = ms
	}
	return s
}
开发者ID:babelrpc,项目名称:babel,代码行数:20,代码来源:csharp.go


示例5: fullTypeName

// fullTypeName returns the fully qualified type name using namespace syntax for go.
// Note: this probably doesn't work.
func (gen *goGenerator) fullTypeName(t *idl.Type) string {
	var s string
	ms, ok := goTypes[t.Name]
	if !ok {
		ms = t.Name
	}
	if t.Name == "list" {
		s = fmt.Sprintf(ms, gen.fullTypeName(t.ValueType))
	} else if t.Name == "map" {
		s = fmt.Sprintf(ms, goTypes[t.KeyType.Name], gen.fullTypeName(t.ValueType))
	} else if t.IsPrimitive() {
		s = "*" + ms
	} else {
		ns := gen.tplRootIdl.NamespaceOf(ms, "go")
		if ns != "" {
			s = fmt.Sprintf("*%s.%s", ns, ms)
		} else {
			s = ms
		}
	}
	return s
}
开发者ID:babelrpc,项目名称:babel,代码行数:24,代码来源:go.go


示例6: isVoid

func (gen *javaGenerator) isVoid(t *idl.Type) bool {
	return t.IsVoid()
}
开发者ID:babelrpc,项目名称:babel,代码行数:3,代码来源:java.go


示例7: toType

func toType(val []string, midl *idl.Idl, typ *idl.Type, fmt rest.ListFmt) (interface{}, error) {
	if typ.IsBool() {
		return strconv.ParseBool(one(val))
	} else if typ.IsInt() {
		if typ.Name == "int64" {
			// int64 is quoted
			return one(val), nil
		} else {
			return strconv.ParseInt(one(val), 10, 32)
		}
	} else if typ.IsString() || typ.IsChar() || typ.IsDatetime() || typ.IsBinary() || typ.IsDecimal() {
		// treat as string - these are all quoted
		return one(val), nil
	} else if typ.IsFloat() {
		return strconv.ParseFloat(one(val), 64)
	} else if typ.IsList() && typ.ValueType.IsPrimitive() {
		var sep string
		switch fmt {
		case rest.CSV:
			sep = ","
		case rest.SSV:
			sep = " "
		case rest.TSV:
			sep = "\t"
		case rest.PIPES:
			sep = "|"
		case rest.MULTI:
		default:
			return nil, errors.New("Format must be specified when lists are encoded.")
		}
		vals := make([]interface{}, 0)
		var arr []string
		if sep != "" {
			arr = strings.Split(one(val), sep)
		} else {
			if val == nil {
				arr = []string{}
			} else {
				arr = val
			}
		}
		for _, s := range arr {
			v, err := toType([]string{s}, midl, typ.ValueType, rest.NONE)
			if err != nil {
				return nil, err
			}
			vals = append(vals, v)
		}
		return vals, nil
	} else if typ.IsEnum(midl) {
		// treat as string - quoted
		return one(val), nil
	}

	// all other types are custom
	// in theory maybe maps could be handled?
	return nil, errors.New("Unexpected type: " + typ.String())
}
开发者ID:babelrpc,项目名称:babel,代码行数:58,代码来源:handlers.go


示例8: typeToItems

func typeToItems(pidl *idl.Idl, t *idl.Type) *swagger2.ItemsDef {
	it := new(swagger2.ItemsDef)
	it.Ref = ""
	if t.IsPrimitive() {
		it.Format = t.String()
		if t.IsInt() || t.IsByte() {
			it.Type = "integer"
			it.Format = "int32"
			if t.Name == "int64" {
				if swagInt && restful {
					// Swagger style int64
					it.Format = "int64"
				} else {
					// Babel style int64
					it.Type = "string"  // ??? Babel quotes large integers to avoid precision loss in JavaScript
					it.Format = "int64" // SWAGGER-CLARIFICATION: is format int64 legal with type string?
				}
			}
		} else if t.IsFloat() {
			it.Type = "number"
			it.Format = "float"
			if t.Name == "float64" {
				it.Format = "double"
			}
		} else if t.IsBool() {
			it.Type = "boolean"
			it.Format = ""
		} else if t.IsDatetime() {
			it.Type = "string"
			it.Format = "date-time"
		} else if t.IsDecimal() {
			it.Type = "string"
			it.Format = ""
		} else if t.IsString() || t.IsChar() {
			it.Type = "string"
			it.Format = ""
		}
	} else if t.IsBinary() {
		it.Type = "string"
		it.Format = "byte"
	} else if t.IsMap() {
		it.Type = "object"
		// hmmm....what to do if keytype is not string?
		// SWAGGER-CLARIFICATION: Does swagger require all key types to be strings?
		it.AdditionalProperties = typeToItems(pidl, t.ValueType)
	} else if t.IsList() {
		it.Type = "array"
		it.Format = ""
		it.Items = typeToItems(pidl, t.ValueType)
	} else if t.IsEnum(pidl) {
		// SWAGGER-BUG: Enums cannot be delared in a schema
		it.Type = "string"
		it.Format = ""
		it.Enum = make([]interface{}, 0)
		e := pidl.FindEnum(t.Name)
		if e != nil {
			for _, x := range e.Values {
				it.Enum = append(it.Enum, x.Name)
			}
		}
	} else {
		// user-defined, struct or enum
		it.Ref = "#/definitions/" + t.Name
	}
	return it
}
开发者ID:babelrpc,项目名称:babel,代码行数:66,代码来源:helpers.go


示例9: formatType

// formatType returns the Type as a string in format suitable for C#.
func (gen *goGenerator) formatType(t *idl.Type) string {
	var s string
	ms, ok := goTypes[t.Name]
	if !ok {
		ms = t.Name
	}
	if t.IsList() {
		s = fmt.Sprintf(ms, gen.formatType(t.ValueType))
	} else if t.IsMap() {
		s = fmt.Sprintf(ms, goTypes[t.KeyType.Name], gen.formatType(t.ValueType))
	} else if t.IsBinary() {
		s = ms
	} else if t.IsPrimitive() {
		s = "*" + ms
	} else if t.IsEnum(gen.tplRootIdl) {
		s = "*" + ms
	} else if t.IsVoid() {
		s = ""
	} else {
		s = "*" + ms
	}
	return s
}
开发者ID:babelrpc,项目名称:babel,代码行数:24,代码来源:go.go


示例10: isTrivialProperty

func (gen *csharpGenerator) isTrivialProperty(t *idl.Type) bool {
	return t.IsPrimitive() || t.Name == "binary" || t.IsEnum(gen.tplRootIdl)
}
开发者ID:babelrpc,项目名称:babel,代码行数:3,代码来源:csharp.go


示例11: isVoid

func (gen *csharpGenerator) isVoid(t *idl.Type) bool {
	return t.IsVoid()
}
开发者ID:babelrpc,项目名称:babel,代码行数:3,代码来源:csharp.go



注:本文中的github.com/babelrpc/babel/idl.Type类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang evego.Database类代码示例发布时间:2022-05-24
下一篇:
Golang idl.Idl类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap