Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
Flags flag.FlagSet
)
View Source
var ProtoHelpersFuncMap = template.FuncMap{ "string": func(i interface { String() string }) string { return i.String() }, "json": func(v interface{}) string { a, err := json.Marshal(v) if err != nil { return err.Error() } return string(a) }, "prettyjson": func(v interface{}) string { a, err := json.MarshalIndent(v, "", " ") if err != nil { return err.Error() } return string(a) }, "splitArray": func(sep string, s string) []interface{} { var r []interface{} t := strings.Split(s, sep) for i := range t { if t[i] != "" { r = append(r, t[i]) } } return r }, "first": func(a []string) string { return a[0] }, "last": func(a []string) string { return a[len(a)-1] }, "concat": func(a string, b ...string) string { return strings.Join(append([]string{a}, b...), "") }, "join": func(sep string, a ...string) string { return strings.Join(a, sep) }, "upperFirst": func(s string) string { return strings.ToUpper(s[:1]) + s[1:] }, "lowerFirst": func(s string) string { return strings.ToLower(s[:1]) + s[1:] }, "camelCase": func(s string) string { if len(s) > 1 { res := xstrings.ToCamelCase(s) return strings.ToUpper(res[:1]) + res[1:] } return strings.ToUpper(s[:1]) }, "lowerCamelCase": func(s string) string { if len(s) > 1 { s = xstrings.ToCamelCase(s) } return strings.ToLower(s[:1]) + s[1:] }, "upperCase": func(s string) string { return strings.ToUpper(s) }, "kebabCase": func(s string) string { return strings.Replace(xstrings.ToSnakeCase(s), "_", "-", -1) }, "contains": func(sub, s string) bool { return strings.Contains(s, sub) }, "trimstr": func(cutset, s string) string { return strings.Trim(s, cutset) }, "index": func(array interface{}, i int) interface{} { slice := reflect.ValueOf(array) if slice.Kind() != reflect.Slice { panic("Error in index(): given a non-slice type") } if i < 0 || i >= slice.Len() { panic("Error in index(): index out of bounds") } return slice.Index(i).Interface() }, "add": func(a int, b int) int { return a + b }, "subtract": func(a int, b int) int { return a - b }, "multiply": func(a int, b int) int { return a * b }, "divide": func(a int, b int) int { if b == 0 { panic("psssst ... little help here ... you cannot divide by 0") } return a / b }, "snakeCase": xstrings.ToSnakeCase, "getProtoFile": getProtoFile, "getMessageType": getMessageType, "getEnumValue": getEnumValue, "isFieldMessage": isFieldMessage, "isFieldMessageTimeStamp": isFieldMessageTimeStamp, "isFieldRepeated": isFieldRepeated, "haskellType": haskellType, "goType": goType, "goZeroValue": goZeroValue, "goTypeWithPackage": goTypeWithPackage, "goTypeWithGoPackage": goTypeWithGoPackage, "jsType": jsType, "jsSuffixReserved": jsSuffixReservedKeyword, "namespacedFlowType": namespacedFlowType, "httpVerb": httpVerb, "httpPath": httpPath, "httpPathsAdditionalBindings": httpPathsAdditionalBindings, "httpBody": httpBody, "shortType": shortType, "urlHasVarsFromMessage": urlHasVarsFromMessage, "lowerGoNormalize": lowerGoNormalize, "goNormalize": goNormalize, "leadingComment": leadingComment, "trailingComment": trailingComment, "leadingDetachedComments": leadingDetachedComments, "stringFileOptionsExtension": stringFileOptionsExtension, "stringMessageExtension": stringMessageExtension, "stringFieldExtension": stringFieldExtension, "int64FieldExtension": int64FieldExtension, "int64MessageExtension": int64MessageExtension, "stringMethodOptionsExtension": stringMethodOptionsExtension, "boolMethodOptionsExtension": boolMethodOptionsExtension, "boolMessageExtension": boolMessageExtension, "boolFieldExtension": boolFieldExtension, "isFieldMap": isFieldMap, "fieldMapKeyType": fieldMapKeyType, "fieldMapValueType": fieldMapValueType, "replaceDict": replaceDict, "setStore": setStore, "getStore": getStore, "goPkg": goPkg, "goPkgLastElement": goPkgLastElement, "cppType": cppType, "cppTypeWithPackage": cppTypeWithPackage, "rustType": rustType, "rustTypeWithPackage": rustTypeWithPackage, "fieldType": getFieldType, "isMessage": func(f *descriptor.FieldDescriptorProto) bool { return *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE }, "isMessageArray": func(f *descriptor.FieldDescriptorProto) bool { return *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE && f.Label != nil && *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED }, "isArray": func(f *descriptor.FieldDescriptorProto) bool { return f.Label != nil && *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED }, "isEnumArray": func(f *descriptor.FieldDescriptorProto) bool { return *f.Type == descriptor.FieldDescriptorProto_TYPE_ENUM && f.Label != nil && *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED }, "isEnum": func(f *descriptor.FieldDescriptorProto) bool { return *f.Type == descriptor.FieldDescriptorProto_TYPE_ENUM }, "isOneOf": func(f *descriptor.FieldDescriptorProto) bool { return f.OneofIndex != nil && (f.Proto3Optional == nil || *f.Proto3Optional == false) }, "oneOfFiledName": func(message *descriptor.DescriptorProto, field *descriptor.FieldDescriptorProto) string { if field.OneofIndex == nil { return "" } idx := int(field.GetOneofIndex()) if idx >= len(message.OneofDecl) { return "" } if message.OneofDecl[idx].Name == nil { return "" } return *message.OneofDecl[idx].Name }, "oneOfFiledType": func(message *descriptor.DescriptorProto, field *descriptor.FieldDescriptorProto) string { if field.OneofIndex == nil { return "" } idx := int(field.GetOneofIndex()) if idx >= len(message.OneofDecl) { return "" } if message.Name == nil { return "" } return *message.Name }, "getMethodArgType": func(arg *string) string { if arg == nil { return "nil" } parts := strings.Split(*arg, ".") return parts[len(parts)-1] }, }
Functions ¶
func InitPathMap ¶
func InitPathMap(file *descriptor.FileDescriptorProto)
func InitPathMaps ¶
func InitPathMaps(files []*descriptor.FileDescriptorProto)
func SetRegistry ¶
func SetRegistry(reg *ggdescriptor.Registry)
Types ¶
type Ast ¶
type Ast struct {
BuildDate time.Time `json:"build-date"`
BuildHostname string `json:"build-hostname"`
BuildUser string `json:"build-user"`
GoPWD string `json:"go-pwd,omitempty"`
PWD string `json:"pwd"`
Debug bool `json:"debug"`
DestinationDir string `json:"destination-dir"`
File *protogen.File `json:"file"`
RawFilename string `json:"raw-filename"`
Filename string `json:"filename"`
TemplateDir string `json:"template-dir"`
Service *descriptor.ServiceDescriptorProto `json:"service"`
Enum []*descriptor.EnumDescriptorProto `json:"enum"`
}
type GenericTemplateBasedEncoder ¶
type GenericTemplateBasedEncoder struct {
// contains filtered or unexported fields
}
func NewGenericServiceTemplateBasedEncoder ¶
func NewGenericServiceTemplateBasedEncoder(templateDir string, service *descriptor.ServiceDescriptorProto, file *protogen.File, debug bool, destinationDir string) (e *GenericTemplateBasedEncoder)
func (*GenericTemplateBasedEncoder) Files ¶
func (e *GenericTemplateBasedEncoder) Files() []*plugin_go.CodeGeneratorResponse_File
Click to show internal directories.
Click to hide internal directories.