gocuelang.org/go/mod/modconfig Index | Files

package modconfig

import "cuelang.org/go/mod/modconfig"

Package modconfig provides access to the standard CUE module configuration, including registry access and authorization.

Index

Constants

const DefaultRegistry = "registry.cue.works"

DefaultRegistry is the default registry host.

Types

type Config

type Config struct {

	// Transport is used to make the underlying HTTP requests.
	// If it's nil, [http.DefaultTransport] will be used.
	Transport http.RoundTripper

	// Env provides environment variable values. If this is nil,
	// the current process's environment will be used.
	Env []string

	// ClientType is used as part of the User-Agent header
	// that's added in each outgoing HTTP request.
	// If it's empty, it defaults to "cuelang.org/go".
	ClientType string
}

Config provides the starting point for the configuration.

type Host

type Host = modresolve.Host

Host represents a registry host name and whether it should be accessed via a secure connection or not.

type HostLocation

type HostLocation = modresolve.Location

HostLocation represents a registry host and a location with it.

type Registry

type Registry interface {
	// Requirements returns a list of the modules required by the given module
	// version.
	Requirements(ctx context.Context, m module.Version) ([]module.Version, error)

	// Fetch returns the location of the contents for the given module
	// version, downloading it if necessary.
	Fetch(ctx context.Context, m module.Version) (module.SourceLoc, error)

	// ModuleVersions returns all the versions for the module with the
	// given path, which should contain a major version.
	ModuleVersions(ctx context.Context, mpath string) ([]string, error)
}

Registry is used to access CUE modules from external sources.

func NewRegistry

func NewRegistry(cfg *Config) (Registry, error)

NewRegistry returns an implementation of the Registry interface suitable for passing to [load.Instances]. It uses the standard CUE cache directory.

type Resolver

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

Resolver implements modregistry.Resolver in terms of the CUE registry configuration file and auth configuration.

func NewResolver

func NewResolver(cfg *Config) (*Resolver, error)

NewResolver returns an implementation of modregistry.Resolver that uses cfg to guide registry resolution. If cfg is nil, it's equivalent to passing pointer to a zero Config struct.

It consults the same environment variables used by the cue command.

The contents of the configuration will not be mutated.

func (*Resolver) AllHosts

func (r *Resolver) AllHosts() []Host

AllHosts returns all the registry hosts that the resolver might resolve to, ordered lexically by hostname.

func (*Resolver) ResolveToLocation

func (r *Resolver) ResolveToLocation(mpath string, version string) (HostLocation, bool)

ResolveToLocation returns the host location for the given module path and version without creating a Registry instance for it.

func (*Resolver) ResolveToRegistry

func (r *Resolver) ResolveToRegistry(mpath string, version string) (modregistry.RegistryLocation, error)

ResolveToRegistry implements modregistry.Resolver.ResolveToRegistry.

Source Files

modconfig.go

Version
v0.12.0 (latest)
Published
Jan 30, 2025
Platform
linux/amd64
Imports
19 packages
Last checked
8 hours ago

Tools for package owners.