Documentation ¶
Overview ¶
Package data data structure , constant values and global variables used in protoconf generator related code
Index ¶
- Constants
- Variables
- func FlattenLocalPackage(msg *MessageData)
- func GetEnumProtoAndFile(name string) (e *ProtoEnum, file *ProtoFile)
- func GetMessageProtoAndFile(name string) (msg *ProtoMessage, file *ProtoFile)
- func LoadTpl(tplPath string) string
- func Setup(request *plugin.CodeGeneratorRequest)
- type CodeGenerator
- type CommentMap
- type EnumData
- type EnumField
- type GenerateReq
- type MessageData
- type MessageField
- type Method
- type OptionInfo
- type OptionMap
- type ProtoEnum
- type ProtoField
- type ProtoFile
- type ProtoMessage
- type ProtoMethod
- type ProtoOption
- type ProtoService
- type ServiceData
Constants ¶
const ( //IntFieldType datatype string for interge, it is assumed to be of signed and at least 64 bit IntFieldType = "int" //Int32FieldType datatype string for interge 32 bit Int32FieldType = "int32" //Int64FieldType datatype string for interge 64 bit Int64FieldType = "int64" // BooleanFieldType datatype string for boolean BooleanFieldType = "bool" // StringFieldType datatype string for string StringFieldType = "string" // DoubleFieldType datatype string for floating point, it is assumed to be at least of ieee double precision DoubleFieldType = "float64" // PathSeparator the path seperator used to form the full key (ie, key/sub_key ) PathSeparator = "/" // FieldRepeatedLabel is the label for repeated data type FieldRepeatedLabel = "LABEL_REPEATED" // JavaPackageOption is Java package option constant JavaPackageOption = "javaPackageOption" // ServiceAuthOption is service auth option ServiceAuthOption = 51009 // ServiceCommonErrorOption is service common_error option ServiceCommonErrorOption = 51008 // ServiceTypeMethodOption is service method option ServiceTypeMethodOption = 51006 // ErrorTypeMethodOption is error return type option ErrorTypeMethodOption = 51007 // FormatFieldOption is the field type validation field option FormatFieldOption = 51002 // RequiredFieldOption is the required type validation field option RequiredFieldOption = 51003 // ComErrMsgName is common error message name ComErrMsgName = "CommonError" // path numbers in FileDescriptorProto (describe proto file) MessageCommentPath = 4 EnumCommentPath = 5 ServiceCommentPath = 6 // path numbers in DescriptorProto (describe messages) MessageFieldCommentPath = 2 // field MessageNestedCommentPath = 3 // nested MessageEnumCommentPath = 4 // enum // path numbers in EnumDescriptorProto (describe enum) EnumFieldCommentPath = 2 // field // path numbers in ServiceDescriptorProto (describe service) ServiceMethodCommentPath = 2 )
Variables ¶
var FieldOptions = map[int32]OptionInfo{ FormatFieldOption: OptionInfo{"val_format", (*string)(nil), StringFieldType}, RequiredFieldOption: OptionInfo{"val_required", (*bool)(nil), BooleanFieldType}, }
FieldOptions is the map of field number and field name in field options
var MethodOptions = map[int32]OptionInfo{ ServiceTypeMethodOption: OptionInfo{"service_method", (*string)(nil), StringFieldType}, ErrorTypeMethodOption: OptionInfo{"error", (*string)(nil), StringFieldType}, }
MethodOptions is the map of field number and field name in method options
var OutputMap = make(map[string]CodeGenerator)
OutputMap the registra for output code type and its associated output plugin
var ServiceOptions = map[int32]OptionInfo{ ServiceCommonErrorOption: OptionInfo{"common_error", (*string)(nil), StringFieldType}, ServiceAuthOption: OptionInfo{"auth", (*bool)(nil), BooleanFieldType}, }
ServiceOptions is the map of field number and field name in service options
Functions ¶
func FlattenLocalPackage ¶
func FlattenLocalPackage(msg *MessageData)
func GetEnumProtoAndFile ¶
func GetMessageProtoAndFile ¶
func GetMessageProtoAndFile(name string) (msg *ProtoMessage, file *ProtoFile)
func LoadTpl ¶
LoadTpl is the function to load template file as string It loads file content from esc embed by default Set environment variable debugTpl to "true" to load template from disk directly
func Setup ¶
func Setup(request *plugin.CodeGeneratorRequest)
Types ¶
type CodeGenerator ¶
type CodeGenerator interface { Init(request *plugin.CodeGeneratorRequest) Gen(applicationName string, packageName string, services []*ServiceData, messages []*MessageData, enums []*EnumData, options OptionMap) (map[string]string, error) }
type CommentMap ¶
CommentMap map comment to message/service/field path => comment
type EnumData ¶
type EnumData struct { Name string // enum type name Comment string Fields []EnumField // enum entries }
EnumData a structure to represent a enum datatype
type EnumField ¶
type EnumField struct { Name string // enum entry name Value int32 // enum entry value Comment string }
EnumField a enum entry for enum datatype
type GenerateReq ¶
type GenerateReq struct { Files map[string]*ProtoFile PackageMap map[string]*ProtoFile MessageMap map[string]*ProtoMessage EnumMap map[string]*ProtoEnum }
GenerateReq is the code-gen request struct passed to generators
func NewGenerateReq ¶
func NewGenerateReq(request *plugin.CodeGeneratorRequest) *GenerateReq
type MessageData ¶
type MessageData struct { File string // file where this message is defined Name string // name of the message (class, struct) Comment string Fields []*MessageField // message members }
MessageData a structure to represent a message datatype
type MessageField ¶
type MessageField struct { Name string // message variable name DataType string // message variable type Key string // coresponding key name for the variable, default is the same as variable name Label string Comment string Options OptionMap }
MessageField a field for the defined message.
type OptionInfo ¶
type ProtoEnum ¶
type ProtoEnum struct {
Proto *descriptor.EnumDescriptorProto
}
ProtoEnum is a thin wrapper around descriptor.EnumDescriptorProto
func NewProtoEnum ¶
func NewProtoEnum(proto *descriptor.EnumDescriptorProto) *ProtoEnum
NewProtoEnum create ProtoEnum from descriptor.EnumDescriptorProto
type ProtoField ¶
type ProtoField struct { Proto *descriptor.FieldDescriptorProto Options map[string]*ProtoOption }
ProtoField is a thin wrapper around descriptor.FieldDescriptorProto
func NewProtoField ¶
func NewProtoField(proto *descriptor.FieldDescriptorProto) *ProtoField
NewProtoField create ProtoField from descriptor.FieldDescriptorProto
type ProtoFile ¶
type ProtoFile struct { IsFileToGenerate bool Proto *descriptor.FileDescriptorProto Options map[string]*ProtoOption Enums map[string]*ProtoEnum Messages map[string]*ProtoMessage Services map[string]*ProtoService }
ProtoFile is a thin wrapper around descriptor.FileDescriptorProto
func GetProtoFile ¶
func NewProtoFile ¶
func NewProtoFile(proto *descriptor.FileDescriptorProto) *ProtoFile
NewProtoFile create ProtoFile from descriptor.FileDescriptorProto
type ProtoMessage ¶
type ProtoMessage struct { Proto *descriptor.DescriptorProto Options map[string]*ProtoOption Fields map[string]*ProtoField }
ProtoMessage is a thin wrapper around descriptor.DescriptorProto (Message descriptor)
func NewProtoMessage ¶
func NewProtoMessage(proto *descriptor.DescriptorProto) *ProtoMessage
NewProtoMessage create ProtoMessage from descriptor.DescriptorProto
type ProtoMethod ¶
type ProtoMethod struct { Proto *descriptor.MethodDescriptorProto Options map[string]*ProtoOption }
ProtoMethod is a thin wrapper around descriptor.MethodDescriptorProto
func NewProtoMethod ¶
func NewProtoMethod(proto *descriptor.MethodDescriptorProto) *ProtoMethod
NewProtoMethod create ProtoMethod from descriptor.MethodDescriptorProto
type ProtoOption ¶
type ProtoOption struct { }
ProtoOption is a thin wrapper around descriptor.OptionDescriptorProto
type ProtoService ¶
type ProtoService struct { Proto *descriptor.ServiceDescriptorProto Options map[string]*ProtoOption Methods map[string]*ProtoMethod }
ProtoService is a thin wrapper around descriptor.ServiceDescriptorProto
func NewProtoService ¶
func NewProtoService(proto *descriptor.ServiceDescriptorProto) *ProtoService
NewProtoService create ProtoService from descriptor.ServiceDescriptorProto
type ServiceData ¶
type ServiceData struct { Name string Comment string Methods []*Method Options OptionMap CommonErrorType string Service *descriptor.ServiceDescriptorProto }