Documentation ¶
Index ¶
- Constants
- func AddImport(section *SectionTemplate, imprts ...*ImportSpec)
- func CamelCase(name string, firstUpper bool, acronym bool) string
- func CommandLine() string
- func Comment(elems ...string) string
- func ConvertToGoStruct(str interface{}, structName string) (string, error)
- func CopyStringMap[Value any](mp map[string]Value) map[string]Value
- func Indent(s, prefix string) string
- func KebabCase(name string) string
- func SnakeCase(name string) string
- func TemplateFuncs() map[string]interface{}
- func ToTitle(s string) string
- func WrapText(text string, maxChars int) string
- type Differ
- type File
- type ImportSpec
- type LinesState
- type Match
- type SectionTemplate
- type Tag
Constants ¶
const ( Delete = Tag(iota) Replace Insert Equal )
const Gendir = "scg"
Gendir is the name of the subdirectory of the output directory that contains the generated files. This directory is wiped and re-written each time goa is run.
Variables ¶
This section is empty.
Functions ¶
func AddImport ¶
func AddImport(section *SectionTemplate, imprts ...*ImportSpec)
AddImport adds imports to a section template that was generated with Header.
func CamelCase ¶
CamelCase produces the CamelCase version of the given string. It removes any non letter and non digit character.
If firstUpper is true the first letter of the string is capitalized else the first letter is in lowercase.
If acronym is true and a part of the string is a common acronym then it keeps the part capitalized (firstUpper = true) (e.g. APIVersion) or lowercase (firstUpper = false) (e.g. apiVersion).
func CommandLine ¶
func CommandLine() string
CommandLine return the command used to run this process.
func Comment ¶
Comment produces line comments by concatenating the given strings and producing 80 characters long lines starting with "//".
func ConvertToGoStruct ¶
ConvertToGoStruct generate golang struct on any unknown types in string
func CopyStringMap ¶
CopyStringMap create copy of map with strings kay and any values
func Indent ¶
Indent inserts prefix at the beginning of each non-empty line of s. The end-of-line marker is NL.
func SnakeCase ¶
SnakeCase produces the snake_case version of the given CamelCase string. News => news OldNews => old_news CNNNews => cnn_news
func TemplateFuncs ¶
func TemplateFuncs() map[string]interface{}
TemplateFuncs lists common template helper functions.
Types ¶
type Differ ¶
type Differ struct {
// contains filtered or unexported fields
}
func (*Differ) GetLineStates ¶
func (diff *Differ) GetLineStates() []LinesState
func (*Differ) GetMatchingBlocks ¶
func (*Differ) SetFirstSequences ¶
func (*Differ) SetSecondSequences ¶
func (*Differ) SetSequences ¶
type File ¶
type File struct { // SectionTemplates is the list of file section templates in // order of rendering. SectionTemplates []*SectionTemplate // Path returns the file path relative to the output directory. Path string // SkipExist indicates whether the file should be skipped if one // already exists at the given path. SkipExist bool // FinalizeFunc is called after the file has been generated. It // is given the absolute path to the file as argument. FinalizeFunc func(string) error // IsUpdatable indicates whether the file should be updated if one // already exists at the given path. IsUpdatable bool }
A File contains the logic to generate a complete file.
func (*File) Render ¶
Render executes the file section templates and writes the resulting bytes to an output file. The path of the output file is computed by appending the file path to dir. If a file already exists with the computed path then Render happens the smallest integer value greater than 1 to make it unique. Renders returns the computed path.
func (*File) Section ¶
func (f *File) Section(name string) []*SectionTemplate
Section returns the section templates with the given name or nil if not found.
type ImportSpec ¶
type ImportSpec struct { // Name of imported package if needed. Name string // Go import path of package. Path string }
ImportSpec defines a generated import statement.
func SCGImport ¶
func SCGImport(rel string) *ImportSpec
SCGImport creates an import for a Goa package.
func SCGNamedImport ¶
func SCGNamedImport(rel, name string) *ImportSpec
SCGNamedImport creates an import for a Goa package with the given name.
func SimpleImport ¶
func SimpleImport(path string) *ImportSpec
SimpleImport creates an import with no explicit path component.
func (*ImportSpec) Code ¶
func (s *ImportSpec) Code() string
Code returns the Go import statement for the ImportSpec.
type LinesState ¶
type LinesState struct { Tag Tag // contains filtered or unexported fields }
type SectionTemplate ¶
type SectionTemplate struct { // Name is the name reported when parsing the source fails. Name string // Source is used to create the text/template.Template that // renders the section text. Source string // FuncMap lists the functions used to render the templates. FuncMap map[string]interface{} // Data used as input of template. Data interface{} }
A SectionTemplate is a template and accompanying render data. The template format is described in the (stdlib) text/template package.
func Header ¶
func Header(title, pack string, imports []*ImportSpec, allowEdit bool) *SectionTemplate
Header returns a Go source file header section template.