connstr

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package connstr provides utilties to parse and resolve Couchbase SDK style connection string.

Index

Constants

View Source
const (
	// DefaultHTTPPort is the default http management port for Couchbase Server. Will be used when no port is supplied
	// when using a non-ssl scheme.
	DefaultHTTPPort = 8091

	// DefaultHTTPSPort is the default https management port for Couchbase Server. Will be used when no port is supplied
	// when using a ssl scheme.
	DefaultHTTPSPort = 18091
)

Variables

View Source
var (
	// ErrInvalidConnectionString is returned if the part matching regex results in a <nil> return value i.e. it doesn't
	// match against the input string.
	ErrInvalidConnectionString = errors.New("invalid connection string")

	// ErrNoAddressesParsed is returned when the resulting parsed connection string doesn't contain any addresses.
	ErrNoAddressesParsed = errors.New("parsed connection string contains no addresses")

	// ErrNoAddressesResolved is returned when the resolved connection string doesn't contain any addresses.
	ErrNoAddressesResolved = errors.New("resolved connection string contains no addresses")

	// ErrBadScheme is returned if the user supplied a scheme that's not supported. Currently 'http', 'https',
	// 'couchbase' and 'couchbases' are supported.
	ErrBadScheme = errors.New("bad scheme")

	// ErrBadPort is returned if the parsed port is an invalid 16 bit unsigned integer.
	ErrBadPort = errors.New("bad port")
)

Functions

This section is empty.

Types

type Address

type Address struct {
	// Host is a IP/DNS hostname.
	Host string

	// Port is a port number.
	//
	// NOTE: May be zero if omitted by the user.
	Port uint16
}

Address represents an address used to connect to Couchbase Server. Should not be used directly i.e. access should be provided through a 'ConnectionString' or a 'ResolvedConnectionString'.

type ConnectionString

type ConnectionString struct {
	// Scheme is the parsed scheme without '://'.
	Scheme string

	// Addresses represents the node addresses, this value must be non-empty.
	//
	// NOTE: This attribute is required, and must be non-empty.
	Addresses []Address

	// Params are any parsed query parameters, will be <nil> if none were parsed.
	Params url.Values
}

ConnectionString represents a connection string that can be supplied to the 'backup' tools to give the tools a node or nodes in a cluster to bootstrap from.

func Parse

func Parse(connectionString string) (*ConnectionString, error)

Parse the given connection string and perform first tier validation i.e. it's possible for a parsed connection string to fail when the 'Resolve' function is called.

For more information on the connection string formats accepted by this function, refer to the host formats documentation at https://docs.couchbase.com/server/7.0/backup-restore/cbbackupmgr-backup.html#host-formats.

func (*ConnectionString) Resolve

Resolve the current connection string and return addresses which can be used to bootstrap from. Will perform additional validation, once resolved the connection string is valid and can be used.

type ResolvedConnectionString

type ResolvedConnectionString struct {
	// UseSSL indicates whether SSL should be used when connecting to the hosts.
	UseSSL bool

	// Addresses represents the resolved addresses for the cluster nodes.
	//
	// NOTE: This attribute is required, and must be non-empty.
	Addresses []Address

	// Params are any parsed query parameters, will be <nil> if none were parsed.
	Params url.Values
}

ResolvedConnectionString is similar to a 'ConnectionString', however, addresses are resolved i.e. ports/schemes are converted into something that we can use to bootstrap from.

NOTE: If provided with a valid srv record (an address with the scheme 'couchbase' or 'couchbases', and no port). This function will lookup the srv record and use those addresses.

Jump to

Keyboard shortcuts

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