roxyutil

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package roxyutil provides miscellaneous utility functions for use by Roxy and by users of mainutil.

As with mainutil, it is undecided how much (if any) of the roxyutil API will remain available outside of the Roxy project once Roxy reaches v1.0.0.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedToMatch          = inputError("failed to match expected pattern")
	ErrExpectEmpty            = inputError("expected empty string")
	ErrExpectEmptyOrLocalhost = inputError("expected empty string or \"localhost\"")
	ErrExpectNonEmpty         = inputError("expected non-empty string")
	ErrExpectOneSlash         = inputError("expected one '/', found 2 or more")
	ErrExpectLeadingSlash     = inputError("expected path to start with '/'")
	ErrExpectTrailingSlash    = inputError("expected path to end with '/'")
	ErrExpectNoEndSlash       = inputError("did not expect path to end with '/'")
	ErrExpectNoDoubleSlash    = inputError("did not expect path to contain '//'")
	ErrExpectNoDot            = inputError("did not expect path to contain '/./'")
	ErrExpectNoDotDot         = inputError("did not expect path to contain '/../'")
	ErrExpectEmptyList        = inputError("expected empty list")
	ErrExpectNonEmptyList     = inputError("expected non-empty list")
)

ErrFailedToMatch et al signal that input parsing has failed.

View Source
var ErrIsNull = isNullError(0)

ErrIsNull indicates that a JSON null value was parsed.

View Source
var ErrNoHealthyBackends = noHealthyBackendsError(0)

ErrNoHealthyBackends signals that a roxyresolver.Resolver was unable to find any healthy servers to talk to.

View Source
var ErrNotExist = notExistError(0)

ErrNotExist signals that something does not exist.

Functions

func Assert added in v0.5.0

func Assert(cond bool, message string)

Assert panics with CheckError if cond is false.

func AssertNotNil added in v0.5.0

func AssertNotNil(v interface{})

AssertNotNil takes a pointer to a nil-able type (pointer, interface, etc) and panics with CheckError if the pointed-to value is nil.

func Assertf added in v0.5.0

func Assertf(cond bool, format string, v ...interface{})

Assertf panics with CheckError if cond is false.

func ExpandPassword

func ExpandPassword(in string) (string, error)

ExpandPassword expands ${ENV_VAR} references and @file references.

func ExpandPath

func ExpandPath(in string) (string, error)

ExpandPath expands ${ENV_VAR} references, ~ and ~user references, and makes the path absolute (by assuming it is relative to the current directory).

func ExpandPathWithCWD added in v0.4.8

func ExpandPathWithCWD(in string, cwd string) (string, error)

ExpandPathWithCWD expands ${ENV_VAR} references, ~ and ~user references, and makes the path absolute (by assuming it is relative to the given cwd).

func ExpandString

func ExpandString(in string) (string, error)

ExpandString expands ${ENV_VAR} references.

func LookupGroupByID added in v0.4.6

func LookupGroupByID(gid uint32) (*user.Group, error)

LookupGroupByID is a wrapper around "os/user".LookupGroupId.

func LookupGroupByName added in v0.4.6

func LookupGroupByName(groupName string) (*user.Group, error)

LookupGroupByName is a wrapper around "os/user".LookupGroup.

func LookupHost added in v0.4.7

func LookupHost(ctx context.Context, res *net.Resolver, hostname string) ([]net.IP, error)

LookupHost is a wrapper around "net".(*Resolver).LookupHost.

func LookupPort added in v0.4.7

func LookupPort(ctx context.Context, res *net.Resolver, network string, service string) (uint16, error)

LookupPort is a wrapper around "net".(*Resolver).LookupPort.

func LookupSRV added in v0.4.7

func LookupSRV(ctx context.Context, res *net.Resolver, service, network, domain string) (string, []*net.SRV, error)

LookupSRV is a wrapper around "net".(*Resolver).LookupSRV.

func LookupUserByID added in v0.4.6

func LookupUserByID(uid uint32) (*user.User, error)

LookupUserByID is a wrapper around "os/user".LookupId.

func LookupUserByName added in v0.4.6

func LookupUserByName(userName string) (*user.User, error)

LookupUserByName is a wrapper around "os/user".Lookup.

func MakeAllowedEnumNames added in v0.4.7

func MakeAllowedEnumNames(enumData []EnumData) []string

MakeAllowedEnumNames returns the list of canonical string representations for this enum.

func MarshalEnumToJSON added in v0.4.7

func MarshalEnumToJSON(enumName string, enumData []EnumData, value uint) ([]byte, error)

MarshalEnumToJSON marshals this enum value to JSON. It may panic with InvalidEnumValueError if the enum value is out of range.

func ParseEnum added in v0.4.7

func ParseEnum(enumName string, enumData []EnumData, str string) (uint, error)

ParseEnum parses an enum value. Returns InvalidEnumNameError if the string cannot be parsed.

func PathAbs added in v0.4.6

func PathAbs(str string) (string, error)

PathAbs is a wrapper around "path/filepath".Abs.

func UnmarshalEnumFromJSON added in v0.4.7

func UnmarshalEnumFromJSON(enumName string, enumData []EnumData, raw []byte) (uint, error)

UnmarshalEnumFromJSON unmarshals an enum value from JSON. Returns ErrIsNull, InvalidEnumNameError, or InvalidEnumValueError if a JSON value was parsed but could not be unmarshaled as an enum value.

func ValidateATCLocation

func ValidateATCLocation(str string) error

ValidateATCLocation validates that the given string is a valid Location for the Air Traffic Control service.

func ValidateATCServiceName

func ValidateATCServiceName(str string) error

ValidateATCServiceName validates that the given string is a valid Service Name for the Air Traffic Control service.

func ValidateATCUniqueID added in v0.6.0

func ValidateATCUniqueID(str string) error

ValidateATCUniqueID validates that the given string is a valid UniqueID for the Air Traffic Control service.

func ValidateEtcdPath

func ValidateEtcdPath(str string) error

ValidateEtcdPath validates that the given string is a valid etcd.io V3 key prefix, which must end with a "/".

func ValidateNamedPort

func ValidateNamedPort(str string) error

ValidateNamedPort validates that the given string is a valid named port for a membership.Roxy or membership.ServerSet address advertisement.

func ValidateZKPath

func ValidateZKPath(str string) error

ValidateZKPath validates that the given string is a valid ZooKeeper node path.

Types

type ATCLoadUniqueError added in v0.6.0

type ATCLoadUniqueError struct {
	Err error
}

ATCLoadUniqueError represents failure to load or persist a stable unique ID.

func (ATCLoadUniqueError) Error added in v0.6.0

func (err ATCLoadUniqueError) Error() string

Error fulfills the error interface.

func (ATCLoadUniqueError) Unwrap added in v0.6.0

func (err ATCLoadUniqueError) Unwrap() error

Unwrap returns the underlying cause of this error.

type ATCLocationError added in v0.4.6

type ATCLocationError struct {
	Location string
	Err      error
}

ATCLocationError represents failure to parse an ATC location.

func (ATCLocationError) Error added in v0.4.6

func (err ATCLocationError) Error() string

Error fulfills the error interface.

func (ATCLocationError) Unwrap added in v0.4.6

func (err ATCLocationError) Unwrap() error

Unwrap returns the underlying cause of this error.

type ATCServiceNameError added in v0.4.6

type ATCServiceNameError struct {
	ServiceName string
	Err         error
}

ATCServiceNameError represents failure to parse an ATC service name.

func (ATCServiceNameError) Error added in v0.4.6

func (err ATCServiceNameError) Error() string

Error fulfills the error interface.

func (ATCServiceNameError) Unwrap added in v0.4.6

func (err ATCServiceNameError) Unwrap() error

Unwrap returns the underlying cause of this error.

type ATCShardNumberError added in v0.6.0

type ATCShardNumberError struct {
	ShardNumber string
	Err         error
}

ATCShardNumberError represents failure to parse an ATC shard number.

func (ATCShardNumberError) Error added in v0.6.0

func (err ATCShardNumberError) Error() string

Error fulfills the error interface.

func (ATCShardNumberError) Unwrap added in v0.6.0

func (err ATCShardNumberError) Unwrap() error

Unwrap returns the underlying cause of this error.

type ATCUniqueIDError added in v0.6.0

type ATCUniqueIDError struct {
	UniqueID string
	Err      error
}

ATCUniqueIDError represents failure to parse an ATC unique ID.

func (ATCUniqueIDError) Error added in v0.6.0

func (err ATCUniqueIDError) Error() string

Error fulfills the error interface.

func (ATCUniqueIDError) Unwrap added in v0.6.0

func (err ATCUniqueIDError) Unwrap() error

Unwrap returns the underlying cause of this error.

type AuthorityError added in v0.4.6

type AuthorityError struct {
	Authority string
	Err       error
}

AuthorityError represents failure to parse a URL authority section or a Target authority section.

func (AuthorityError) Error added in v0.4.6

func (err AuthorityError) Error() string

Error fulfills the error interface.

func (AuthorityError) Unwrap added in v0.4.6

func (err AuthorityError) Unwrap() error

Unwrap returns the underlying cause of this error.

type BoolError added in v0.4.6

type BoolError struct {
	Input string
	Err   error
}

BoolError represents failure to parse the string representation of a boolean value.

func (BoolError) Error added in v0.4.6

func (err BoolError) Error() string

Error fulfills the error interface.

func (BoolError) Unwrap added in v0.4.6

func (err BoolError) Unwrap() error

Unwrap returns the underlying cause of this error.

type CheckError added in v0.4.7

type CheckError struct {
	Message string
}

CheckError represents an assertion failure.

func (CheckError) Error added in v0.4.7

func (err CheckError) Error() string

Error fulfills the error interface.

type EndpointError added in v0.4.6

type EndpointError struct {
	Endpoint string
	Err      error
}

EndpointError represents failure to parse a Target endpoint section.

func (EndpointError) Error added in v0.4.6

func (err EndpointError) Error() string

Error fulfills the error interface.

func (EndpointError) Unwrap added in v0.4.6

func (err EndpointError) Unwrap() error

Unwrap returns the underlying cause of this error.

type EnumData added in v0.4.7

type EnumData struct {
	// GoName is the Go constant name for this enum value.
	GoName string

	// Name is the string representation of this enum value.
	Name string

	// JSON is the JSON representation of this enum value.
	//
	// Optional; it is inferred from Name if not set.
	JSON []byte

	// Aliases is a list of zero or more aliases for this enum value.
	//
	// Optional.
	Aliases []string
}

EnumData holds data about one particular enum value.

func DereferenceEnumData added in v0.4.7

func DereferenceEnumData(enumName string, enumData []EnumData, value uint) EnumData

DereferenceEnumData returns enumData[value] or panics with InvalidEnumValueError.

type EnvVarLookupError added in v0.4.6

type EnvVarLookupError struct {
	Var string
	Err error
}

EnvVarLookupError represents failure to look up an environment variable.

func (EnvVarLookupError) Error added in v0.4.6

func (err EnvVarLookupError) Error() string

Error fulfills the error interface.

func (EnvVarLookupError) Unwrap added in v0.4.6

func (err EnvVarLookupError) Unwrap() error

Unwrap returns the underlying cause of this error.

type ExpectLiteralError added in v0.4.7

type ExpectLiteralError string

ExpectLiteralError represents failure to parse an input.

func (ExpectLiteralError) Error added in v0.4.7

func (err ExpectLiteralError) Error() string

Error fulfills the error interface.

func (ExpectLiteralError) GRPCStatusCode added in v0.4.7

func (err ExpectLiteralError) GRPCStatusCode() codes.Code

GRPCStatusCode returns the GRPC status code "InvalidArgument".

type GRPCStatusError added in v0.4.6

type GRPCStatusError struct {
	Code codes.Code
	Err  error
}

GRPCStatusError represents an error with an associated GRPC status code.

func MakeGRPCStatusError added in v0.4.6

func MakeGRPCStatusError(err error) GRPCStatusError

MakeGRPCStatusError attempts to autodetect the correct status code.

func (GRPCStatusError) Error added in v0.4.6

func (err GRPCStatusError) Error() string

Error fulfills the error interface.

func (GRPCStatusError) GRPCStatus added in v0.4.6

func (err GRPCStatusError) GRPCStatus() *status.Status

GRPCStatus returns this error's representation as a gRPC Status.

func (GRPCStatusError) Unwrap added in v0.4.6

func (err GRPCStatusError) Unwrap() error

Unwrap returns the underlying cause of this error.

type HostError added in v0.4.6

type HostError struct {
	Host string
	Err  error
}

HostError represents failure to parse a hostname string.

func (HostError) Error added in v0.4.6

func (err HostError) Error() string

Error fulfills the error interface.

func (HostError) Unwrap added in v0.4.6

func (err HostError) Unwrap() error

Unwrap returns the underlying cause of this error.

type HostPortError added in v0.4.6

type HostPortError struct {
	HostPort string
	Err      error
}

HostPortError represents failure to parse a "host:port"-shaped string.

func (HostPortError) Error added in v0.4.6

func (err HostPortError) Error() string

Error fulfills the error interface.

func (HostPortError) Unwrap added in v0.4.6

func (err HostPortError) Unwrap() error

Unwrap returns the underlying cause of this error.

type IPError added in v0.4.6

type IPError struct {
	IP  string
	Err error
}

IPError represents failure to parse an IP address string.

func (IPError) Error added in v0.4.6

func (err IPError) Error() string

Error fulfills the error interface.

func (IPError) Unwrap added in v0.4.6

func (err IPError) Unwrap() error

Unwrap returns the underlying cause of this error.

type InvalidEnumNameError added in v0.4.7

type InvalidEnumNameError struct {
	Type    string
	Name    string
	Allowed []string
}

InvalidEnumNameError indicates an enum whose string representation could not be recognized.

func (InvalidEnumNameError) Error added in v0.4.7

func (err InvalidEnumNameError) Error() string

Error fulfills the error interface.

type InvalidEnumValueError added in v0.4.7

type InvalidEnumValueError struct {
	Type  string
	Value uint
	Limit uint
}

InvalidEnumValueError indicates an enum whose numeric value is out of range.

func (InvalidEnumValueError) Error added in v0.4.7

func (err InvalidEnumValueError) Error() string

Error fulfills the error interface.

type ListIndexError added in v0.4.7

type ListIndexError struct {
	List  string
	Index uint
	Value interface{}
	Err   error
}

ListIndexError indicates an error in one item of a list.

func (ListIndexError) Error added in v0.4.7

func (err ListIndexError) Error() string

Error fulfills the error interface.

func (ListIndexError) Unwrap added in v0.4.7

func (err ListIndexError) Unwrap() error

Unwrap returns the underlying cause of this error.

type LookupGroupByIDError added in v0.4.6

type LookupGroupByIDError struct {
	ID  uint32
	Err error
}

LookupGroupByIDError represents failure to look up an OS group by GID.

func (LookupGroupByIDError) Error added in v0.4.6

func (err LookupGroupByIDError) Error() string

Error fulfills the error interface.

func (LookupGroupByIDError) Unwrap added in v0.4.6

func (err LookupGroupByIDError) Unwrap() error

Unwrap returns the underlying cause of this error.

type LookupGroupByNameError added in v0.4.6

type LookupGroupByNameError struct {
	Name string
	Err  error
}

LookupGroupByNameError represents failure to look up an OS group by name.

func (LookupGroupByNameError) Error added in v0.4.6

func (err LookupGroupByNameError) Error() string

Error fulfills the error interface.

func (LookupGroupByNameError) Unwrap added in v0.4.6

func (err LookupGroupByNameError) Unwrap() error

Unwrap returns the underlying cause of this error.

type LookupHostError added in v0.4.7

type LookupHostError struct {
	Host string
	Err  error
}

LookupHostError represents failure to look up DNS A/AAAA records.

func (LookupHostError) Error added in v0.4.7

func (err LookupHostError) Error() string

Error fulfills the error interface.

func (LookupHostError) Unwrap added in v0.4.7

func (err LookupHostError) Unwrap() error

Unwrap returns the underlying cause of this error.

type LookupPortError added in v0.4.7

type LookupPortError struct {
	Net  string
	Port string
	Err  error
}

LookupPortError represents failure to look up a network port by service name, using /etc/services or the like.

func (LookupPortError) Error added in v0.4.7

func (err LookupPortError) Error() string

Error fulfills the error interface.

func (LookupPortError) Unwrap added in v0.4.7

func (err LookupPortError) Unwrap() error

Unwrap returns the underlying cause of this error.

type LookupSRVError added in v0.4.7

type LookupSRVError struct {
	Service string
	Network string
	Domain  string
	Err     error
}

LookupSRVError represents failure to look up DNS SRV records.

func (LookupSRVError) Error added in v0.4.7

func (err LookupSRVError) Error() string

Error fulfills the error interface.

func (LookupSRVError) Unwrap added in v0.4.7

func (err LookupSRVError) Unwrap() error

Unwrap returns the underlying cause of this error.

type LookupUserByIDError added in v0.4.6

type LookupUserByIDError struct {
	ID  uint32
	Err error
}

LookupUserByIDError represents failure to look up an OS user by UID.

func (LookupUserByIDError) Error added in v0.4.6

func (err LookupUserByIDError) Error() string

Error fulfills the error interface.

func (LookupUserByIDError) Unwrap added in v0.4.6

func (err LookupUserByIDError) Unwrap() error

Unwrap returns the underlying cause of this error.

type LookupUserByNameError added in v0.4.6

type LookupUserByNameError struct {
	Name string
	Err  error
}

LookupUserByNameError represents failure to look up an OS user by name.

func (LookupUserByNameError) Error added in v0.4.6

func (err LookupUserByNameError) Error() string

Error fulfills the error interface.

func (LookupUserByNameError) Unwrap added in v0.4.6

func (err LookupUserByNameError) Unwrap() error

Unwrap returns the underlying cause of this error.

type MapKeyError added in v0.4.7

type MapKeyError struct {
	Map   string
	Key   interface{}
	Value interface{}
	Err   error
}

MapKeyError indicates an error in one value of a map.

func (MapKeyError) Error added in v0.4.7

func (err MapKeyError) Error() string

Error fulfills the error interface.

func (MapKeyError) Unwrap added in v0.4.7

func (err MapKeyError) Unwrap() error

Unwrap returns the underlying cause of this error.

type PathAbsError added in v0.4.6

type PathAbsError struct {
	Path string
	Err  error
}

PathAbsError represents failure to make a file path absolute.

func (PathAbsError) Error added in v0.4.6

func (err PathAbsError) Error() string

Error fulfills the error interface.

func (PathAbsError) Unwrap added in v0.4.6

func (err PathAbsError) Unwrap() error

Unwrap returns the underlying cause of this error.

type PathError added in v0.4.6

type PathError struct {
	Path string
	Err  error
}

PathError represents failure to parse a path of some sort, such as a URL path or a ZooKeeper path.

func (PathError) Error added in v0.4.6

func (err PathError) Error() string

Error fulfills the error interface.

func (PathError) Unwrap added in v0.4.6

func (err PathError) Unwrap() error

Unwrap returns the underlying cause of this error.

type PortError added in v0.4.6

type PortError struct {
	Type PortType
	Port string
	Err  error
}

PortError represents failure to parse a port number string.

func (PortError) Error added in v0.4.6

func (err PortError) Error() string

Error fulfills the error interface.

func (PortError) Unwrap added in v0.4.6

func (err PortError) Unwrap() error

Unwrap returns the underlying cause of this error.

type PortType added in v0.4.7

type PortType uint8

PortType denotes whether a port is named, numbered, or either.

const (
	NumericPort PortType = iota
	NumericPortOrServiceName
	NamedPort
)

PortType constants.

type QueryParamError added in v0.4.6

type QueryParamError struct {
	Name  string
	Value string
	Err   error
}

QueryParamError represents failure to parse the value of a specific URL query parameter or a specific Target query parameter.

func (QueryParamError) Error added in v0.4.6

func (err QueryParamError) Error() string

Error fulfills the error interface.

func (QueryParamError) Unwrap added in v0.4.6

func (err QueryParamError) Unwrap() error

Unwrap returns the underlying cause of this error.

type QueryStringError added in v0.4.6

type QueryStringError struct {
	QueryString string
	Err         error
}

QueryStringError represents failure to parse a URL query string or a Target query string.

func (QueryStringError) Error added in v0.4.6

func (err QueryStringError) Error() string

Error fulfills the error interface.

func (QueryStringError) Unwrap added in v0.4.6

func (err QueryStringError) Unwrap() error

Unwrap returns the underlying cause of this error.

type RegexpMatchError added in v0.4.6

type RegexpMatchError struct {
	Input   string
	Pattern *regexp.Regexp
}

RegexpMatchError represents failure to match a regular expression.

func (RegexpMatchError) Error added in v0.4.6

func (err RegexpMatchError) Error() string

Error fulfills the error interface.

func (RegexpMatchError) GRPCStatusCode added in v0.4.6

func (err RegexpMatchError) GRPCStatusCode() codes.Code

GRPCStatusCode returns the GRPC status code "InvalidArgument".

type SchemeError added in v0.4.6

type SchemeError struct {
	Scheme string
	Err    error
}

SchemeError represents failure to identify a URL scheme or a Target scheme.

func (SchemeError) Error added in v0.4.6

func (err SchemeError) Error() string

Error fulfills the error interface.

func (SchemeError) Unwrap added in v0.4.6

func (err SchemeError) Unwrap() error

Unwrap returns the underlying cause of this error.

type StructFieldError added in v0.4.7

type StructFieldError struct {
	Field string
	Value interface{}
	Err   error
}

StructFieldError indicates an error in one field of a struct.

func (StructFieldError) Error added in v0.4.7

func (err StructFieldError) Error() string

Error fulfills the error interface.

func (StructFieldError) Unwrap added in v0.4.7

func (err StructFieldError) Unwrap() error

Unwrap returns the underlying cause of this error.

Jump to

Keyboard shortcuts

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