Documentation
¶
Index ¶
- Constants
- func DefaultFuncMap() template.FuncMap
- func SubstituteYear(boilerplate string) string
- type BoilerplateMixin
- type Builder
- type CloseFileError
- type CodeFragments
- type CodeFragmentsMap
- type CreateDirectoryError
- type CreateFileError
- type DomainMixin
- type ExistsFileError
- type File
- type FileAlreadyExistsError
- type Filesystem
- type HasBoilerplate
- type HasDomain
- type HasIfNotExistsAction
- type HasMultiGroup
- type HasNamespaced
- type HasProjectName
- type HasRepository
- type HasResource
- type IfExistsAction
- type IfExistsActionMixin
- type IfNotExistsAction
- type IfNotExistsActionMixin
- type Inserter
- type InserterMixin
- type Marker
- type ModelAlreadyExistsError
- type MultiGroupMixin
- type NamespacedMixin
- type OpenFileError
- type PathMixin
- type ProjectNameMixin
- type ReadFileError
- type RepositoryMixin
- type RequiresValidation
- type ResourceMixin
- type Scaffold
- type ScaffoldOption
- type SetTemplateDefaultsError
- type Template
- type TemplateMixin
- type UnknownIfExistsActionError
- type UseCustomFuncMap
- type ValidateError
- type WriteFileError
Constants ¶
const ( // DefaultDirectoryPermission and DefaultFilePermission are used so generated // files work in shared and container workflows. Use them when writing scaffolded // or config files for consistency. DefaultDirectoryPermission os.FileMode = 0o755 DefaultFilePermission os.FileMode = 0o644 )
Variables ¶
This section is empty.
Functions ¶
func DefaultFuncMap ¶
DefaultFuncMap returns the default template.FuncMap for rendering the template.
func SubstituteYear ¶ added in v4.14.0
SubstituteYear replaces every occurrence of "YEAR" in the boilerplate string with the current UTC year.
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 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
// IfNotExistsAction determines what to do if the file is missing (optional updates only)
IfNotExistsAction IfNotExistsAction
}
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 ¶
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 HasDomain ¶
type HasDomain interface {
// InjectDomain sets the template domain
InjectDomain(string)
}
HasDomain allows the domain to be used on a template
type HasIfNotExistsAction ¶ added in v4.8.0
type HasIfNotExistsAction interface {
GetIfNotExistsAction() IfNotExistsAction
}
HasIfNotExistsAction allows a template to define an action if the file is missing
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 HasNamespaced ¶ added in v4.12.0
type HasNamespaced interface {
// InjectNamespaced sets the template namespaced flag
InjectNamespaced(bool)
}
HasNamespaced allows the namespaced 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 IfNotExistsAction ¶ added in v4.8.0
type IfNotExistsAction int
IfNotExistsAction determines what to do if a file to be updated does not exist
const ( // ErrorIfNotExist returns an error and stops processing (default behavior) ErrorIfNotExist IfNotExistsAction = iota // IgnoreFile skips the file and logs a message if it does not exist IgnoreFile )
type IfNotExistsActionMixin ¶ added in v4.8.0
type IfNotExistsActionMixin struct {
// IfNotExistsAction determines what to do if the file does not exist
IfNotExistsAction IfNotExistsAction
}
IfNotExistsActionMixin provides file builders with an if-not-exists-action field
func (*IfNotExistsActionMixin) GetIfNotExistsAction ¶ added in v4.8.0
func (m *IfNotExistsActionMixin) GetIfNotExistsAction() IfNotExistsAction
GetIfNotExistsAction implements Inserter
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 ¶
NewMarkerFor creates a new marker customized for the specific file. The created marker is prefixed with `+kubebuilder:scaffold:` the default prefix for kubebuilder. Supported file extensions: .go, .yaml, .yml.
func NewMarkerWithPrefixFor ¶ added in v4.1.0
NewMarkerWithPrefixFor creates a new custom prefixed marker customized for the specific file Supported file extensions: .go, .yaml, .yml
func (Marker) EqualsLine ¶
EqualsLine compares a marker with a string representation to check if they are the same marker
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 NamespacedMixin ¶ added in v4.12.0
type NamespacedMixin struct {
// Namespaced is the namespaced flag
Namespaced bool
}
NamespacedMixin provides templates with a injectable namespaced flag field
func (*NamespacedMixin) InjectNamespaced ¶ added in v4.12.0
func (m *NamespacedMixin) InjectNamespaced(flag bool)
InjectNamespaced implements HasNamespaced
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
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 ¶
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
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. Any YEAR placeholder in the boilerplate is substituted with the current year.
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(res *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
// SetDelim sets an action delimiters to replace default delimiters: {{ }}
SetDelim(left, right string)
// GetDelim returns the alternative delimiters
GetDelim() (string, string)
}
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
// contains filtered or unexported fields
}
TemplateMixin is the mixin that should be embedded in Template builders
func (*TemplateMixin) GetBody ¶
func (t *TemplateMixin) GetBody() string
GetBody implements Template
func (*TemplateMixin) GetDelim ¶
func (t *TemplateMixin) GetDelim() (string, string)
GetDelim implements Template
func (*TemplateMixin) SetDelim ¶
func (t *TemplateMixin) SetDelim(left, right string)
SetDelim 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 ¶
func (e UnknownIfExistsActionError) Error() string
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