util

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: Apache-2.0 Imports: 11 Imported by: 5

Documentation

Overview

Package util provides network related utility functions.

Index

Constants

This section is empty.

Variables

View Source
var TemporaryErrorMessages = []string{

	"bad record MAC",

	"broken pipe",

	"connection refused",

	"connection reset",

	"connection timed out",

	"http2: client connection force closed via ClientConn.Close",

	"http2: timeout awaiting response headers",

	"http: ContentLength=",

	"i/o timeout",

	"net/http: TLS handshake timeout",

	"net/http: timeout awaiting response headers",

	"server closed idle connection",

	"stream error:",

	"transport connection broken",

	"unexpected EOF reading trailer",

	"use of closed network connection",
}

TemporaryErrorMessages is a slice of known error messages which may be returned by the Go standard library when attempting to perform network operations.

View Source
var TemporaryFailureStatusCodes = map[int]struct{}{

	http.StatusBadGateway: {},

	http.StatusGatewayTimeout: {},

	http.StatusInternalServerError: {},

	http.StatusServiceUnavailable: {},

	http.StatusTooManyRequests: {},

	509: {},
}

TemporaryFailureStatusCodes is a slice of temporary status codes which should be retried by default.

Functions

func HostsToConnectionString

func HostsToConnectionString(hosts []string) string

HostsToConnectionString creates a connection string using the provided hosts. The returned connection string can be used when creating a new REST client or when connecting to a cluster via gocbcore.

func IsMethodIdempotent

func IsMethodIdempotent(method string) bool

IsMethodIdempotent returns a boolean indicating whether the given method is idempotent.

func IsTemporaryError

func IsTemporaryError(err error) bool

IsTemporaryError returns a boolean indicating whether the provided error is a result of a temporary failure and should be retried.

func IsTemporaryFailure

func IsTemporaryFailure(status int) bool

IsTemporaryFailure returns a boolean indicating whether the provided status code represents a temporary error and should be retried.

func NewHTTPTransport

func NewHTTPTransport(tlsConfig *tls.Config, timeouts HTTPTimeouts) *http.Transport

NewHTTPTransport returns a new HTTP transport using the given TLS config and timeouts.

func ReconstructIPV6

func ReconstructIPV6(host string) string

ReconstructIPV6 returns a new string where a valid unwrapped IPv6 address is wrapped with '[' and ']'.

func ReplaceLocalhost added in v1.0.8

func ReplaceLocalhost(host, replacement string) (string, error)

ReplaceLocalhost uses 'replacement' if the URL 'host' uses localhost as its hostname, retaining host's scheme, port, path and query.

NOTE: If 'replacement' is an IPv6 address it is correctly wrapped in square brackets.

func ToCouchbaseSchema

func ToCouchbaseSchema(host string) string

ToCouchbaseSchema converts the schema prefix for the given host from http/https to couchbase/couchbases.

func TrimSchema

func TrimSchema(host string) string

TrimSchema trims known schema prefixes from the given host.

Types

type HTTPTimeouts

type HTTPTimeouts struct {
	Dialer                  *time.Duration
	KeepAlive               *time.Duration
	TransportIdleConn       *time.Duration
	TransportContinue       *time.Duration
	TransportResponseHeader *time.Duration
	TransportTLSHandshake   *time.Duration
}

HTTPTimeouts encapsulates the timeouts for a HTTP client into an object which can be parsed as an environment variable.

func (*HTTPTimeouts) UnmarshalJSON

func (ct *HTTPTimeouts) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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