file

package
v3.0.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

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.

func IsSetTemplateDefaultsError

func IsSetTemplateDefaultsError(err error) bool

IsSetTemplateDefaultsError checks if the error was returned by Template.SetTemplateDefaults

func IsValidateError

func IsValidateError(err error) bool

IsValidateError checks if the error was returned by RequiresValidation.Validate

func NewSetTemplateDefaultsError

func NewSetTemplateDefaultsError(err error) error

NewSetTemplateDefaultsError wraps an error to specify it was returned by Template.SetTemplateDefaults

func NewValidateError

func NewValidateError(err error) error

NewValidateError wraps an error to specify it was returned by RequiresValidation.Validate

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 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 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 File

type File struct {
	// Path is the file to write
	Path string `json:"path,omitempty"`

	// Contents is the generated output
	Contents string `json:"contents,omitempty"`

	// IfExistsAction determines what to do if the file exists
	IfExistsAction IfExistsAction `json:"ifExistsAction,omitempty"`
}

File describes a file that will be written

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 (
	// Skip skips the file and moves to the next one
	Skip IfExistsAction = iota

	// Error returns an error and stops processing
	Error

	// Overwrite truncates and overwrites the existing file
	Overwrite
)

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 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 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 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 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 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.

Jump to

Keyboard shortcuts

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