Merge pull request #39 from gfanton/add-jstype-helper

Add jstype
This commit is contained in:
Manfred Touron 2017-01-04 07:40:05 +01:00 committed by GitHub
commit 6b43c020b1

View File

@ -67,6 +67,7 @@ var ProtoHelpersFuncMap = template.FuncMap{
"isFieldMessage": isFieldMessage, "isFieldMessage": isFieldMessage,
"isFieldRepeated": isFieldRepeated, "isFieldRepeated": isFieldRepeated,
"goType": goType, "goType": goType,
"jsType": jsType,
"httpVerb": httpVerb, "httpVerb": httpVerb,
"httpPath": httpPath, "httpPath": httpPath,
} }
@ -139,6 +140,35 @@ func goType(pkg string, f *descriptor.FieldDescriptorProto) string {
} }
} }
func jsType(f *descriptor.FieldDescriptorProto) string {
switch *f.Type {
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
return "number"
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
return "number"
case descriptor.FieldDescriptorProto_TYPE_INT64:
return "number"
case descriptor.FieldDescriptorProto_TYPE_UINT64:
return "number"
case descriptor.FieldDescriptorProto_TYPE_INT32:
return "number"
case descriptor.FieldDescriptorProto_TYPE_BOOL:
return "boolean"
case descriptor.FieldDescriptorProto_TYPE_STRING:
return "string"
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
return "message"
case descriptor.FieldDescriptorProto_TYPE_BYTES:
return "number"
case descriptor.FieldDescriptorProto_TYPE_UINT32:
return "number"
case descriptor.FieldDescriptorProto_TYPE_ENUM:
return "message"
default:
return "object"
}
}
func shortType(s string) string { func shortType(s string) string {
t := strings.Split(s, ".") t := strings.Split(s, ".")
return t[len(t)-1] return t[len(t)-1]