machinery

package
v3.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: Apache-2.0 Imports: 12 Imported by: 26

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultFuncMap

func DefaultFuncMap() template.FuncMap

DefaultFuncMap returns the default template.FuncMap for rendering the template.

Types

type BoilerplateMixin

type BoilerplateMixin struct {
	// Boilerplate is the contents of a Boilerplate go header file
	Boilerplate string
}

BoilerplateMixin provides templates with a injectable boilerplate field

func (*BoilerplateMixin) InjectBoilerplate

func (m *BoilerplateMixin) InjectBoilerplate(boilerplate string)

InjectBoilerplate implements HasBoilerplate

type Builder

type Builder interface {
	// GetPath returns the path to the file location
	GetPath() string
	// GetIfExistsAction returns the behavior when creating a file that already exists
	GetIfExistsAction() IfExistsAction
}

Builder defines the basic methods that any file builder must implement

type CloseFileError

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

CloseFileError is a wrapper error that will be used for errors when closing a file

func (CloseFileError) Unwrap

func (e CloseFileError) Unwrap() error

Unwrap implements Wrapper interface

type CodeFragments

type CodeFragments []string

CodeFragments represents a set of code fragments A code fragment is a piece of code provided as a Go string, it may have multiple lines

type CodeFragmentsMap

type CodeFragmentsMap map[Marker]CodeFragments

CodeFragmentsMap binds Markers and CodeFragments together

type ComponentConfigMixin

type ComponentConfigMixin struct {
	// ComponentConfig is the component-config flag
	ComponentConfig bool
}

ComponentConfigMixin provides templates with a injectable component-config flag field

func (*ComponentConfigMixin) InjectComponentConfig

func (m *ComponentConfigMixin) InjectComponentConfig(flag bool)

InjectComponentConfig implements HasComponentConfig

type CreateDirectoryError

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

CreateDirectoryError is a wrapper error that will be used for errors when creating a directory

func (CreateDirectoryError) Unwrap

func (e CreateDirectoryError) Unwrap() error

Unwrap implements Wrapper interface

type CreateFileError

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

CreateFileError is a wrapper error that will be used for errors when creating a file

func (CreateFileError) Unwrap

func (e CreateFileError) Unwrap() error

Unwrap implements Wrapper interface

type DomainMixin

type DomainMixin struct {
	// Domain is the domain for the APIs
	Domain string
}

DomainMixin provides templates with a injectable domain field

func (*DomainMixin) InjectDomain

func (m *DomainMixin) InjectDomain(domain string)

InjectDomain implements HasDomain

type ExistsFileError

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

ExistsFileError is a wrapper error that will be used for errors when checking for a file existence

func (ExistsFileError) Unwrap

func (e ExistsFileError) Unwrap() error

Unwrap implements Wrapper interface

type File

type File struct {
	// Path is the file to write
	Path string

	// Contents is the generated output
	Contents string

	// IfExistsAction determines what to do if the file exists
	IfExistsAction IfExistsAction
}

File describes a file that will be written

type FileAlreadyExistsError

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

FileAlreadyExistsError is returned if the file is expected not to exist but it does

func (FileAlreadyExistsError) Error

func (e FileAlreadyExistsError) Error() string

Error implements error interface

type Filesystem

type Filesystem struct {
	FS afero.Fs
}

Filesystem abstracts the underlying disk for scaffolding

type HasBoilerplate

type HasBoilerplate interface {
	// InjectBoilerplate sets the template boilerplate
	InjectBoilerplate(string)
}

HasBoilerplate allows a boilerplate to be used on a template

type HasComponentConfig

type HasComponentConfig interface {
	// InjectComponentConfig sets the template component-config flag
	InjectComponentConfig(bool)
}

HasComponentConfig allows the component-config flag to be used on a template

type HasDomain

type HasDomain interface {
	// InjectDomain sets the template domain
	InjectDomain(string)
}

HasDomain allows the domain to be used on a template

type HasMultiGroup

type HasMultiGroup interface {
	// InjectMultiGroup sets the template multi-group flag
	InjectMultiGroup(bool)
}

HasMultiGroup allows the multi-group flag to be used on a template

type HasProjectName

type HasProjectName interface {
	// InjectProjectName sets the template project name.
	InjectProjectName(string)
}

HasProjectName allows a project name to be used on a template.

type HasRepository

type HasRepository interface {
	// InjectRepository sets the template repository
	InjectRepository(string)
}

HasRepository allows the repository to be used on a template

type HasResource

type HasResource interface {
	// InjectResource sets the template resource
	InjectResource(*resource.Resource)
}

HasResource allows a resource to be used on a template

type IfExistsAction

type IfExistsAction int

IfExistsAction determines what to do if the scaffold file already exists

const (
	// SkipFile skips the file and moves to the next one
	SkipFile IfExistsAction = iota

	// Error returns an error and stops processing
	Error

	// OverwriteFile truncates and overwrites the existing file
	OverwriteFile
)

type IfExistsActionMixin

type IfExistsActionMixin struct {
	// IfExistsAction determines what to do if the file exists
	IfExistsAction IfExistsAction
}

IfExistsActionMixin provides file builders with a if-exists-action field

func (*IfExistsActionMixin) GetIfExistsAction

func (t *IfExistsActionMixin) GetIfExistsAction() IfExistsAction

GetIfExistsAction implements Builder

type Inserter

type Inserter interface {
	Builder
	// GetMarkers returns the different markers where code fragments will be inserted
	GetMarkers() []Marker
	// GetCodeFragments returns a map that binds markers to code fragments
	GetCodeFragments() CodeFragmentsMap
}

Inserter is a file builder that inserts code fragments in marked positions

type InserterMixin

type InserterMixin struct {
	PathMixin
}

InserterMixin is the mixin that should be embedded in Inserter builders

func (*InserterMixin) GetIfExistsAction

func (t *InserterMixin) GetIfExistsAction() IfExistsAction

GetIfExistsAction implements Builder

type Marker

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

Marker represents a machine-readable comment that will be used for scaffolding purposes

func NewMarkerFor

func NewMarkerFor(path string, value string) Marker

NewMarkerFor creates a new marker customized for the specific file Supported file extensions: .go, .yaml, .yml

func (Marker) EqualsLine

func (m Marker) EqualsLine(line string) bool

EqualsLine compares a marker with a string representation to check if they are the same marker

func (Marker) String

func (m Marker) String() string

String implements Stringer

type ModelAlreadyExistsError

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

ModelAlreadyExistsError is returned if the file is expected not to exist but a previous model does

func (ModelAlreadyExistsError) Error

func (e ModelAlreadyExistsError) Error() string

Error implements error interface

type MultiGroupMixin

type MultiGroupMixin struct {
	// MultiGroup is the multi-group flag
	MultiGroup bool
}

MultiGroupMixin provides templates with a injectable multi-group flag field

func (*MultiGroupMixin) InjectMultiGroup

func (m *MultiGroupMixin) InjectMultiGroup(flag bool)

InjectMultiGroup implements HasMultiGroup

type OpenFileError

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

OpenFileError is a wrapper error that will be used for errors when opening a file

func (OpenFileError) Unwrap

func (e OpenFileError) Unwrap() error

Unwrap implements Wrapper interface

type PathMixin

type PathMixin struct {
	// Path is the of the file
	Path string
}

PathMixin provides file builders with a path field

func (*PathMixin) GetPath

func (t *PathMixin) GetPath() string

GetPath implements Builder

type ProjectNameMixin

type ProjectNameMixin struct {
	ProjectName string
}

ProjectNameMixin provides templates with an injectable project name field.

func (*ProjectNameMixin) InjectProjectName

func (m *ProjectNameMixin) InjectProjectName(projectName string)

InjectProjectName implements HasProjectName.

type ReadFileError

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

ReadFileError is a wrapper error that will be used for errors when reading a file

func (ReadFileError) Unwrap

func (e ReadFileError) Unwrap() error

Unwrap implements Wrapper interface

type RepositoryMixin

type RepositoryMixin struct {
	// Repo is the go project package path
	Repo string
}

RepositoryMixin provides templates with a injectable repository field

func (*RepositoryMixin) InjectRepository

func (m *RepositoryMixin) InjectRepository(repository string)

InjectRepository implements HasRepository

type RequiresValidation

type RequiresValidation interface {
	Builder
	// Validate returns true if the template has valid values
	Validate() error
}

RequiresValidation is a file builder that requires validation

type ResourceMixin

type ResourceMixin struct {
	Resource *resource.Resource
}

ResourceMixin provides templates with a injectable resource field

func (*ResourceMixin) InjectResource

func (m *ResourceMixin) InjectResource(res *resource.Resource)

InjectResource implements HasResource

type Scaffold

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

Scaffold uses templates to scaffold new files

func NewScaffold

func NewScaffold(fs Filesystem, options ...ScaffoldOption) *Scaffold

NewScaffold returns a new Scaffold with the provided plugins

func (*Scaffold) Execute

func (s *Scaffold) Execute(builders ...Builder) error

Execute writes to disk the provided files

type ScaffoldOption

type ScaffoldOption func(*Scaffold)

ScaffoldOption allows to provide optional arguments to the Scaffold

func WithBoilerplate

func WithBoilerplate(boilerplate string) ScaffoldOption

WithBoilerplate provides the boilerplate to the Scaffold

func WithConfig

func WithConfig(cfg config.Config) ScaffoldOption

WithConfig provides the project configuration to the Scaffold

func WithDirectoryPermissions

func WithDirectoryPermissions(dirPerm os.FileMode) ScaffoldOption

WithDirectoryPermissions sets the permissions for new directories

func WithFilePermissions

func WithFilePermissions(filePerm os.FileMode) ScaffoldOption

WithFilePermissions sets the permissions for new files

func WithResource

func WithResource(resource *resource.Resource) ScaffoldOption

WithResource provides the resource to the Scaffold

type SetTemplateDefaultsError

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

SetTemplateDefaultsError is a wrapper error that will be used for errors returned by Template.SetTemplateDefaults

func (SetTemplateDefaultsError) Unwrap

func (e SetTemplateDefaultsError) Unwrap() error

Unwrap implements Wrapper interface

type Template

type Template interface {
	Builder
	// GetBody returns the template body
	GetBody() string
	// SetTemplateDefaults sets the default values for templates
	SetTemplateDefaults() error
}

Template is file builder based on a file template

type TemplateMixin

type TemplateMixin struct {
	PathMixin
	IfExistsActionMixin

	// TemplateBody is the template body to execute
	TemplateBody string
}

TemplateMixin is the mixin that should be embedded in Template builders

func (*TemplateMixin) GetBody

func (t *TemplateMixin) GetBody() string

GetBody implements Template

type UnknownIfExistsActionError

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

UnknownIfExistsActionError is returned if the if-exists-action is unknown

func (UnknownIfExistsActionError) Error

Error implements error interface

type UseCustomFuncMap

type UseCustomFuncMap interface {
	// GetFuncMap returns a custom FuncMap.
	GetFuncMap() template.FuncMap
}

UseCustomFuncMap allows a template to use a custom template.FuncMap instead of the default FuncMap.

type ValidateError

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

ValidateError is a wrapper error that will be used for errors returned by RequiresValidation.Validate

func (ValidateError) Unwrap

func (e ValidateError) Unwrap() error

Unwrap implements Wrapper interface

type WriteFileError

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

WriteFileError is a wrapper error that will be used for errors when writing a file

func (WriteFileError) Unwrap

func (e WriteFileError) Unwrap() error

Unwrap implements Wrapper interface

Jump to

Keyboard shortcuts

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