Documentation ¶
Overview ¶
Package generator contains functions for generating transform functions.
Index ¶
- Variables
- func OptHelpers(packageName string) string
- func ProcessFile(f *descriptor.FileDescriptorProto, packageName, helperPackageName *string, ...) (string, string, error)
- func SetParameters(setter Setter, param *string) error
- func Version() string
- type Data
- type Field
- type MessageOption
- type MessageOptionList
- type OneofData
- type Setter
- type WriteStringer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNilOptions appears when object has no options. // // Options defined as // // messages MessageName { // option (package.message_option_name) = value; // int64 first_field = 1 [(package.field_option_name = value)]; // } ErrNilOptions = errors.New("options are nil") // ErrFileSkipped is returned when .proto file has not go_models_file_path // option. ErrFileSkipped = errors.New("files was skipped") )
Functions ¶
func OptHelpers ¶
OptHelpers returns file content with optional functions for using options with transformations.
func ProcessFile ¶
func ProcessFile(f *descriptor.FileDescriptorProto, packageName, helperPackageName *string, messages MessageOptionList, debug, usePackageInPath bool) (string, string, error)
ProcessFile processes .proto file and returns content as a string.
func SetParameters ¶
SetParameters accepts flag.CommandLine as a setter, string with params from protobuf compile input. Functions decodes params and adds it as command line flags.
Types ¶
type Data ¶
type Data struct { // Prefix for source structure. SrcPref string // Source structure name. Src string // Left (source) part of transform function name. SrcFn string // Contains "*" if source structure is a pointer. SrcPointer string // Prefix for destination structure. DstPref string // Destination structure name. Dst string // Right (destination) part of transform function name. DstFn string // Contains "*" if destination structure is a pointer. DstPointer string // Field list of structure. Fields []Field // If true Fields.GoToProtoType will be used instead of Fileds.ProtoToGoType. Swapped bool // Is not empty, package name will be used as prefix for helper functions, // such as TimeToNullTime, StringToStirnPtr etc. HelperPackage string // Ptr is used in template for indication of pointer usage. Ptr bool }
Data contains data for fill out template.
type Field ¶
type Field struct { // Field name in Go structure. Name string // Field name in .proto file. ProtoName string // Field type in .proto file. ProtoType string // Name of function which is used for converting proto field into Go one. ProtoToGoType string // Name of function which is used for converting Go field into proto one. GoToProtoType string // True if field in model is a pointer. GoIsPointer bool // True if field in .proto file has an option gogoproto.nullable = false ProtoIsPointer bool // It true, field GoToProtoType and ProtoToGoType functions will be used // with prefix. UsePackage bool // The field has a value when it is used for the oneof migration from Int64 to String for the field // TODO: This is a specific case of OneOf which is used by BoldCommerce and needs to be removed from the plugin. // This field will be deprecated together with oneof.go once BoldCommerce update their code OneofDecl string Opts string }
Field represents one structure field.
type MessageOption ¶
type MessageOption interface { // Returns model name from go_struct option. Target() string // Full returns FQTN of proto type, such as "google.protobuf.Timestamp" and // so on. Full() string // If true, proto message has not target struct, i.e. go_struct option is // empty or not found. Omitted() bool // Returns Oneof message name. OneofDecl() string }
MessageOption represents protobuf message options.
type MessageOptionList ¶
type MessageOptionList map[string]MessageOption
MessageOptionList is a list of proto message option. Map key is a message name with Full Qualified Type Name (FQTN), format like ".google.protobuf.Timestamp".
func CollectAllMessages ¶
func CollectAllMessages(req plugin.CodeGeneratorRequest) (MessageOptionList, error)
CollectAllMessages processes all files passed within plugin request to collect info about all incoming messages. Generator should have information about all messages regardless have those messages transformer options or haven't.
func (MessageOptionList) String ¶
func (sol MessageOptionList) String() string
type OneofData ¶
type OneofData struct { // Package name form proto file. ProtoPackage string // Custom data type from proto file which is used for define oneof field. ProtoType string // Go destination type. GoType string Decl string OneofDecl string }
OneofData contains info about OneOf fields.
message TheOne{ <= OneofType oneof strint { <= OneofDecl string string_value = 1; int64 int64_value = 2; } }