...

Package modconfig

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

Overview ▾

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

Constants

DefaultRegistry is the default registry host.

const DefaultRegistry = "registry.cue.works"

type Config

Config provides the starting point for the configuration.

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
}

type Host

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

type Host = modresolve.Host

type HostLocation

HostLocation represents a registry host and a location with it.

type HostLocation = modresolve.Location

type Registry

Registry is used to access CUE modules from external sources.

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)
}

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

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

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

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)

Resolve implements modregistry.Resolver.Resolve.