From f8c091326ede98a8acd78542fde48f3abfaf07d5 Mon Sep 17 00:00:00 2001 From: gfanton Date: Wed, 4 Jan 2017 00:35:21 +0100 Subject: [PATCH] Add jstype --- helpers.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/helpers.go b/helpers.go index 4eae222..3519b2e 100644 --- a/helpers.go +++ b/helpers.go @@ -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]