generator

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add added in v0.1.3

func Add(n1, n2 int) int

Add adds two numbers.

func CreateMap added in v0.1.3

func CreateMap(pairs ...any) (map[string]any, error)

CreateMap creates a map from a list of key-value pairs to pass multiple arguments to sub-templates.

func ParentCtx added in v0.1.3

func ParentCtx(level int) (string, error)

ParentCtx creates parent context name from the given level.

func WatchMode

func WatchMode() func(*Generator) error

Types

type ActionType

type ActionType string
const (
	KeepAction   ActionType = "keep"
	CreateAction ActionType = "create"
	DeleteAction ActionType = "delete"
	UpdateAction ActionType = "update"
)

type Argument

type Argument struct {
	Name         string
	Value        string
	CEL          *resolver.CELValue
	InlineFields []*Argument
	ProtoComment string
	ZeroValue    string
}

type BadRequest added in v0.5.2

type BadRequest struct {
	FieldViolations []*BadRequestFieldViolation
}

type BadRequestFieldViolation added in v0.5.2

type BadRequestFieldViolation struct {
	Field       string
	Description string
}

type BuildCache

type BuildCache struct {
	Responses       []*pluginpb.CodeGeneratorResponse
	FederationFiles []*resolver.File
}

type BuildCacheMap added in v0.4.0

type BuildCacheMap map[string]*BuildCache

type CastEnum

type CastEnum struct {
	FromValues   []*CastEnumValue
	DefaultValue string
}

type CastEnumValue

type CastEnumValue struct {
	FromValue string
	ToValue   string
}

type CastField

type CastField struct {
	Name string
	// contains filtered or unexported fields
}

func (*CastField) IsEnum

func (f *CastField) IsEnum() bool

func (*CastField) IsOneof

func (f *CastField) IsOneof() bool

func (*CastField) IsSlice

func (f *CastField) IsSlice() bool

func (*CastField) IsStruct

func (f *CastField) IsStruct() bool

func (*CastField) RequestProtoFQDN

func (f *CastField) RequestProtoFQDN() string

func (*CastField) RequestType

func (f *CastField) RequestType() string

func (*CastField) ResponseProtoFQDN

func (f *CastField) ResponseProtoFQDN() string

func (*CastField) ResponseType

func (f *CastField) ResponseType() string

func (*CastField) ToEnum

func (f *CastField) ToEnum() *CastEnum

func (*CastField) ToOneof

func (f *CastField) ToOneof() *CastOneof

func (*CastField) ToSlice

func (f *CastField) ToSlice() *CastSlice

func (*CastField) ToStruct

func (f *CastField) ToStruct() *CastStruct

type CastOneof

type CastOneof struct {
	Name         string
	FieldName    string
	CastName     string
	RequiredCast bool
}

type CastOneofStruct

type CastOneofStruct struct {
	Name   string
	Fields []*CastStructField
}

type CastSlice

type CastSlice struct {
	ResponseType     string
	ElemRequiredCast bool
	ElemCastName     string
}

type CastStruct

type CastStruct struct {
	Name   string
	Fields []*CastStructField
	Oneofs []*CastOneofStruct
}

type CastStructField

type CastStructField struct {
	ToFieldName   string
	FromFieldName string
	CastName      string
	RequiredCast  bool
}

type CodeGenerator

type CodeGenerator struct {
}

func NewCodeGenerator

func NewCodeGenerator() *CodeGenerator

func (*CodeGenerator) Generate

func (g *CodeGenerator) Generate(file *resolver.File) ([]byte, error)

type Config

type Config struct {
	// Imports specify list of import path. This is the same as the list of paths specified by protoc's '-I' option.
	Imports []string `yaml:"imports"`
	// Src specifies the directory to be monitored when watch mode is enabled.
	Src []string `yaml:"src"`
	// Out specify the output destination for automatically generated code.
	Out string `yaml:"out"`
	// Plugins specify protoc's plugin configuration.
	Plugins []*PluginConfig `yaml:"plugins"`
	// AutoProtocGenGo automatically run protoc-gen-go at the time of editing proto. default is true.
	AutoProtocGenGo *bool `yaml:"autoProtocGenGo"`
	// AutoProtocGenGoGRPC automatically run protoc-gen-go-grpc at the time of editing proto. default is true.
	AutoProtocGenGoGRPC *bool `yaml:"autoProtocGenGoGrpc"`
}

func LoadConfig

func LoadConfig(path string) (Config, error)

func LoadConfigFromReader

func LoadConfigFromReader(r io.Reader) (Config, error)

func (*Config) GetAutoProtocGenGo

func (c *Config) GetAutoProtocGenGo() bool

func (*Config) GetAutoProtocGenGoGRPC

func (c *Config) GetAutoProtocGenGoGRPC() bool

type CustomResolver

type CustomResolver struct {
	*resolver.CustomResolver
	Service *resolver.Service
}

func (*CustomResolver) Name

func (r *CustomResolver) Name() string

func (*CustomResolver) ProtoFQDN

func (r *CustomResolver) ProtoFQDN() string

func (*CustomResolver) RequestType

func (r *CustomResolver) RequestType() string

func (*CustomResolver) ReturnType

func (r *CustomResolver) ReturnType() string

type DeclVariable

type DeclVariable struct {
	Name string
	Type string
}

type DependentMethod

type DependentMethod struct {
	Name string
	FQDN string
}

type Field

type Field struct {
	Name string
	Type string
}

type File added in v0.4.0

type File struct {
	*resolver.File
}

func (*File) DefaultImports added in v0.5.3

func (f *File) DefaultImports() []*Import

func (*File) Imports added in v0.4.0

func (f *File) Imports() []*Import

func (*File) Services added in v0.4.0

func (f *File) Services() []*Service

func (*File) Types added in v0.4.0

func (f *File) Types() Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config) *Generator

func (*Generator) Generate

func (g *Generator) Generate(ctx context.Context, protoPath string, opts ...Option) error

func (*Generator) GenerateAll

func (g *Generator) GenerateAll(ctx context.Context) (BuildCacheMap, error)

func (*Generator) SetPostProcessHandler

func (g *Generator) SetPostProcessHandler(postProcessHandler func(ctx context.Context, path string, result Result) error)

type Import

type Import struct {
	Path  string
	Alias string
}

type LocalizedMessage added in v0.5.2

type LocalizedMessage struct {
	Locale  string
	Message string
}

type LogValue

type LogValue struct {
	Name      string
	ValueType string
	Attrs     []*LogValueAttr
	Type      *resolver.Type
	Value     string // for repeated type
}

func (*LogValue) IsMap

func (v *LogValue) IsMap() bool

func (*LogValue) IsMessage

func (v *LogValue) IsMessage() bool

func (*LogValue) IsRepeated

func (v *LogValue) IsRepeated() bool

type LogValueAttr

type LogValueAttr struct {
	Type  string
	Key   string
	Value string
}

type Message

type Message struct {
	*resolver.Message
	Service *resolver.Service
}

func (*Message) CustomResolverArguments

func (m *Message) CustomResolverArguments() []*Argument

func (*Message) CustomResolverName

func (m *Message) CustomResolverName() string

func (*Message) DeclVariables

func (m *Message) DeclVariables() []*DeclVariable

func (*Message) DependencyGraph

func (m *Message) DependencyGraph() string

func (*Message) LogValueReturnType

func (m *Message) LogValueReturnType() string

func (*Message) MessageResolvers

func (m *Message) MessageResolvers() []*MessageResolverGroup

func (*Message) ProtoFQDN

func (m *Message) ProtoFQDN() string

func (*Message) RequestProtoType added in v0.2.0

func (m *Message) RequestProtoType() string

func (*Message) RequestType

func (m *Message) RequestType() string

func (*Message) ResolverName

func (m *Message) ResolverName() string

func (*Message) ReturnFields

func (m *Message) ReturnFields() []*ReturnField

func (*Message) ReturnType

func (m *Message) ReturnType() string

type MessageResolver

type MessageResolver struct {
	Service *resolver.Service
	Message *Message
	*resolver.MessageResolver
}

func (*MessageResolver) Arguments

func (r *MessageResolver) Arguments() []*Argument

func (*MessageResolver) By added in v0.6.0

func (*MessageResolver) Caller

func (r *MessageResolver) Caller() string

func (*MessageResolver) DependentMethodName

func (r *MessageResolver) DependentMethodName() string

func (*MessageResolver) HasErrorHandler

func (r *MessageResolver) HasErrorHandler() bool

func (*MessageResolver) IsBy added in v0.6.0

func (r *MessageResolver) IsBy() bool

func (*MessageResolver) IsValidation added in v0.6.0

func (r *MessageResolver) IsValidation() bool

func (*MessageResolver) Key

func (r *MessageResolver) Key() string

func (*MessageResolver) MessageValidation added in v0.5.1

func (r *MessageResolver) MessageValidation() *ValidationRule

func (*MessageResolver) MethodFQDN

func (r *MessageResolver) MethodFQDN() string

func (*MessageResolver) ProtoComment

func (r *MessageResolver) ProtoComment() string

func (*MessageResolver) RequestType

func (r *MessageResolver) RequestType() string

func (*MessageResolver) ResponseVariable

func (r *MessageResolver) ResponseVariable() string

func (*MessageResolver) ResponseVariables

func (r *MessageResolver) ResponseVariables() []*ResponseVariable

func (*MessageResolver) Retry added in v0.6.0

func (r *MessageResolver) Retry() *resolver.RetryPolicy

func (*MessageResolver) ReturnType

func (r *MessageResolver) ReturnType() string

func (*MessageResolver) ServiceName

func (r *MessageResolver) ServiceName() string

func (*MessageResolver) Timeout

func (r *MessageResolver) Timeout() string

func (*MessageResolver) Type

func (r *MessageResolver) Type() string

func (*MessageResolver) UseResponseVariable

func (r *MessageResolver) UseResponseVariable() bool

func (*MessageResolver) UseRetry

func (r *MessageResolver) UseRetry() bool

func (*MessageResolver) UseTimeout

func (r *MessageResolver) UseTimeout() bool

func (*MessageResolver) ZeroValue added in v0.6.0

func (r *MessageResolver) ZeroValue() string

type MessageResolverGroup

type MessageResolverGroup struct {
	Service *resolver.Service
	Message *Message
	resolver.MessageResolverGroup
}

func (*MessageResolverGroup) End

func (*MessageResolverGroup) ExistsEnd

func (g *MessageResolverGroup) ExistsEnd() bool

func (*MessageResolverGroup) ExistsStart

func (g *MessageResolverGroup) ExistsStart() bool

func (*MessageResolverGroup) IsConcurrent

func (g *MessageResolverGroup) IsConcurrent() bool

func (*MessageResolverGroup) Start

func (*MessageResolverGroup) Starts

type Method

type Method struct {
	*resolver.Method
	Service *resolver.Service
}

func (*Method) ArgumentName

func (m *Method) ArgumentName() string

func (*Method) ProtoFQDN

func (m *Method) ProtoFQDN() string

func (*Method) RequestType

func (m *Method) RequestType() string

func (*Method) ResolverName

func (m *Method) ResolverName() string

func (*Method) ReturnType

func (m *Method) ReturnType() string

func (*Method) ReturnTypeArguments

func (m *Method) ReturnTypeArguments() []string

func (*Method) ReturnTypeWithoutPtr

func (m *Method) ReturnTypeWithoutPtr() string

func (*Method) Timeout

func (m *Method) Timeout() string

func (*Method) UseTimeout

func (m *Method) UseTimeout() bool

type OneofField

type OneofField struct {
	Expr           string
	By             string
	OutType        string
	Condition      string
	Name           string
	Value          string
	Message        *Message
	FieldOneofRule *resolver.FieldOneofRule
}

func (*OneofField) MessageResolvers added in v0.3.0

func (oneof *OneofField) MessageResolvers() []*MessageResolverGroup

type OneofType added in v0.3.0

type OneofType struct {
	Name             string
	FieldName        string
	MessageProtoFQDN string
	TypeDeclare      string
	FieldZeroValues  []string
	FieldGetterNames []string
	ReturnZeroValue  string
}

type Option

type Option func(*Generator) error

type PluginConfig

type PluginConfig struct {
	// Plugin name of the protoc plugin.
	// If the name of the plugin is 'protoc-gen-go', write 'go'. ('protoc-gen-' prefix can be omitted).
	Plugin string `yaml:"plugin"`
	// Option specify options to be passed protoc plugin.
	Opt string `yaml:"opt"`
	// contains filtered or unexported fields
}

type PluginRequest

type PluginRequest struct {
	// contains filtered or unexported fields
}

type PostProcessHandler

type PostProcessHandler func(context.Context, string, Result) error

type PreconditionFailure added in v0.5.2

type PreconditionFailure struct {
	Violations []*PreconditionFailureViolation
}

type PreconditionFailureViolation added in v0.5.2

type PreconditionFailureViolation struct {
	Type        string
	Subject     string
	Description string
}

type ProtoField added in v0.2.0

type ProtoField struct {
	*resolver.Field
}

func (*ProtoField) FieldName added in v0.2.0

func (f *ProtoField) FieldName() string

func (*ProtoField) Name added in v0.2.0

func (f *ProtoField) Name() string

func (*ProtoField) TypeDeclare added in v0.2.0

func (f *ProtoField) TypeDeclare() string

type ProtoFileResult

type ProtoFileResult struct {
	ProtoPath       string
	Type            ActionType
	Files           []*pluginpb.CodeGeneratorResponse_File
	FederationFiles []*resolver.File
	Out             string
}

func (*ProtoFileResult) WriteFiles

func (r *ProtoFileResult) WriteFiles(ctx context.Context) error

type ResponseVariable

type ResponseVariable struct {
	UseName      bool
	Type         string
	Name         string
	Selector     string
	ProtoComment string
	CELExpr      string
	CELType      string
}

type Result

type Result []*ProtoFileResult

type ReturnField

type ReturnField struct {
	Name                  string
	Value                 string
	IsCustomResolverField bool
	IsOneofField          bool
	CEL                   *resolver.CELValue
	OneofCaseFields       []*OneofField
	OneofDefaultField     *OneofField
	ResolverName          string
	RequestType           string
	MessageName           string
	MessageArgumentName   string
	ProtoComment          string
	ZeroValue             string
}

func (*ReturnField) HasFieldOneofRule added in v0.3.0

func (r *ReturnField) HasFieldOneofRule() bool

type Service

type Service struct {
	*resolver.Service
	// contains filtered or unexported fields
}

func (*Service) CastFields added in v0.5.2

func (s *Service) CastFields() []*CastField

func (*Service) CustomResolvers

func (s *Service) CustomResolvers() []*CustomResolver

func (*Service) DependentMethods

func (s *Service) DependentMethods() []*DependentMethod

func (*Service) LogValues

func (s *Service) LogValues() []*LogValue

func (*Service) Messages

func (s *Service) Messages() []*Message

func (*Service) Methods

func (s *Service) Methods() []*Method

func (*Service) OneofTypes added in v0.3.0

func (s *Service) OneofTypes() []*OneofType

func (*Service) PackageName

func (s *Service) PackageName() string

func (*Service) ServiceDependencies

func (s *Service) ServiceDependencies() []*ServiceDependency

func (*Service) ServiceName

func (s *Service) ServiceName() string

func (*Service) Types

func (s *Service) Types() Types

type ServiceDependency

type ServiceDependency struct {
	*resolver.ServiceDependency
}

func (*ServiceDependency) ClientConstructor

func (dep *ServiceDependency) ClientConstructor() string

func (*ServiceDependency) ClientName

func (dep *ServiceDependency) ClientName() string

func (*ServiceDependency) ClientType

func (dep *ServiceDependency) ClientType() string

func (*ServiceDependency) NameConfig

func (dep *ServiceDependency) NameConfig() string

func (*ServiceDependency) PrivateClientName

func (dep *ServiceDependency) PrivateClientName() string

func (*ServiceDependency) ServiceName

func (dep *ServiceDependency) ServiceName() string

type Type

type Type struct {
	Name        string
	Fields      []*Field
	ProtoFields []*ProtoField
	Desc        string
	ProtoFQDN   string
}

func (*Type) HasField

func (t *Type) HasField(fieldName string) bool

type Types added in v0.4.0

type Types []*Type

func (Types) HasProtoFields added in v0.4.0

func (t Types) HasProtoFields() bool

type ValidationError added in v0.5.1

type ValidationError struct {
	Code    code.Code
	Rule    string
	Details []*ValidationErrorDetail
}

func (*ValidationError) GoGRPCStatusCode added in v0.5.1

func (v *ValidationError) GoGRPCStatusCode() string

GoGRPCStatusCode converts a gRPC status code to a corresponding Go const name e.g. FAILED_PRECONDITION -> FailedPrecondition.

func (*ValidationError) HasRule added in v0.5.2

func (v *ValidationError) HasRule() bool

HasRule checks if it has rule or not.

type ValidationErrorDetail added in v0.5.2

type ValidationErrorDetail struct {
	Rule                 string
	PreconditionFailures []*PreconditionFailure
	BadRequests          []*BadRequest
	LocalizedMessages    []*LocalizedMessage
}

type ValidationRule added in v0.5.1

type ValidationRule struct {
	Name  string
	Error *ValidationError
}

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

func NewWatcher

func NewWatcher() (*Watcher, error)

func (*Watcher) Close

func (w *Watcher) Close()

func (*Watcher) IsWorking

func (w *Watcher) IsWorking() bool

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context) error

func (*Watcher) SetHandler

func (w *Watcher) SetHandler(handler func(ctx context.Context, event fsnotify.Event))

func (*Watcher) SetWatchPath

func (w *Watcher) SetWatchPath(path ...string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL