connection

package
v3.0.0-...-a491609 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PlainText              = "text/plain"
	ApplicationOctetStream = "application/octet-stream"
	ApplicationZip         = "application/zip"

	ApplicationJSON = "application/json"
)
View Source
const (
	ArangoHeaderAsyncIDKey = "x-arango-async-id"
	ArangoHeaderAsyncKey   = "x-arango-async"
	ArangoHeaderAsyncValue = "store"
)
View Source
const (
	ContentType = "content-type"
)

Variables

View Source
var ErrReaderOutputBytes = errors.New("use *[]byte as output argument")

ErrReaderOutputBytes is the error to inform caller about invalid output argument.

View Source
var ErrWriterInputBytes = errors.New("use []byte as input argument")

ErrWriterInputBytes is the error to inform caller about invalid input argument.

Functions

func DefaultHTTP2TransportSettings

func DefaultHTTP2TransportSettings(in *http2.Transport)

func DefaultHTTPTransportSettings

func DefaultHTTPTransportSettings(in *http.Transport)

func FixupEndpointURLScheme

func FixupEndpointURLScheme(u string) string

FixupEndpointURLScheme changes endpoint URL schemes used by arangod to ones used by go. E.g. "tcp://localhost:8529" -> "http://localhost:8529"

func HasAsyncID

func HasAsyncID(ctx context.Context) (string, bool)

HasAsyncID returns the async Job ID from the given context.

func IsAsyncJobInProgress

func IsAsyncJobInProgress(err error) (string, bool)

func IsAsyncRequest

func IsAsyncRequest(ctx context.Context) bool

IsAsyncRequest returns true if the given context is an async request.

func IsCleartextEndpoint

func IsCleartextEndpoint(e Endpoint) bool

IsCleartextEndpoint reports whether ALL URLs in e use the http:// scheme. Mixed-scheme endpoint lists (some http://, some https://) are not supported; use ValidateEndpointSchemes to detect this condition before constructing a connection. Endpoints using ArangoDB-native schemes (e.g. tcp://) must be normalized with FixupEndpointURLScheme before being passed here.

func IsCodeError

func IsCodeError(err error, code int) bool

func IsNotFoundError

func IsNotFoundError(err error) bool

func New

func New[T any](mods ...Mod[T]) T

func NewError

func NewError(code int, message string) error

func NewErrorAsyncJobInProgress

func NewErrorAsyncJobInProgress(jobID string) error

func NewErrorf

func NewErrorf(code int, message string, args ...interface{}) error

func NewHTTP2DialForEndpoint

func NewHTTP2DialForEndpoint(e Endpoint) func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error)

func NewNotFoundError

func NewNotFoundError(msg string) error

func NewUrl

func NewUrl(parts ...string) string

NewUrl returns the path in the URL.

func RequestDBNameValueExtractor

func RequestDBNameValueExtractor(requestMethod, requestPath string) (string, error)

RequestDBNameValueExtractor might be used as RequestHashValueExtractor to use DB name from URL for hashing It fallbacks to requestMethod+requestPath concatenation in case if path does not contain DB name

func ValidateEndpointSchemes

func ValidateEndpointSchemes(e Endpoint) error

ValidateEndpointSchemes returns an error if any URL in the endpoint list uses an unsupported scheme or if the list mixes http:// and https:// URLs. Only "http" and "https" are accepted; ArangoDB-native schemes (tcp://, ssl://) must be normalized with FixupEndpointURLScheme before endpoints are constructed.

func WithAsync

func WithAsync(parent context.Context) context.Context

WithAsync is used to configure a context to make an async operation - requires Connection with Async wrapper!

func WithAsyncID

func WithAsyncID(parent context.Context, asyncID string) context.Context

WithAsyncID is used to check an async operation result - requires Connection with Async wrapper!

func WithHTTP2Cleartext

func WithHTTP2Cleartext(in *http2.Transport)

WithHTTP2Cleartext configures h2c (HTTP/2 cleartext) transport for plain-HTTP endpoints. Use this modifier when connecting to http:// endpoints. ArangoDB-native tcp:// endpoints must be normalized with FixupEndpointURLScheme before use.

func WithHTTP2InsecureSkipVerify

func WithHTTP2InsecureSkipVerify(in *http2.Transport)

WithHTTP2InsecureSkipVerify configures TLS certificate verification to be skipped for HTTPS endpoints (e.g. self-signed certificates). For cleartext endpoints use WithHTTP2Cleartext.

func WithHTTPInsecureSkipVerify

func WithHTTPInsecureSkipVerify(in *http.Transport)

Types

type ArangoDBConfiguration

type ArangoDBConfiguration struct {
	// ArangoQueueTimeoutEnabled is used to enable Queue timeout on the server side.
	// If ArangoQueueTimeoutEnabled is used, then its value takes precedence.
	// In another case value of context.Deadline will be taken
	ArangoQueueTimeoutEnabled bool

	// ArangoQueueTimeout defines max queue timeout on the server side
	ArangoQueueTimeoutSec uint

	// DriverFlags configure additional flags for the `x-arango-driver` header
	DriverFlags []string

	// Compression is used to enable compression between client and server
	Compression *CompressionConfig
}

type Array

type Array struct {
	// contains filtered or unexported fields
}

func (*Array) More

func (a *Array) More() bool

func (*Array) Unmarshal

func (a *Array) Unmarshal(i interface{}) error

func (*Array) UnmarshalJSON

func (a *Array) UnmarshalJSON(d []byte) error

type AsyncConnectionWrapper

type AsyncConnectionWrapper struct {
	Connection
}

func (*AsyncConnectionWrapper) Do

func (a *AsyncConnectionWrapper) Do(ctx context.Context, request Request, output interface{}, allowedStatusCodes ...int) (Response, error)

type Authentication

type Authentication interface {
	RequestModifier(r Request) error
}

func NewBasicAuth

func NewBasicAuth(username, password string) Authentication

func NewHeaderAuth

func NewHeaderAuth(key, value string, args ...interface{}) Authentication

type AuthenticationGetter

type AuthenticationGetter func(ctx context.Context, conn Connection) (Authentication, error)

type Compression

type Compression interface {
	ApplyRequestHeaders(r Request)
	ApplyRequestCompression(r *httpRequest, rootWriter io.Writer) (io.WriteCloser, error)
}

type CompressionConfig

type CompressionConfig struct {
	// CompressionConfig is used to enable compression for the requests
	CompressionType CompressionType

	// ResponseCompressionEnabled is used to enable compression for the responses (requires server side adjustments)
	ResponseCompressionEnabled bool

	// RequestCompressionEnabled is used to enable compression for the requests
	RequestCompressionEnabled bool

	// RequestCompressionLevel - Sets the compression level between -1 and 9
	// Default: 0 (NoCompression). For Reference see: https://pkg.go.dev/compress/flate#pkg-constants
	RequestCompressionLevel int
}

CompressionConfig is used to enable compression for the connection

type CompressionType

type CompressionType string
const (

	// RequestCompressionTypeGzip is used to enable gzip compression
	RequestCompressionTypeGzip CompressionType = "gzip"

	// RequestCompressionTypeDeflate is used to enable deflate compression
	RequestCompressionTypeDeflate CompressionType = "deflate"
)

type Connection

type Connection interface {
	// NewRequest initializes Request object
	NewRequest(method string, urls ...string) (Request, error)

	// NewRequestWithEndpoint initializes a Request object with a specific endpoint
	NewRequestWithEndpoint(endpoint string, method string, urls ...string) (Request, error)

	// Do execute the given Request and parses the response into output
	// If allowed status codes are provided, they will be checked before decoding the response body.
	// In case of mismatch shared.ArangoError will be returned
	Do(ctx context.Context, request Request, output interface{}, allowedStatusCodes ...int) (Response, error)

	// Stream executes the given Request and returns a reader for Response body
	Stream(ctx context.Context, request Request) (Response, io.ReadCloser, error)

	// GetEndpoint returns Endpoint which is currently used to execute requests
	GetEndpoint() Endpoint

	// SetEndpoint changes Endpoint which is used to execute requests
	SetEndpoint(e Endpoint) error

	// GetAuthentication returns Authentication
	GetAuthentication() Authentication

	// SetAuthentication returns Authentication parameters used to execute requests
	SetAuthentication(a Authentication) error

	// Decoder returns Decoder to use for Response body decoding
	Decoder(contentType string) Decoder

	// GetConfiguration returns the configuration for the connection to database
	GetConfiguration() ArangoDBConfiguration

	// SetConfiguration sets the configuration for the connection to database
	SetConfiguration(config ArangoDBConfiguration)
}

func NewConnectionAsyncWrapper

func NewConnectionAsyncWrapper(conn Connection) Connection

func NewHttp2Connection

func NewHttp2Connection(config Http2Configuration) Connection

NewHttp2Connection Warning: Ensure that VST is not enabled to avoid performance issues

func NewHttpConnection

func NewHttpConnection(config HttpConfiguration) Connection

func NewPool

func NewPool(connections int, factory Factory) (Connection, error)

func NewRetryWrapper

func NewRetryWrapper(conn Connection, retries int, wrapper RetryWrapper) Connection

func RetryOn503

func RetryOn503(conn Connection, retries int) Connection

type ContextKey

type ContextKey string

type Decoder

type Decoder interface {
	Decode(reader io.Reader, obj interface{}) error
	Encode(writer io.Writer, obj interface{}) error
	Reencode(in, out interface{}) error
}

type EncodingCodec

type EncodingCodec interface {
}

type Endpoint

type Endpoint interface {
	// Get returns provided endpoint if it is known, otherwise chooses one endpoint from existing list
	// Endpoint implementation might use the Request method and path values to determine which endpoint to return
	Get(endpoint, method, path string) (string, error)
	// List returns known endpoints
	List() []string
}

func NewMaglevHashEndpoints

func NewMaglevHashEndpoints(eps []string, extractor RequestHashValueExtractor) (Endpoint, error)

NewMaglevHashEndpoints returns Endpoint manager which consistently returns the same endpoint based on value extracted from request using provided RequestHashValueExtractor e.g. if you want to use DB name from URL for hashing you can use RequestDBNameValueExtractor

func NewRoundRobinEndpoints

func NewRoundRobinEndpoints(e []string) Endpoint

NewRoundRobinEndpoints returns Endpoint manager which runs round-robin

type Error

type Error struct {
	Code    int
	Message string
}

func (Error) Error

func (e Error) Error() string

type ErrorAsyncJobInProgress

type ErrorAsyncJobInProgress struct {
	// contains filtered or unexported fields
}

func (ErrorAsyncJobInProgress) Error

func (a ErrorAsyncJobInProgress) Error() string

type Factory

type Factory func() (Connection, error)

type Http2Configuration

type Http2Configuration struct {
	Authentication Authentication
	Endpoint       Endpoint

	ContentType string

	ArangoDBConfig ArangoDBConfiguration

	Transport *http2.Transport
}

func DefaultHTTP2ConfigurationWrapper

func DefaultHTTP2ConfigurationWrapper(endpoint Endpoint, insecureSkipVerify bool) Http2Configuration

func (Http2Configuration) GetContentType

func (h Http2Configuration) GetContentType() string

type HttpConfiguration

type HttpConfiguration struct {
	Authentication Authentication
	Endpoint       Endpoint

	ContentType string

	ArangoDBConfig ArangoDBConfiguration

	Transport http.RoundTripper

	// DontFollowRedirect; if set, redirect will not be followed, response from the initial request will be returned without an error
	// DontFollowRedirect takes precendance over FailOnRedirect.
	DontFollowRedirect bool
}

func DefaultHTTPConfigurationWrapper

func DefaultHTTPConfigurationWrapper(endpoint Endpoint, insecureSkipVerify bool) HttpConfiguration

func (HttpConfiguration) GetContentType

func (h HttpConfiguration) GetContentType() string

type Mod

type Mod[T any] func(in *T)

func WithHTT2PEndpoint

func WithHTT2PEndpoint(endpoint Endpoint) Mod[Http2Configuration]

func WithHTTP2Transport

func WithHTTP2Transport(mods ...Mod[http2.Transport]) Mod[Http2Configuration]

func WithHTTPEndpoint

func WithHTTPEndpoint(endpoint Endpoint) Mod[HttpConfiguration]

func WithHTTPTransport

func WithHTTPTransport(mods ...Mod[http.Transport]) Mod[HttpConfiguration]

type RawObject

type RawObject []byte

RawObject is a raw encoded object. Connection implementations must be able to unmarshal *RawObject into Go objects.

type Request

type Request interface {
	Method() string
	URL() string

	Endpoint() string

	SetBody(i interface{}) error
	AddHeader(key, value string)
	AddQuery(key, value string)

	GetHeader(key string) (string, bool)
	GetQuery(key string) (string, bool)

	SetFragment(s string)
}

type RequestHashValueExtractor

type RequestHashValueExtractor func(requestMethod, requestPath string) (string, error)

RequestHashValueExtractor accepts request method and full request path and must return a value which will be used for hash calculation

type RequestModifier

type RequestModifier func(r Request) error

func WithBody

func WithBody(i interface{}) RequestModifier

func WithFragment

func WithFragment(s string) RequestModifier

func WithQuery

func WithQuery(s, value string) RequestModifier

func WithTransactionID

func WithTransactionID(transactionID string) RequestModifier

type Response

type Response interface {
	// Code returns an HTTP compatible status code of the response.
	Code() int

	// Response returns underlying response object
	Response() interface{}

	// Endpoint returns the endpoint that handled the request.
	Endpoint() string

	// Content returns Content-Type
	Content() string

	// Header gets the first value associated with the given key.
	// If there are no values associated with the key, Get returns "".
	Header(name string) string

	RawResponse() *http.Response
}

func Call

func Call(ctx context.Context, c Connection, method, url string, output interface{}, modifiers ...RequestModifier) (Response, error)

func CallDelete

func CallDelete(ctx context.Context, c Connection, url string, output interface{}, modifiers ...RequestModifier) (Response, error)

func CallGet

func CallGet(ctx context.Context, c Connection, url string, output interface{}, modifiers ...RequestModifier) (Response, error)

func CallHead

func CallHead(ctx context.Context, c Connection, url string, output interface{}, modifiers ...RequestModifier) (Response, error)

func CallPatch

func CallPatch(ctx context.Context, c Connection, url string, output interface{}, body interface{}, modifiers ...RequestModifier) (Response, error)

func CallPost

func CallPost(ctx context.Context, c Connection, url string, output interface{}, body interface{}, modifiers ...RequestModifier) (Response, error)

func CallPut

func CallPut(ctx context.Context, c Connection, url string, output interface{}, body interface{}, modifiers ...RequestModifier) (Response, error)

func CallStream

func CallStream(ctx context.Context, c Connection, method, url string, modifiers ...RequestModifier) (Response, io.ReadCloser, error)

CallStream performs HTTP request with the given method and URL. It returns the response and body reader to read the data from there. The caller is responsible to free the response body.

func CallWithChecks

func CallWithChecks(ctx context.Context, c Connection, method, url string, output interface{}, allowedStatusCodes []int, modifiers ...RequestModifier) (Response, error)

type RetryWrapper

type RetryWrapper func(response Response, err error) bool

type Wrapper

type Wrapper func(c Connection) Connection

func NewJWTAuthWrapper

func NewJWTAuthWrapper(username, password string) Wrapper

func NewSSOAuthWrapper

func NewSSOAuthWrapper(initialToken string) Wrapper

func WrapAuthentication

func WrapAuthentication(getter AuthenticationGetter) Wrapper

Jump to

Keyboard shortcuts

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