Documentation
¶
Index ¶
Constants ¶
const ( // DefaultFilePerms are the default file permissions for files rendered onto // disk when a specific file permission has not already been specified. DefaultFilePerms = 0644 )
Variables ¶
var ( // ErrNoParentDir is the error returned with the parent directory is missing // and the user disabled it. ErrNoParentDir = errors.New("parent directory is missing") // ErrMissingDest is the error returned with the destination is empty. ErrMissingDest = errors.New("missing destination") )
Functions ¶
func AtomicWrite ¶
func AtomicWrite(path string, createDestDirs bool, contents []byte, perms os.FileMode, backup bool) error
AtomicWrite accepts a destination path and the template contents. It writes the template contents to a TempFile on disk, returning if any errors occur.
If the parent destination directory does not exist, it will be created automatically with permissions 0755. To use a different permission, create the directory first or use `chmod` in a Command.
If the destination path exists, all attempts will be made to preserve the existing file permissions. If those permissions cannot be read, an error is returned. If the file does not exist, it will be created automatically with permissions 0644. To use a different permission, create the destination file first or use `chmod` in a Command.
If no errors occur, the Tempfile is "renamed" (moved) to the destination path.
Types ¶
type ErrChildDied ¶
type ErrChildDied struct {
// contains filtered or unexported fields
}
ErrChildDied is the error returned when the child process prematurely dies.
func NewErrChildDied ¶
func NewErrChildDied(c int) *ErrChildDied
NewErrChildDied creates a new error with the given exit code.
func (*ErrChildDied) Error ¶
func (e *ErrChildDied) Error() string
Error implements the error interface.
func (*ErrChildDied) ExitStatus ¶
func (e *ErrChildDied) ExitStatus() int
ExitStatus implements the ErrExitable interface.
type ErrExitable ¶
type ErrExitable interface {
ExitStatus() int
}
ErrExitable is an interface that defines an integer ExitStatus() function.
type RenderEvent ¶
type RenderEvent struct {
// Contents is the raw, rendered contents from the template.
Contents []byte
// UpdatedAt is the last time this render event was updated.
UpdatedAt time.Time
// WouldRender determines if the template would have been rendered. A template
// would have been rendered if all the dependencies are satisfied, but may
// not have actually rendered if the file was already present or if an error
// occurred when trying to write the file.
WouldRender bool
// LastWouldRender marks the last time the template would have rendered.
LastWouldRender time.Time
// DidRender determines if the Template was actually written to disk. In dry
// mode, this will always be false, since templates are not written to disk
// in dry mode. A template is only rendered to disk if all dependencies are
// satisfied and the template is not already in place with the same contents.
DidRender bool
// LastDidRender marks the last time the template was written to disk.
LastDidRender time.Time
}
RenderEvent captures the time and events that occurred for a template rendering.
type RenderInput ¶
type RenderInput struct {
Backup bool
Contents []byte
CreateDestDirs bool
Dry bool
DryStream io.Writer
Path string
Perms os.FileMode
}
RenderInput is used as input to the render function.
type RenderResult ¶
type RenderResult struct {
// DidRender indicates if the template rendered to disk. This will be false in
// the event of an error, but it will also be false in dry mode or when the
// template on disk matches the new result.
DidRender bool
// WouldRender indicates if the template would have rendered to disk. This
// will return false in the event of an error, but will return true in dry
// mode or when the template on disk matches the new result.
WouldRender bool
// Contents are the actual contents of the resulting template from the render
// operation.
Contents []byte
}
RenderResult is returned and stored. It contains the status of the render operation.
func Render ¶
func Render(i *RenderInput) (*RenderResult, error)
Render atomically renders a file contents to disk, returning a result of whether it would have rendered and actually did render.
type Runner ¶
type Runner struct {
//sync.Mutex
// ErrCh and DoneCh are channels where errors and finish notifications occur.
ErrCh chan error
DoneCh chan bool
// Env represents a custom set of environment variables to populate the
// template and command runtime with. These environment variables will be
// available in both the command's environment as well as the template's
// environment.
Env map[string]string
// contains filtered or unexported fields
}
Runner responsible rendering Templates and invoking Commands.
func NewRunner ¶
NewRunner accepts a slice of TemplateConfigs and returns a pointer to the new Runner and any error that occurred during creation.
func (*Runner) RenderEvents ¶
func (r *Runner) RenderEvents() map[string]*RenderEvent
RenderEvents returns the render events for each template was rendered. The map is keyed by template ID.
func (*Runner) Run ¶
Run iterates over each template in this Runner and conditionally executes the template rendering and command execution.
The template is rendered atomically. If and only if the template render completes successfully, the optional commands will be executed, if given. Please note that all templates are rendered **and then** any commands are executed.
func (*Runner) SetErrStream ¶
SetErrStream modifies runner error stream. Defaults to stderr.
func (*Runner) SetOutStream ¶
SetOutStream modifies runner output stream. Defaults to stdout.
func (*Runner) Signal ¶
Signal sends a signal to the child process, if it exists. Any errors that occur are returned.