Documentation
¶
Index ¶
- type Argument
- type General
- type Generator
- func (gen *Generator) Indent()
- func (gen *Generator) Indentation() int
- func (gen *Generator) MakeCode() (err error)
- func (gen *Generator) MakeIntegrationTests() (err error)
- func (gen *Generator) MakeSpecs() (err error)
- func (gen *Generator) MakeVersion() error
- func (gen *Generator) ParseSpecs() (svc *Service, err error)
- func (gen *Generator) Print(format string, args ...any)
- func (gen *Generator) ReadVersion() (version int, hash string, timestamp time.Time, err error)
- func (gen *Generator) Run() (err error)
- func (gen *Generator) Unindent()
- type Handler
- func (h *Handler) In(spec string) string
- func (h *Handler) MethodWithBody() bool
- func (h *Handler) Name() string
- func (h *Handler) Out(spec string) string
- func (h *Handler) Port() (string, error)
- func (h *Handler) SourceSuffix() string
- func (h *Handler) UnmarshalYAML(unmarshal func(any) error) error
- type Service
- type Signature
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type General ¶
type General struct {
Host string `yaml:"host"`
Description string `yaml:"description"`
IntegrationTests bool `yaml:"integrationTests"`
OpenAPI bool `yaml:"openApi"`
}
General are general properties of the microservice.
type Generator ¶
type Generator struct {
WorkingDir string // The file-system directory in which the code generator was invoked
ProjectDir string // The file-system directory of the project
ModulePath string // The module from go.mod
PackagePath string // The package path, equals the module path joined with the relative file-system path to the package
PackageName string // The name given to the package in the package statement, most likely the same as the name of the containing directory
Force bool // Force code generation even if not changes are detected
Verbose bool // Whether or not to print verbose progress messages
Testing bool // Testing mode
// contains filtered or unexported fields
}
Generator is the main operator that generates the code.
func NewGenerator ¶
NewGenerator creates a new code generator. Verbose output is sent to stdout and stderr.
func (*Generator) Indent ¶
func (gen *Generator) Indent()
Indent increments the indentation depth by 1.
func (*Generator) Indentation ¶
Indentation returns the indentation depth.
func (*Generator) MakeCode ¶
MakeCode generates the microservice's code based on the YAML specs. The code generated includes the client API, intermediate and service.go.
func (*Generator) MakeIntegrationTests ¶
MakeIntegrationTests creates the integration tests.
func (*Generator) MakeVersion ¶
MakeVersion generates the versioning files.
func (*Generator) ParseSpecs ¶
ParseSpecs parses service.yaml and returns the specs of the microservice.
func (*Generator) Print ¶
Print prints a message to stdout at the current indentation depth but only if the printer is in verbose mode.
func (*Generator) ReadVersion ¶
ReadVersion reads the version information from version-gen.go. It returns 0 if the file doesn't exists.
type Handler ¶
type Handler struct {
Type string `yaml:"-"`
Exists bool `yaml:"-"`
// Shared
Signature *Signature `yaml:"signature"`
Description string `yaml:"description"`
Method string `yaml:"method"`
Path string `yaml:"path"`
Queue string `yaml:"queue"`
OpenAPI bool `yaml:"openApi"`
Actor string `yaml:"actor"`
Callback bool `yaml:"callback"`
// Sink
Event string `yaml:"event"`
Source string `yaml:"source"`
ForHost string `yaml:"forHost"`
// Config
Default string `yaml:"default"`
Validation string `yaml:"validation"`
Secret bool `yaml:"secret"`
// Metrics
Kind string `json:"kind" yaml:"kind"`
Alias string `json:"alias" yaml:"alias"`
Buckets []float64 `json:"buckets" yaml:"buckets"`
// Ticker
Interval time.Duration `yaml:"interval"`
}
Handler is the spec of a callback handler. Web requests, lifecycle events, config changes, tickers, etc.
func (*Handler) In ¶
In returns the input argument list as a string. Spec options:
, name type , name name type, name, name name type
func (*Handler) MethodWithBody ¶
MethodWithBody indicates if the HTTP method of the endpoint allows sending a body. "GET", "DELETE", "TRACE", "OPTIONS", "HEAD" do not allow a body.
func (*Handler) Out ¶
Out returns the output argument list as a string. Spec options:
, name type , name name type, name, name name type
func (*Handler) SourceSuffix ¶
SourceSuffix returns the last piece of the event source package path, which is expected to point to a microservice.
type Service ¶
type Service struct {
ModulePath string `yaml:"-"`
PackagePath string `yaml:"-"`
PackageName string `yaml:"-"`
General General `yaml:"general"`
Configs []*Handler `yaml:"configs"`
Metrics []*Handler `yaml:"metrics"`
Functions []*Handler `yaml:"functions"`
Events []*Handler `yaml:"events"`
Sinks []*Handler `yaml:"sinks"`
Webs []*Handler `yaml:"webs"`
Tickers []*Handler `yaml:"tickers"`
Types []*Type `yaml:"-"`
// contains filtered or unexported fields
}
Service is the spec of the microservice parsed from service.yaml.
func (*Service) AllHandlers ¶
AllHandlers returns an array holding all handlers of all types.
func (*Service) FullyQualifyTypes ¶
func (s *Service) FullyQualifyTypes()
FullyQualifyTypes prepends the API package name to complex types of function arguments.
func (*Service) ModulePathSuffix ¶
ModulePathSuffix returns only the last portion of the full module path.
func (*Service) PackagePathSuffix ¶
PackagePathSuffix returns only the last portion of the full package path.
func (*Service) ShorthandTypes ¶
func (s *Service) ShorthandTypes()
ShorthandTypes removed the API package name from complex types of function arguments.
type Signature ¶
type Signature struct {
OrigString string
Name string
InputArgs []*Argument
OutputArgs []*Argument
}
Signature is the spec of a function signature.
func (*Signature) InputArg ¶
InputArg returns the named input arg, or nil if none exist with this name.
func (*Signature) OutputArg ¶
OutputArg returns the named output arg, or nil if none exist with this name.