Version: v1.1.0 Latest Latest

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 12 Imported by: 0




This section is empty.


View Source
var StandardTemplates embed.FS

StandardTemplates provides access to all of the code generation templates that Frodo ships with out of the box.


func File

func File(ctx *parser.Context, fileTemplate FileTemplate) error

File runs the parsed service context through the given file template, generating the appropriate code/project file. The 'ctx' will be fed in as the root data to the Go template represented by the fileTemplate parameter.

func ServiceScaffold

func ServiceScaffold(request ServiceScaffoldRequest) error

ServiceScaffold creates the bare minimum code required to have a frodo-powered service. It creates a directory for the service code to live, a declaration file that contains the interface and model definitions, and a skeleton implementation. These all help establish some of the base patterns you should use when working with frodo services.


type FileTemplate

type FileTemplate struct {
	// Name is the identifier used to indicate "which" file you're generating. For example you might set
	// this to "client.go" when generating a Go RPC client file or "gateway.go" when generating the API
	// gateway. In practice this is generally used when building the file name for the generated file.
	Name string
	// FileSystem is the store where we can look up the code template.
	FileSystem fs.FS
	// Path is the location on the FileSystem where this template is located.
	Path string

FileTemplate tracks the data needed to load a code generation template for one of our output artifacts. This can be one of our built-in templates (using embed.FS) or a

func NewCustomTemplate

func NewCustomTemplate(name string, path string) FileTemplate

NewCustomTemplate creates the metadata that points to a custom template defined by the user running one of our CLI commands. They might have their own ".tmpl" file somewhere on their hard drive and this allows you to swap that into our artifact generation logic in place of one of our built-in templates.

func NewStandardTemplate

func NewStandardTemplate(name string, path string) FileTemplate

NewStandardTemplate creates the metadata that points to one of our standard, built-in templates for a gateway, client, etc.

func (FileTemplate) Eval

func (t FileTemplate) Eval(data interface{}) ([]byte, error)

Eval runs the given value through the Go template resolved by looking up Path in the FileSystem. The 'data' value is the root context value we'll pass to the template when running Execute(). This will return the complete set of bytes for the output file contents.

type ServiceScaffoldRequest

type ServiceScaffoldRequest struct {
	// ServiceName is the value of the --service argument.
	ServiceName string
	// Directory is the value of the --dir argument which defines where the new .go files will be written.
	Directory string
	// Force is the status of the --force flag to overwrite files if they already exist.
	Force bool

ServiceScaffoldRequest contains the inputs from our "frodo create" CLI command.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL