renderer

package
Version: v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: MPL-2.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

View Source
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

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

Please note that this is only atomic on POSIX systems. It is not atomic on Windows and it is impossible to rename atomically on Windows. For more on this see: https://github.com/golang/go/issues/22397#issuecomment-498856679

Types

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.

Jump to

Keyboard shortcuts

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