Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrGenerateCommandIsNil is returned when the generate function is nil. ErrGenerateCommandIsNil = errors.New("generate command is nil") // ErrRequestCompilerVersionIsNil is returned when the request compiler version is nil. ErrRequestCompilerVersionIsNil = errors.New("request compiler version is nil") // ErrProtoFileNameIsEmpty is returned when the proto file name is empty. ErrProtoFileNameIsEmpty = errors.New("proto file name is empty") // ErrFileDescriptorIsNil is returned when the file descriptor is nil. ErrFileDescriptorIsNil = errors.New("file descriptor is nil") // ErrDuplicateProtoFile is returned when the proto file is duplicated. ErrDuplicateProtoFile = errors.New("duplicate proto file") // ErrFileHasNoKnownDescriptor is returned when the file has no known descriptor. ErrFileHasNoKnownDescriptor = errors.New("file has no known descriptor") // ErrUnableToParseOptions is returned when the options are unable to be parsed. ErrUnableToParseOptions = errors.New("unable to parse options") // ErrGeneratedFileHasNoContent is returned when the generated file has no content. ErrGeneratedFileHasNoContent = errors.New("generated file has no content") )
Functions ¶
This section is empty.
Types ¶
type GenerateCommand ¶
type GenerateCommand struct {
Name string
Version string
MinimumEdition descriptorpb.Edition
MaximumEdition descriptorpb.Edition
SupportedFeatures uint64
Options []opts.Option
ValidateCodeGeneratorRequest func(req *pluginpb.CodeGeneratorRequest) error
Generate func(pl *PluginContext) error
}
GenerateCommand is a command that transforsm a pluginpb.CodeGeneratorRequest into a PluginContext and delegates to [Generate] to generate the code. The generated code is then returned as a pluginpb.CodeGeneratorResponse.
func (*GenerateCommand) Run ¶
func (cmd *GenerateCommand) Run() error
Run executes the command: reads CodeGeneratorRequest from stdin, parses flags, delegates to Generate, and writes CodeGeneratorResponse to stdout.
type GeneratedFile ¶
type GeneratedFile struct {
// contains filtered or unexported fields
}
GeneratedFile is a generated file to be returned in the response. It is a simple wrapper around a bytes.Buffer that provides a few convenience methods.
func (*GeneratedFile) Content ¶
func (g *GeneratedFile) Content() []byte
Content returns the generated file content as a byte slice.
func (*GeneratedFile) Fprint ¶
func (g *GeneratedFile) Fprint(v ...any) (int, error)
Fprint prints the provided values in their default format to the generated file.
func (*GeneratedFile) Fprintf ¶
func (g *GeneratedFile) Fprintf(format string, v ...any) (int, error)
Fprintf prints the provided values in using the provided format to the generated file.
type PluginContext ¶
type PluginContext struct {
Request *pluginpb.CodeGeneratorRequest
Files []*descriptorpb.FileDescriptorProto
FilesByName map[string]*descriptorpb.FileDescriptorProto
FilesToGenerate map[string]bool
ErrorMessage error
// contains filtered or unexported fields
}
PluginContext is a protoc plugin invocation context independent of Go-specific protogen.
func (*PluginContext) NewGeneratedFile ¶
func (pl *PluginContext) NewGeneratedFile(filename string) *GeneratedFile
NewGeneratedFile creates a new generated file for the plugin context.