http

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 22 Imported by: 217

Documentation

Overview

Package http implements driver.Connection using an HTTP connection.

This connection uses HTTP or HTTPS to connect to the ArangoDB database and encodes its content as JSON or Velocypack, depending on the value of the `ContentType` fields in the `http.ConnectionConfig`.

Creating an Insecure Connection

To create an HTTP connection, use code like this.

// Create an HTTP connection to the database
conn, err := http.NewConnection(http.ConnectionConfig{
	Endpoints: []string{"http://localhost:8529"},
})
if err != nil {
	// Handle error
}

The resulting connection is used to create a client which you will use for normal database requests.

// Create a client
c, err := driver.NewClient(driver.ClientConfig{
	Connection: conn,
})
if err != nil {
	// Handle error
}

Creating a Secure Connection

To create a secure HTTPS connection, use code like this.

// Create an HTTPS connection to the database
conn, err := http.NewConnection(http.ConnectionConfig{
	Endpoints: []string{"https://localhost:8529"},
	TLSConfig: &tls.Config{
		InsecureSkipVerify: trueWhenUsingNonPublicCertificates,
	},
})
if err != nil {
	// Handle error
}

Index

Constants

View Source
const (
	DefaultMaxIdleConnsPerHost = 64
	DefaultConnLimit           = 32
)

Variables

View Source
var ErrAuthenticationNotChanged = errors.New("authentication not changed")

ErrAuthenticationNotChanged is returned when authentication is not changed.

Functions

func IsAuthenticationTheSame

func IsAuthenticationTheSame(auth1, auth2 driver.Authentication) bool

IsAuthenticationTheSame checks whether two authentications are the same.

func NewBinaryBodyBuilder

func NewBinaryBodyBuilder(contentType string) *binaryBody

func NewConnection

func NewConnection(config ConnectionConfig) (driver.Connection, error)

NewConnection creates a new HTTP connection based on the given configuration settings.

func NewConnectionDebugWrapper added in v1.3.0

func NewConnectionDebugWrapper(conn driver.Connection, ct driver.ContentType) driver.Connection

func NewJsonBodyBuilder

func NewJsonBodyBuilder() *jsonBody

func NewRepeatConnection

func NewRepeatConnection(conn driver.Connection, repeat RequestRepeater) driver.Connection

func NewVelocyPackBodyBuilder

func NewVelocyPackBodyBuilder() *velocyPackBody

Types

type ConnectionConfig

type ConnectionConfig struct {
	// Endpoints holds 1 or more URL's used to connect to the database.
	// In case of a connection to an ArangoDB cluster, you must provide the URL's of all coordinators.
	// If there is more than one endpoint, the client will pick the first one that works and use it till it fails.
	// Then it will try the next one
	Endpoints []string
	// TLSConfig holds settings used to configure a TLS (HTTPS) connection.
	// This is only used for endpoints using the HTTPS scheme.
	TLSConfig *tls.Config
	// Transport allows the use of a custom round tripper.
	// If Transport is not of type `*http.Transport`, the `TLSConfig` property is not used.
	// Otherwise a `TLSConfig` property other than `nil` will overwrite the `TLSClientConfig`
	// property of `Transport`.
	//
	// When using a custom `http.Transport`, make sure to set the `MaxIdleConnsPerHost` field at least as
	// high as the maximum number of concurrent requests you will make to your database.
	// A lower number will cause the golang runtime to create additional connections and close them
	// directly after use, resulting in a large number of connections in `TIME_WAIT` state.
	// When this value is not set, the driver will set it to 64 automatically.
	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
	// FailOnRedirect; if set, redirect will not be followed, instead the status code is returned as error
	FailOnRedirect bool
	// Cluster configuration settings
	cluster.ConnectionConfig
	// ContentType specified type of content encoding to use.
	ContentType driver.ContentType
	// ConnLimit is the upper limit to the number of connections to a single server.
	// The default is 32 (DefaultConnLimit).
	// Set this value to -1 if you do not want any upper limit.
	ConnLimit int
}

ConnectionConfig provides all configuration options for a HTTP connection.

type RepeatConnection

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

RepeatConnection is responsible for sending request until request repeater gives up.

func (*RepeatConnection) Do

Do performs a given request, returning its response. Repeats requests until repeat function gives up.

func (*RepeatConnection) Endpoints

func (h *RepeatConnection) Endpoints() []string

Endpoints returns the endpoints used by this connection.

func (*RepeatConnection) NewRequest

func (h *RepeatConnection) NewRequest(method, path string) (driver.Request, error)

NewRequest creates a new request with given method and path.

func (*RepeatConnection) Protocols

func (h *RepeatConnection) Protocols() driver.ProtocolSet

Protocols returns all protocols used by this connection.

func (*RepeatConnection) SetAuthentication

func (h *RepeatConnection) SetAuthentication(authentication driver.Authentication) (driver.Connection, error)

SetAuthentication configure the authentication used for this connection. Returns ErrAuthenticationNotChanged when the authentication is not changed.

func (*RepeatConnection) Unmarshal

func (h *RepeatConnection) Unmarshal(data driver.RawObject, result interface{}) error

Unmarshal unmarshals the given raw object into the given result interface.

func (*RepeatConnection) UpdateEndpoints

func (h *RepeatConnection) UpdateEndpoints(endpoints []string) error

UpdateEndpoints reconfigures the connection to use the given endpoints.

type RequestRepeater

type RequestRepeater interface {
	Repeat(conn driver.Connection, resp driver.Response, err error) bool
}

RequestRepeater creates possibility to send the request many times.

Jump to

Keyboard shortcuts

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