Help us shape the future of Go! Take the 2026 Go Developer Survey

artifact

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package artifact owns generated media, output paths, persistence, and cleanup.

Index

Constants

View Source
const (
	ResponseEmptyInline = "empty inline result"
)

The internal/artifact section of the copy catalog, one constant per entry.

View Source
const SidecarExt = ".md"

SidecarExt is the Markdown extension shared by sidecar persistence and collision checks.

Variables

This section is empty.

Functions

func Cleanup

func Cleanup(artifacts []Media) error

Cleanup attempts to remove every temporary source in the supplied artifacts. It clears their TmpPath fields even on failure and returns all removal errors.

func CreateDir

func CreateDir(path string) error

CreateDir creates a directory and missing parents, accepting an existing directory.

func DefaultStem

func DefaultStem(mediaKind media.Kind) string

DefaultStem returns the default filename stem for an image or video run.

func ExpandHome

func ExpandHome(path string) (string, error)

ExpandHome replaces ~, or a leading ~ followed by a slash or the platform's separator, with the home directory, returning an error if it is unavailable. Other paths are unchanged.

func FormatExt

func FormatExt(format string) string

FormatExt returns the canonical file extension for format, or an empty string when format is unsupported.

Types

type Location

type Location struct {
	Dir    string
	Stem   string
	Ext    string
	Format string
}

Location contains the parsed components of an output path.

  • Dir: the directory portion of the path
  • Stem: the filename without its extension
  • Ext: the supported media extension as supplied
  • Format: the image format represented by Ext

func ParseOutPath

func ParseOutPath(outPath string) Location

ParseOutPath separates an output path into its directory, stem, and supported media extension. Unsupported extensions are discarded; only image extensions select an output format.

func (*Location) Resolve

func (location *Location) Resolve() error

Resolve makes the location's directory absolute, creates it, and sanitizes its stem. It updates Dir only after successful directory creation and leaves an empty stem empty.

type Media

type Media struct {
	Data    []byte
	TmpPath string
	FileExt string
}

Media contains generated media stored in memory or in a temporary file.

  • Data: the generated bytes when held in memory
  • TmpPath: the temporary file path when stored on disk
  • FileExt: the detected or fallback filename extension, including its leading period

func New

func New(data []byte, mime, fallbackExt string) (Media, error)

New returns a bytes-backed artifact with an extension inferred from its MIME type, data, or fallback extension.

type SavedFile

type SavedFile struct {
	Path  string `json:"path"`
	Bytes int64  `json:"bytes"`
}

SavedFile describes a successfully closed output file.

  • Path: the saved destination path
  • Bytes: the number of bytes written

func Write

func Write(dir, name, ext string, data []byte) (SavedFile, error)

Write exclusively creates and writes one file under the first free name.

func WriteMedia

func WriteMedia(dir, requestedStem string, mediaKind media.Kind, artifacts []Media, writesSidecar bool) (finalStem string, completedFiles []SavedFile, writeErr error)

WriteMedia saves generated media under an available stem and returns all completed files. A destination failure stops further writes. It then attempts source cleanup for every supplied artifact, clearing each TmpPath even when removal fails.

Jump to

Keyboard shortcuts

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