当前位置: 首页>>代码示例>>Golang>>正文


Golang Type.IsByte方法代码示例

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


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

示例1: 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


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