github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/remote/registry/regclient/client.go (about)

     1  // Package regclient defines a client for interacting with a registry server
     2  package regclient
     3  
     4  import (
     5  	"errors"
     6  	"net/http"
     7  )
     8  
     9  var (
    10  	// ErrNoRegistry indicates that no registry has been specified
    11  	// all client methods MUST return ErrNoRegistry for all method calls
    12  	// when config.Registry.Location is an empty string
    13  	ErrNoRegistry = errors.New("registry: no registry specified")
    14  	// ErrNoConnection indicates no path to the registry can be found
    15  	ErrNoConnection = errors.New("registry: no connection")
    16  	// ErrNotRegistered indicates this client is not registered
    17  	ErrNotRegistered = errors.New("registry: not registered")
    18  
    19  	// HTTPClient is hoisted here in case you'd like to use a different client instance
    20  	// by default we just use http.DefaultClient
    21  	HTTPClient = http.DefaultClient
    22  )
    23  
    24  // Client wraps a registry configuration with methods for interacting
    25  // with the configured registry
    26  type Client struct {
    27  	cfg        *Config
    28  	httpClient *http.Client
    29  }
    30  
    31  // Config encapsulates options for working with a registry
    32  type Config struct {
    33  	// Location is the URL base to call to
    34  	Location string
    35  }
    36  
    37  // NewClient creates a registry from a provided Registry configuration
    38  func NewClient(cfg *Config) *Client {
    39  	return &Client{cfg, HTTPClient}
    40  }