core

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

README

Core Package

This package provides the core interfaces and types used throughout the application.

Components

Artifact

The Artifact type represents an artifact that can be mirrored between sources and destinations.

type Artifact struct {
    Name     string
    Version  string
    Location string
    Metadata map[string]string
}
Source Interface

The Source interface defines the contract for artifact sources:

type Source interface {
    Get(ctx context.Context, artifact *Artifact) (io.ReadCloser, error)
    List(ctx context.Context) ([]*Artifact, error)
    Validate() error
}
Destination Interface

The Destination interface defines the contract for artifact destinations:

type Destination interface {
    Put(ctx context.Context, artifact *Artifact, content io.Reader) error
    Exists(ctx context.Context, artifact *Artifact) (bool, error)
    Validate() error
}
MirrorOptions

The MirrorOptions type defines options for mirroring operations:

type MirrorOptions struct {
    PreserveStructure bool
    VerifyChecksum    bool
    Concurrent        int
    Context          context.Context
}

Usage

Creating an Artifact
artifact := &core.Artifact{
    Name:     "example",
    Version:  "1.0.0",
    Location: "path/to/artifact",
    Metadata: map[string]string{
        "key": "value",
    },
}
Implementing a Source
type CustomSource struct {
    // ... fields
}

func (s *CustomSource) Get(ctx context.Context, artifact *core.Artifact) (io.ReadCloser, error) {
    // Implementation
}

func (s *CustomSource) List(ctx context.Context) ([]*core.Artifact, error) {
    // Implementation
}

func (s *CustomSource) Validate() error {
    // Implementation
}
Implementing a Destination
type CustomDestination struct {
    // ... fields
}

func (d *CustomDestination) Put(ctx context.Context, artifact *core.Artifact, content io.Reader) error {
    // Implementation
}

func (d *CustomDestination) Exists(ctx context.Context, artifact *core.Artifact) (bool, error) {
    // Implementation
}

func (d *CustomDestination) Validate() error {
    // Implementation
}

Best Practices

  1. Always implement proper error handling in interface methods
  2. Use context for cancellation and timeouts
  3. Clean up resources properly
  4. Validate inputs and configurations
  5. Provide meaningful error messages
  6. Use appropriate logging levels
  7. Handle concurrent access safely

Documentation

Overview

Package core provides core types and constants for the garf application.

Package core provides source type detection functionality.

Package core provides validation functionality for garf parameters.

Index

Constants

View Source
const (
	// SourceTypeGitHub represents the GitHub source type for downloading from GitHub releases.
	SourceTypeGitHub = "github"

	// SourceTypeGeneric represents the generic HTTP source type for downloading from any HTTP/HTTPS URL.
	SourceTypeGeneric = "generic"
)

Source type constants.

View Source
const (
	// RegistryTypeJFrog represents the JFrog Artifactory registry type.
	RegistryTypeJFrog = "jfrog"

	// RegistryTypeCloudsmith represents the Cloudsmith registry type.
	RegistryTypeCloudsmith = "cloudsmith"
)

Registry type constants.

View Source
const (
	// GitHubHost is the standard GitHub hostname.
	GitHubHost = "github.com"
)

Variables

View Source
var ValidDestinationTypes = map[string]struct{}{
	RegistryTypeJFrog:      {},
	RegistryTypeCloudsmith: {},
}

ValidDestinationTypes contains the set of valid destination types for validation. Using map[string]struct{} for memory efficiency in set operations.

Functions

func DetectSourceType added in v0.5.0

func DetectSourceType(sourceURL, sourcePathStrip string) string

DetectSourceType determines the source type based on the URL. When sourcePathStrip is provided, it strips the prefix first to determine the actual source.

func IsGitHubURL

func IsGitHubURL(urlStr string) (bool, error)

IsGitHubURL checks if a URL is from GitHub. During testing, localhost and 127.0.0.1 are considered valid GitHub URLs.

func ParseProperties

func ParseProperties(properties []string) map[string]string

ParseProperties parses a slice of strings into a map of key-value pairs. For each string, it splits at the first '=' character and trims any surrounding whitespace from both the key and value.

func ValidateDryRunMode added in v0.5.0

func ValidateDryRunMode(dryRunMode string) error

ValidateDryRunMode validates the dry run mode parameter.

func ValidateGitHubURL

func ValidateGitHubURL(urlStr string) error

ValidateGitHubURL validates that the given URL is a GitHub URL. Returns an error if the URL is invalid or not from GitHub. During testing, localhost and 127.0.0.1 are considered valid GitHub URLs.

func ValidateSourcePathStrip added in v0.5.0

func ValidateSourcePathStrip(sourcePathStrip string) error

ValidateSourcePathStrip validates the source path strip parameter for security and correctness.

Types

type Artifact

type Artifact struct {
	// Name is the unique identifier for the artifact
	Name string

	// Version represents the artifact version
	Version string

	// Location is the source location of the artifact
	Location string

	// Metadata contains additional artifact information
	Metadata map[string]string
}

Artifact represents a single artifact that can be mirrored.

func (*Artifact) Validate

func (a *Artifact) Validate() error

Validate validates the artifact fields.

type Destination

type Destination interface {
	// Put stores an artifact in the destination and returns the destination path
	// If raw is true, keeps the original URL structure
	// Returns the final destination path/URL where the artifact was stored
	Put(ctx context.Context, artifact *Artifact, content io.Reader, raw bool) (string, error)

	// Exists checks if an artifact already exists in the destination
	// If raw is true, keeps the original URL structure
	Exists(ctx context.Context, artifact *Artifact, raw bool) (bool, error)

	// BuildDestinationPath builds the destination path without uploading
	// This is useful for dry-run mode to show where the artifact would be uploaded
	BuildDestinationPath(artifact *Artifact, raw bool) (string, error)

	// Validate checks if the destination configuration is valid
	Validate() error
}

Destination represents a location where artifacts can be stored.

type ErrorGroup

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

ErrorGroup collects multiple errors and combines them into a single error.

func NewErrorGroup

func NewErrorGroup() *ErrorGroup

NewErrorGroup creates a new ErrorGroup.

func (*ErrorGroup) Add

func (g *ErrorGroup) Add(err error)

Add adds an error to the group if it is not nil.

func (*ErrorGroup) Err

func (g *ErrorGroup) Err() error

Err returns nil if no errors were added, otherwise returns a combined error with all error messages.

type MirrorOptions

type MirrorOptions struct {
	// Context allows for cancellation and timeouts
	Context context.Context

	// Raw keeps the original URL structure instead of creating a cleaner path
	Raw bool

	// Concurrent specifies the number of concurrent mirror operations
	// If set to 0, a sensible default will be used
	Concurrent int

	// ProgressFunc is called to report progress during mirroring
	ProgressFunc func(current, total int64, message string)

	// DryRun indicates if this is a dry run operation
	DryRun bool

	// DryRunMode specifies the dry run mode: "all" or "upload"
	DryRunMode string

	// Unzip indicates if ZIP files should be extracted during mirroring
	Unzip bool

	// PreserveZipName indicates if the ZIP filename should be preserved when extracting,
	// replacing the ZIP extension with the extracted file's extension
	PreserveZipName bool

	// Checksum is the SHA256 checksum to verify the artifact against
	// If empty, no verification is performed
	Checksum string
}

MirrorOptions configures how artifacts are mirrored.

func (*MirrorOptions) Validate

func (o *MirrorOptions) Validate() error

Validate validates the mirror options.

type Source

type Source interface {
	// List returns all available artifacts from the source
	List(ctx context.Context) ([]*Artifact, error)

	// Get retrieves a specific artifact by its coordinates
	Get(ctx context.Context, artifact *Artifact) (io.ReadCloser, error)

	// Validate checks if the source configuration is valid
	Validate() error
}

Source represents a source from which artifacts can be retrieved.

Directories

Path Synopsis
Package config provides configuration management functionality.
Package config provides configuration management functionality.

Jump to

Keyboard shortcuts

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