artifacts

package
v0.0.0-...-77eaac7 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Overview

Package artifacts provides functionality for writing artifact files in configured artifacts directory. This package operators with a singleton directory variable that can be changed and reset. It provides simple functionality that can be accessible from any calling library.

Index

Constants

View Source
const DefaultArtifactsDir = "artifacts"

Variables

View Source
var ErrFileAlreadyExists = errors.New("file already exists")

Functions

func ContextWithWriter

func ContextWithWriter(ctx context.Context, w ArtifactWriter) context.Context

ContextWithWriter adds ArtifactWriter w to the context ctx.

Types

type ArtifactWriter

type ArtifactWriter interface {
	WriteFile(filename string, contents io.Reader) (fullpathToFile string, err error)
}

ArtifactWriter is the functionality required by all implementations.

func WriterFromContext

func WriterFromContext(ctx context.Context) ArtifactWriter

WriterFromContext returns the writer from the context, or nil.

type FilesystemWriter

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

FilesystemWriter is an ArtifactWriter that targets a particular directory on the underlying filesystem.

func NewFilesystemWriter

func NewFilesystemWriter(opts ...FilesystemWriterOption) (*FilesystemWriter, error)

NewFilesystemWriter creates an artifact writer which writes to the filesystem.

func (*FilesystemWriter) Exists

func (w *FilesystemWriter) Exists(filename string) (bool, error)

Exists checks if a file exists with a filename

func (*FilesystemWriter) Path

func (w *FilesystemWriter) Path() string

Path is the full artifacts path.

func (*FilesystemWriter) Remove

func (w *FilesystemWriter) Remove(filename string) error

Remove removes contents from dir at filename.

func (*FilesystemWriter) WriteFile

func (w *FilesystemWriter) WriteFile(filename string, contents io.Reader) (string, error)

WriteFile places contents into dir at filename.

type FilesystemWriterOption

type FilesystemWriterOption = func(*FilesystemWriter)

func WithDirectory

func WithDirectory(dir string) FilesystemWriterOption

WithDirectory sets the artifacts directory to dir unless it's empty, in which case this option is ignored.

type MapWriter

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

MapWriter implements an ArtifactWriter storing contents in a map.

func NewMapWriter

func NewMapWriter() (*MapWriter, error)

NewMapWriter creates an artifact writer in memory using a map.

func (*MapWriter) Files

func (w *MapWriter) Files() map[string]io.Reader

func (*MapWriter) WriteFile

func (w *MapWriter) WriteFile(filename string, contents io.Reader) (string, error)

WriteFile places contents into files at filename.

Jump to

Keyboard shortcuts

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