Add jstype

This commit is contained in:
gfanton 2017-01-04 00:35:21 +01:00
parent 83f2bd1514
commit f8c091326e

View File

@ -60,6 +60,7 @@ var ProtoHelpersFuncMap = template.FuncMap{
"isFieldMessage": isFieldMessage,
"isFieldRepeated": isFieldRepeated,
"goType": goType,
"jsType": jsType,
"httpVerb": httpVerb,
"httpPath": httpPath,
}
@ -132,6 +133,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 {
t := strings.Split(s, ".")
return t[len(t)-1]