generator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Name string
	Type string
}

Argument is an input or output argument of a signature.

func (*Argument) EndType

func (arg *Argument) EndType() string

EndType returns the final part of the type, excluding map, array and pointer markers. map[string]int -> int; []*User -> User; *time.Time -> time.Time

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.

func (*General) UnmarshalYAML

func (g *General) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML parses and validates the YAML.

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

func NewGenerator() (gen *Generator, err error)

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

func (gen *Generator) Indentation() int

Indentation returns the indentation depth.

func (*Generator) MakeCode

func (gen *Generator) MakeCode() (err error)

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

func (gen *Generator) MakeIntegrationTests() (err error)

MakeIntegrationTests creates the integration tests.

func (*Generator) MakeSpecs

func (gen *Generator) MakeSpecs() (err error)

MakeSpecs creates or updates service.yaml.

func (*Generator) MakeVersion

func (gen *Generator) MakeVersion() error

MakeVersion generates the versioning files.

func (*Generator) ParseSpecs

func (gen *Generator) ParseSpecs() (svc *Service, err error)

ParseSpecs parses service.yaml and returns the specs of the microservice.

func (*Generator) Print

func (gen *Generator) Print(format string, args ...any)

Print prints a message to stdout at the current indentation depth but only if the printer is in verbose mode.

func (*Generator) ReadVersion

func (gen *Generator) ReadVersion() (version int, hash string, timestamp time.Time, err error)

ReadVersion reads the version information from version-gen.go. It returns 0 if the file doesn't exists.

func (*Generator) Run

func (gen *Generator) Run() (err error)

Run performs code generation.

func (*Generator) Unindent

func (gen *Generator) Unindent()

Indent decrements the indentation depth by 1.

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

func (h *Handler) In(spec string) string

In returns the input argument list as a string. Spec options:

, name type
, name
name type,
name,
name
name type

func (*Handler) MethodWithBody

func (h *Handler) MethodWithBody() bool

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) Name

func (h *Handler) Name() string

Name of the handler function.

func (*Handler) Out

func (h *Handler) Out(spec string) string

Out returns the output argument list as a string. Spec options:

, name type
, name
name type,
name,
name
name type

func (*Handler) Port

func (h *Handler) Port() (string, error)

Port returns the port number set in the path.

func (*Handler) SourceSuffix

func (h *Handler) SourceSuffix() string

SourceSuffix returns the last piece of the event source package path, which is expected to point to a microservice.

func (*Handler) UnmarshalYAML

func (h *Handler) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML parses the handler.

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

func (s *Service) AllHandlers() []*Handler

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

func (s *Service) ModulePathSuffix() string

ModulePathSuffix returns only the last portion of the full module path.

func (*Service) PackagePathSuffix

func (s *Service) PackagePathSuffix() string

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.

func (*Service) UnmarshalYAML

func (s *Service) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML parses and validates the YAML.

type Signature

type Signature struct {
	OrigString string
	Name       string
	InputArgs  []*Argument
	OutputArgs []*Argument
}

Signature is the spec of a function signature.

func (*Signature) InputArg

func (sig *Signature) InputArg(name string) *Argument

InputArg returns the named input arg, or nil if none exist with this name.

func (*Signature) OutputArg

func (sig *Signature) OutputArg(name string) *Argument

OutputArg returns the named output arg, or nil if none exist with this name.

func (*Signature) TestingT

func (sig *Signature) TestingT() string

TestingT returns "testingT" if "t" conflicts with an argument of the function. Otherwise, "t" is returned.

func (*Signature) UnmarshalYAML

func (sig *Signature) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML parses the signature.

type Type

type Type struct {
	Name        string
	Exists      bool
	PackagePath string
}

Type is a complex type used in a function.

func (*Type) PackagePathSuffix

func (t *Type) PackagePathSuffix() string

PackagePathSuffix returns only the last portion of the import package path.

Jump to

Keyboard shortcuts

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