Documentation
¶
Overview ¶
Package protogen provides proto file parsing and code generation.
Index ¶
- func FromStruct(src interface{}) (map[string]interface{}, error)
- func GenerateFile(proto *storage.ProtoParseResult, serviceName string, opts ServerGenOptions, ...) error
- func ToStruct(m map[string]interface{}, target interface{}) error
- type ImplementationGenerator
- func (g *ImplementationGenerator) GenerateAll(outputDir string, opts ServerGenOptions) error
- func (g *ImplementationGenerator) GenerateAllServicesImpl(opts ServerGenOptions, w io.Writer) error
- func (g *ImplementationGenerator) GenerateServiceImpl(serviceName string, opts ServerGenOptions, w io.Writer) error
- func (g *ImplementationGenerator) GetStats() storage.MappingStats
- type MethodDescriptor
- type MethodHandler
- type MockHooks
- type MockServer
- func (s *MockServer) Call(ctx context.Context, service, method string, req map[string]interface{}) (map[string]interface{}, error)
- func (s *MockServer) ClearData()
- func (s *MockServer) GetData(table string) []map[string]interface{}
- func (s *MockServer) RegisterHandler(service, method string, handler MethodHandler)
- func (s *MockServer) SeedData(table string, records []map[string]interface{})
- func (s *MockServer) SetHooks(hooks *MockHooks)
- type Parser
- func (p *Parser) Parse(r io.Reader, filename string) (*storage.ProtoFile, error)
- func (p *Parser) ParseDir(dir string) (*storage.ProtoParseResult, error)
- func (p *Parser) ParseFile(path string) (*storage.ProtoFile, error)
- func (p *Parser) ParseFiles(paths ...string) (*storage.ProtoParseResult, error)
- type RepositoryGenerator
- type ServerGenOptions
- type ServerGenerator
- type ServiceDescriptor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromStruct ¶
FromStruct converts a struct to a map using JSON marshaling.
func GenerateFile ¶
func GenerateFile(proto *storage.ProtoParseResult, serviceName string, opts ServerGenOptions, w io.Writer) error
GenerateFile generates a complete Go file with service and repository.
Types ¶
type ImplementationGenerator ¶
type ImplementationGenerator struct {
// contains filtered or unexported fields
}
ImplementationGenerator generates complete repository implementations.
func NewImplementationGenerator ¶
func NewImplementationGenerator(proto *storage.ProtoParseResult, procedures []*storage.Procedure) *ImplementationGenerator
NewImplementationGenerator creates a generator with proto-to-SQL mappings.
func (*ImplementationGenerator) GenerateAll ¶
func (g *ImplementationGenerator) GenerateAll(outputDir string, opts ServerGenOptions) error
GenerateAll generates implementation files for all services.
func (*ImplementationGenerator) GenerateAllServicesImpl ¶
func (g *ImplementationGenerator) GenerateAllServicesImpl(opts ServerGenOptions, w io.Writer) error
GenerateAllServicesImpl generates all services in a single output with one package header.
func (*ImplementationGenerator) GenerateServiceImpl ¶
func (g *ImplementationGenerator) GenerateServiceImpl(serviceName string, opts ServerGenOptions, w io.Writer) error
GenerateServiceImpl generates a complete service implementation file.
func (*ImplementationGenerator) GetStats ¶
func (g *ImplementationGenerator) GetStats() storage.MappingStats
GetStats returns mapping statistics.
type MethodDescriptor ¶
type MethodDescriptor struct {
Name string
RequestType reflect.Type
ResponseType reflect.Type
Handler MethodHandler
}
MethodDescriptor provides runtime information about a method.
type MethodHandler ¶
type MethodHandler func(ctx context.Context, req map[string]interface{}) (map[string]interface{}, error)
MethodHandler handles a single RPC method.
type MockHooks ¶
type MockHooks struct {
// BeforeCall is invoked before each method call
BeforeCall func(service, method string, req map[string]interface{})
// AfterCall is invoked after each method call
AfterCall func(service, method string, req, resp map[string]interface{}, err error)
// OnNotFound is invoked when a method has no handler
OnNotFound func(service, method string, req map[string]interface{}) (map[string]interface{}, error)
}
MockHooks allows customising mock behaviour.
type MockServer ¶
type MockServer struct {
// contains filtered or unexported fields
}
MockServer is a dynamic mock server generated from proto definitions.
func NewMockServer ¶
func NewMockServer(proto *storage.ProtoParseResult) *MockServer
NewMockServer creates a mock server from proto definitions.
func (*MockServer) Call ¶
func (s *MockServer) Call(ctx context.Context, service, method string, req map[string]interface{}) (map[string]interface{}, error)
Call invokes an RPC method.
func (*MockServer) GetData ¶
func (s *MockServer) GetData(table string) []map[string]interface{}
GetData returns all records for a table.
func (*MockServer) RegisterHandler ¶
func (s *MockServer) RegisterHandler(service, method string, handler MethodHandler)
RegisterHandler registers a custom handler for a method.
func (*MockServer) SeedData ¶
func (s *MockServer) SeedData(table string, records []map[string]interface{})
SeedData populates a table with records.
func (*MockServer) SetHooks ¶
func (s *MockServer) SetHooks(hooks *MockHooks)
SetHooks sets the mock hooks.
type Parser ¶
type Parser struct {
// ImportPaths are directories to search for imports
ImportPaths []string
}
Parser reads and parses .proto files.
func (*Parser) ParseDir ¶
func (p *Parser) ParseDir(dir string) (*storage.ProtoParseResult, error)
ParseDir parses all .proto files in a directory.
func (*Parser) ParseFiles ¶
func (p *Parser) ParseFiles(paths ...string) (*storage.ProtoParseResult, error)
ParseFiles parses multiple .proto files.
type RepositoryGenerator ¶
type RepositoryGenerator struct {
// contains filtered or unexported fields
}
RepositoryGenerator generates repository interface and implementation stubs.
func NewRepositoryGenerator ¶
func NewRepositoryGenerator(proto *storage.ProtoParseResult, packageName string) *RepositoryGenerator
NewRepositoryGenerator creates a repository generator.
func (*RepositoryGenerator) GenerateInterface ¶
func (g *RepositoryGenerator) GenerateInterface(serviceName string, w io.Writer) error
GenerateInterface generates the repository interface.
func (*RepositoryGenerator) GenerateSQLImpl ¶
func (g *RepositoryGenerator) GenerateSQLImpl(serviceName string, w io.Writer) error
GenerateSQLImpl generates a SQL-based implementation.
func (*RepositoryGenerator) GenerateStub ¶
func (g *RepositoryGenerator) GenerateStub(serviceName string, w io.Writer) error
GenerateStub generates a stub implementation.
type ServerGenOptions ¶
type ServerGenOptions struct {
PackageName string // Go package name for generated code
IncludeComments bool // Include method comments
UseContext bool // Include context.Context in method signatures
GenerateMocks bool // Also generate mock implementations
OutputDir string // Output directory
Dialect string // SQL dialect (postgres, mysql, sqlserver, sqlite)
}
ServerGenOptions configures server generation.
func DefaultServerGenOptions ¶
func DefaultServerGenOptions() ServerGenOptions
DefaultServerGenOptions returns sensible defaults.
type ServerGenerator ¶
type ServerGenerator struct {
// contains filtered or unexported fields
}
ServerGenerator generates Go server implementation code from proto definitions.
func NewServerGenerator ¶
func NewServerGenerator(proto *storage.ProtoParseResult, opts ServerGenOptions) *ServerGenerator
NewServerGenerator creates a server generator.
func (*ServerGenerator) GenerateAll ¶
func (g *ServerGenerator) GenerateAll(w io.Writer) error
GenerateAll generates server implementations for all services.
func (*ServerGenerator) GenerateService ¶
func (g *ServerGenerator) GenerateService(serviceName string, w io.Writer) error
GenerateService generates server implementation for a service.
type ServiceDescriptor ¶
type ServiceDescriptor struct {
Name string
Methods []MethodDescriptor
}
ServiceDescriptor provides runtime information about a service.
func BuildDescriptors ¶
func BuildDescriptors(proto *storage.ProtoParseResult) []ServiceDescriptor
BuildDescriptors builds service descriptors from proto definitions.