Documentation
¶
Overview ¶
Package util provides network related utility functions.
Index ¶
- Variables
- func HostsToConnectionString(hosts []string) string
- func IsMethodIdempotent(method string) bool
- func IsTemporaryError(err error) bool
- func IsTemporaryFailure(status int) bool
- func NewHTTPTransport(tlsConfig *tls.Config, timeouts HTTPTimeouts) *http.Transport
- func ReconstructIPV6(host string) string
- func ToCouchbaseSchema(host string) string
- func TrimSchema(host string) string
- type HTTPTimeouts
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
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 ¶
IsMethodIdempotent returns a boolean indicating whether the given method is idempotent.
func IsTemporaryError ¶
IsTemporaryError returns a boolean indicating whether the provided error is a result of a temporary failure and should be retried.
func IsTemporaryFailure ¶
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 ¶
ReconstructIPV6 returns a new string where a valid unwrapped IPv6 address is wrapped with '[' and ']'.
func ToCouchbaseSchema ¶
ToCouchbaseSchema converts the schema prefix for the given host from http/https to couchbase/couchbases.
func TrimSchema ¶
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