reference

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

Package reference

Purpose

Provides parsing and manipulation of OCI container image references, supporting tags, digests, registries, and repository paths.

Functionality

  • Reference parsing - Parse image reference strings into structured components
  • Component extraction - Extract domain, path, tag, and digest from references
  • Name formatting - Generate full names and familiar (shortened) names
  • Pattern matching - Check if references match familiar patterns
  • Container naming - Generate suggested container names based on image references
  • Digest support - Parse and handle both full and short digest formats
  • Tag normalization - Automatically applies "latest" tag when no tag specified

Public API

type ImageReference struct {
    Protocol    Protocol
    Digest      digest.Digest
    Tag         string
    ExplicitTag string // Tag explicitly specified in input (empty if omitted)
    Path        string
    Domain      string
}

// Parsing
func Parse(rawRef string) (*ImageReference, error)

// Methods
func (ir *ImageReference) Name() string                              // Full name (domain/path)
func (ir *ImageReference) FamiliarName() string                      // Shortened name
func (ir *ImageReference) FamiliarMatch(pattern string) (bool, error) // Pattern matching
func (ir *ImageReference) String() string                            // String representation
func (ir *ImageReference) SuggestContainerName(suffix string) string // Generate container name

// Exported error types
var (
    ErrInvalidImageReference error
    ErrInvalidPattern        error
)

Design

  • Reference normalization: Uses distribution/reference library for standardized parsing
  • Tag defaulting: Automatically adds "latest" tag via TagNameOnly when no tag specified
  • Digest detection: Tries parsing as digest first (with and without "sha256:" prefix)
  • Protocol support: Special handling for non-registry protocols (via Protocol field)
  • Familiar names: Follows Docker conventions for shortened display names
  • Container naming: Generates safe container names from image references (base name + suffix)

Reference Format Support

Supported reference formats:

  • registry.example.com/namespace/image:tag
  • namespace/image:tag (uses default registry)
  • image:tag (uses default registry and namespace)
  • image (adds "latest" tag automatically)
  • registry.example.com/namespace/image@sha256:abc123...
  • sha256:abc123... (digest-only reference)
  • abc123... (short digest, automatically prefixed with "sha256:")

Dependencies

  • External: distribution/reference for OCI reference parsing, opencontainers/go-digest for digest handling
  • Internal: None (standalone module)

Security Considerations

  • Input validation: All references validated and normalized via distribution/reference
  • Digest verification: Full digest format support for content-addressable pulls
  • No string injection: Uses type-safe digest and reference types, not string concatenation

Documentation

Overview

Package reference to manipulate image references.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidImageReference indicates that the image reference is invalid.
	ErrInvalidImageReference = errors.New("invalid image reference")
	// ErrInvalidPattern indicates that the pattern used to parse the image reference is invalid.
	ErrInvalidPattern = errors.New("invalid pattern")
)

Functions

This section is empty.

Types

type ImageReference

type ImageReference struct {
	Protocol    Protocol
	Digest      digest.Digest
	Tag         string
	ExplicitTag string
	Path        string
	Domain      string
	// contains filtered or unexported fields
}

ImageReference represents a reference to an image, which may include a protocol, domain, path, tag, and digest.

func Parse

func Parse(rawRef string) (*ImageReference, error)

Parse parses a raw image reference string and returns an ImageReference object.

func (*ImageReference) FamiliarMatch

func (ir *ImageReference) FamiliarMatch(pattern string) (bool, error)

FamiliarMatch checks if the image reference matches a familiar pattern.

func (*ImageReference) FamiliarName

func (ir *ImageReference) FamiliarName() string

FamiliarName returns a familiar (eg: shortened) name for the image reference.

func (*ImageReference) Name

func (ir *ImageReference) Name() string

Name returns the name of the image reference, including the domain and path.

func (*ImageReference) String

func (ir *ImageReference) String() string

String returns the string representation of the image reference.

func (*ImageReference) SuggestContainerName

func (ir *ImageReference) SuggestContainerName(suffix string) string

SuggestContainerName generates a suggested container name based on the image reference.

type Protocol

type Protocol string

Protocol represents the protocol used for the image reference.

Jump to

Keyboard shortcuts

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