Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var StandardTemplates embed.FS
StandardTemplates provides access to all of the code generation templates that Frodo ships out of the box with.
Functions ¶
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 OutputPath ¶ added in v0.1.3
OutputPath calculates the path (relative to where frodo's being executed) where we'll write the output artifact.
func ServiceScaffold ¶
func ServiceScaffold(request ServiceScaffoldRequest) error
ServiceScaffold creates the bare minimum code required to have an 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 base patterns you should use when working with frodo services.
func UpToDate ¶ added in v0.1.3
UpToDate looks at the modified timestamp of your source/interface file and the timestamp of the output artifact file you want to generate. This will return 'true' if either:
- The output artifact doesn't exist, so it needs to be initially created.
- The output artifact is older than the source file (i.e. it's stale).
Types ¶
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 any) ([]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.