當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Idl.FindEnum方法代碼示例

本文整理匯總了Golang中github.com/babelrpc/babel/idl.Idl.FindEnum方法的典型用法代碼示例。如果您正苦於以下問題:Golang Idl.FindEnum方法的具體用法?Golang Idl.FindEnum怎麽用?Golang Idl.FindEnum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/babelrpc/babel/idl.Idl的用法示例。


在下文中一共展示了Idl.FindEnum方法的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.Idl.FindEnum方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。