codegen

package
v0.2.5-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StartGenComment = "// <<<<<<< Generated"
	EndGenComment   = "// >>>>>>> Generated"
)
View Source
const (
	Delete = Tag(iota)
	Replace
	Insert
	Equal
)
View Source
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.

View Source
const (
	GeneratorCommandName = "scg"
)
View Source
const NumberPartOfString = 2

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

func CamelCase(name string, firstUpper, acronym bool) string

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

func Comment(elems ...string) string

Comment produces line comments by concatenating the given strings and producing 80 characters long lines starting with "//".

func ConvertToGoStruct

func ConvertToGoStruct(str interface{}, structName string) (string, error)

ConvertToGoStruct generate golang struct on any unknown types in string.

func CopyStringMap

func CopyStringMap[Value any](mp map[string]Value) map[string]Value

CopyStringMap create copy of map with strings kay and any values.

func Indent

func Indent(s, prefix string) string

Indent inserts prefix at the beginning of each non-empty line of s. The end-of-line marker is NL.

func KebabCase

func KebabCase(name string) string

KebabCase produces the kebab-case version of the given CamelCase string.

func LowerCamelCase

func LowerCamelCase(name string) string

func SnakeCase

func SnakeCase(name string) string

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.

func ToTitle

func ToTitle(s string) string

func WrapText

func WrapText(text string, maxChars int) string

WrapText produces lines with text capped at maxChars it will keep words intact and respects newlines.

Types

type Differ

type Differ struct {
	// contains filtered or unexported fields
}

func NewDiffer

func NewDiffer(first, second []string) *Differ

func (*Differ) GetLineStates

func (diff *Differ) GetLineStates() []LinesState

func (*Differ) GetMatchingBlocks

func (diff *Differ) GetMatchingBlocks() []Match

func (*Differ) SetFirstSequences

func (diff *Differ) SetFirstSequences(first []string)

func (*Differ) SetSecondSequences

func (diff *Differ) SetSecondSequences(second []string)

func (*Differ) SetSequences

func (diff *Differ) SetSequences(first, second []string)

type File

type File struct {
	// IsUpdatable indicates whether the file should be updated if one
	// already exists at the given path.
	IsUpdatable bool
	// SkipExist indicates whether the file should be skipped if one
	// already exists at the given path.
	SkipExist bool
	// Path returns the file path relative to the output directory.
	Path string
	// SectionTemplates is the list of file section templates in
	// order of rendering.
	SectionTemplates []*SectionTemplate
	// FinalizeFunc is called after the file has been generated. It
	// is given the absolute path to the file as argument.
	FinalizeFunc func(string) error
}

A File contains the logic to generate a complete file.

func (*File) Render

func (f *File) Render(dir string, update bool) (string, error)

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 NewImport

func NewImport(name, path string) *ImportSpec

NewImport creates an import spec.

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 Match

type Match struct {
	Size int
	// 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(title, pack string, imports []*ImportSpec, allowEdit bool) *SectionTemplate

Header returns a Go source file header section template.

func (*SectionTemplate) Write

func (s *SectionTemplate) Write(w io.Writer) error

Write writes the section to the given writer.

type Tag

type Tag byte

Jump to

Keyboard shortcuts

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