catalog

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package catalog defines the extension catalog

A catalog maps a dependency for k6 extension with optional semantic versioning constrains to the corresponding golang modules.

For example `k6/x/output-kafka:>0.1.0` ==> `github.com/grafana/xk6-output-kafka@v0.2.0`

The catalog is a json file with the following schema:

	{
	     "<dependency>": {
              "module": "<module path>",
              "versions": ["<version>", "<version>", ... "<version>"],
              "cgo": <bool>
	     },
	}

where: <dependency>: is the import path for the dependency module: is the path to the go module that implements the dependency versions: is the list of supported versions cgo: is a boolean that indicates if the module requires cgo

Example:

{
     "k6": {"module": "go.k6.io/k6", "versions": ["v0.50.0", "v0.51.0"]},
     "k6/x/kubernetes": {"module": "github.com/grafana/xk6-kubernetes", "versions": ["v0.8.0","v0.9.0"]},
     "k6/x/output-kafka": {"module": "github.com/grafana/xk6-output-kafka", "versions": ["v0.7.0"]},
     "k6/x/xk6-sql-driver-sqlite3": {"module": "github.com/grafana/xk6-sql", "cgo": true, "versions": ["v0.1.0"]}
}

Index

Constants

View Source
const (
	DefaultCatalogFile = "catalog.json"                        //nolint:revive
	DefaultCatalogURL  = "https://registry.k6.io/catalog.json" //nolint:revive
)

Variables

View Source
var (
	ErrCannotSatisfy     = errors.New("cannot satisfy dependency") //nolint:revive
	ErrDownload          = errors.New("downloading catalog")
	ErrInvalidConstrain  = errors.New("invalid constrain")
	ErrInvalidCatalog    = fmt.Errorf("invalid catalog")
	ErrOpening           = errors.New("opening catalog")
	ErrUnknownDependency = errors.New("unknown dependency")
)

Functions

This section is empty.

Types

type Catalog

type Catalog interface {
	// Resolve returns a Module that satisfies a Dependency
	Resolve(ctx context.Context, dep Dependency) (Module, error)
}

Catalog defines the interface of the extension catalog service

func DefaultCatalog

func DefaultCatalog() (Catalog, error)

DefaultCatalog creates a Catalog from the default catalog URL

func NewCatalog

func NewCatalog(ctx context.Context, location string) (Catalog, error)

NewCatalog returns a catalog loaded from a location. The location can be a local path or an URL

func NewCatalogFromFile

func NewCatalogFromFile(catalogFile string) (Catalog, error)

NewCatalogFromFile creates a Catalog from a json file

func NewCatalogFromJSON

func NewCatalogFromJSON(stream io.Reader) (Catalog, error)

NewCatalogFromJSON creates a Catalog from a json file that follows the [schema](./schema.json):

func NewCatalogFromURL

func NewCatalogFromURL(ctx context.Context, catalogURL string) (Catalog, error)

NewCatalogFromURL creates a Catalog from a URL

type Dependency

type Dependency struct {
	Name       string `json:"name,omitempty"`
	Constrains string `json:"constrains,omitempty"`
}

Dependency defines a Dependency with a version constrain Examples: Name: k6/x/k6-kubernetes Constrains * Name: k6/x/k6-output-kafka Constrains >v0.9.0

type Module

type Module struct {
	Path    string `json:"path,omitempty"`
	Version string `json:"version,omitempty"`
	Cgo     bool   `json:"cgo,omitempty"`
}

Module defines a go module that resolves a Dependency

Jump to

Keyboard shortcuts

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