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 ¶
const DefaultArtifactsDir = "artifacts"
Variables ¶
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.
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 ¶
NewMapWriter creates an artifact writer in memory using a map.