Documentation ¶
Index ¶
- Variables
- func Dial(conn interfaces.Dialer, errorChannel chan error, options ...clientOption) (*client, error)
- func IsNetworkErr(err error) bool
- func NewPool(createQueryExecutor QueryExecutorFactoryFunc, maxActiveConnections int, ...) (*pool, error)
- func NewWebsocket(host string, options ...optionWebsocket) (interfaces.Dialer, error)
- func PingInterval(interval time.Duration) clientOption
- func SetAuth(credentialProvider CredentialProvider) clientOption
- func SetBufferSize(readBufferSize int, writeBufferSize int) optionWebsocket
- func SetReadingWait(wait time.Duration) optionWebsocket
- func SetTimeout(timeout time.Duration) optionWebsocket
- func SetWritingWait(wait time.Duration) optionWebsocket
- func WithMetrics(metrics clientMetrics) clientOption
- type Cosmos
- type CredentialProvider
- type Error
- type ErrorCategory
- type Metrics
- type Option
- func AutomaticRetries(maxRetries int, timeout time.Duration) Option
- func ConnectionIdleTimeout(timeout time.Duration) Option
- func MetricsPrefix(prefix string) Option
- func NumMaxActiveConnections(numMaxActiveConnections int) Option
- func QueryTimeouts(readTimeout time.Duration, writeTimeout time.Duration) Option
- func WithAuth(username string, password string) Option
- func WithLogger(logger zerolog.Logger) Option
- func WithResourceTokenAuth(credentialProvider CredentialProvider) Option
- type QueryExecutorFactoryFunc
- type StaticCredentialProvider
Constants ¶
This section is empty.
Variables ¶
var ErrNoConnection = Error{Wrapped: fmt.Errorf("no connection"), Category: ErrorCategoryConnectivity}
var MimeType = []byte("application/vnd.gremlin-v2.0+json")
MimeType used for communication with the gremlin server.
Functions ¶
func Dial ¶
func Dial(conn interfaces.Dialer, errorChannel chan error, options ...clientOption) (*client, error)
Dial returns a client for interaction with the Gremlin Server specified in the host IP. The client is already connected.
func IsNetworkErr ¶ added in v0.1.15
IsNetworkErr determines whether the given error is related to any network issues (timeout, connectivity,..)
func NewPool ¶
func NewPool(createQueryExecutor QueryExecutorFactoryFunc, maxActiveConnections int, idleTimeout time.Duration, logger zerolog.Logger) (*pool, error)
NewPool creates a new pool which is a QueryExecutor
func NewWebsocket ¶
func NewWebsocket(host string, options ...optionWebsocket) (interfaces.Dialer, error)
NewWebsocket returns a WebSocket dialer to use when connecting to Gremlin Server
func PingInterval ¶
PingInterval sets the ping interval, which is the interval to send the ping frame to the peer
func SetAuth ¶
func SetAuth(credentialProvider CredentialProvider) clientOption
SetAuth sets credentials provider for an authenticated connection
func SetBufferSize ¶
SetBufferSize sets the read/write buffer size
func SetReadingWait ¶
SetReadingWait sets the time for waiting that reading occur
func SetTimeout ¶
SetTimeout sets the dial handshake timeout
func SetWritingWait ¶
SetWritingWait sets the time for waiting that writing occur
func WithMetrics ¶ added in v0.1.24
func WithMetrics(metrics clientMetrics) clientOption
WithMetrics sets the metrics provider
Types ¶
type Cosmos ¶
type Cosmos interface { // ExecuteQuery executes the given query and returns the according responses from the CosmosDB ExecuteQuery(query interfaces.QueryBuilder) ([]interfaces.Response, error) // Execute can be used to execute a raw query (string). This can be used to issue queries that are not yet supported by the QueryBuilder. Execute(query string) ([]interfaces.Response, error) // ExecuteAsync can be used to issue a query and streaming in the responses as they are available / are provided by the CosmosDB ExecuteAsync(query string, responseChannel chan interfaces.AsyncResponse) (err error) // ExecuteWithBindings can be used to execute a raw query (string) with optional bindings/rebindings. This can be used to issue queries that are not yet supported by the QueryBuilder. ExecuteWithBindings(path string, bindings, rebindings map[string]interface{}) (resp []interfaces.Response, err error) // IsConnected returns true in case the connection to the CosmosDB is up, false otherwise. IsConnected() bool // Stop stops the connector, terminates all background go routines and closes open connections. Stop() error // String returns a string representation of the cosmos connector String() string // IsHealthy returns nil in case the connection to the CosmosDB is up, the according error otherwise. IsHealthy() error }
Cosmos is an abstraction of the CosmosDB
type CredentialProvider ¶ added in v0.1.9
CredentialProvider provides access to cosmos credentials. In order to be able to provide dynamic credentials aka cosmos resource tokens you have to implement this interface and ensure in this implementation that always a valid resource token is returned by Password().
type Error ¶ added in v0.1.15
type Error struct { Wrapped error Category ErrorCategory }
type ErrorCategory ¶ added in v0.1.15
type ErrorCategory string
const ( ErrorCategoryGeneral ErrorCategory = "GeneralErr" ErrorCategoryConnectivity ErrorCategory = "ConnectivityErr" ErrorCategoryAuth ErrorCategory = "AuthErr" ErrorCategoryClient ErrorCategory = "ClientErr" ErrorCategoryServer ErrorCategory = "ServerErr" )
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics represents the collection of metrics internally set by the service.
func NewMetrics ¶
NewMetrics returns the metrics collection
type Option ¶
type Option func(*cosmosImpl)
Option is the struct for defining optional parameters for Cosmos
func AutomaticRetries ¶ added in v0.1.21
AutomaticRetries tries to retry failed requests, if appropriate. Retries are limited to maxRetries. Retrying is stopped after timeout is reached. Appropriate error codes are 409, 412, 429, 1007, 1008 see https://docs.microsoft.com/en-us/azure/cosmos-db/graph/gremlin-headers#status-codes Hint: Be careful when specifying the values for maxRetries and timeout. They influence how much latency is added on requests that need to be retried.
For example if maxRetries = 1 and timeout = 1s the call might take 1s longer to return a potential persistent error.
func ConnectionIdleTimeout ¶
ConnectionIdleTimeout specifies the timeout after which idle connections will be removed from the internal connection pool
func MetricsPrefix ¶
MetricsPrefix can be used to customize the metrics prefix as needed for a specific service. Per default 'gremcos' is used as prefix.
func NumMaxActiveConnections ¶
NumMaxActiveConnections specifies the maximum amount of active connections.
func QueryTimeouts ¶ added in v0.1.32
QueryTimeouts specifies the timeouts for executing a query. readTimeout specifies the amount of time a query can last until the response is completely fetched at the client. writeTimeout specifies the amount of time its allowed to take to send the query and all related data to the server.
func WithAuth ¶
WithAuth sets credentials for an authenticated connection using static credentials (primary-/ secondary cosmos key as password)
func WithLogger ¶
WithLogger specifies the logger to use
func WithResourceTokenAuth ¶ added in v0.1.9
func WithResourceTokenAuth(credentialProvider CredentialProvider) Option
WithResourceTokenAuth sets credential provider that is used to authenticate the requests to cosmos. With this approach dynamic credentials (cosmos resource tokens) can be used for authentication. To do this you have to provide a CredentialProvider implementation that takes care for providing a valid (not yet expired) resource token
myResourceTokenProvider := MyDynamicCredentialProvider{} New("wss://example.com", WithResourceTokenAuth(myResourceTokenProvider))
If you want to use static credentials (primary-/ secondary cosmos key as password) instead you can either use "WithAuth".
New("wss://example.com", WithAuth("username","primary-key"))
Or you use the default implementation for a static credential provider "StaticCredentialProvider"
staticCredProvider := StaticCredentialProvider{UsernameStatic: "username", PasswordStatic: "primary-key"} New("wss://example.com", WithResourceTokenAuth(staticCredProvider))
type QueryExecutorFactoryFunc ¶
type QueryExecutorFactoryFunc func() (interfaces.QueryExecutor, error)
type StaticCredentialProvider ¶ added in v0.1.9
StaticCredentialProvider is a default implementation of the CredentialProvider interface. It can be used in case you have no dynamic credentials but use the static primary-/ secondary cosmos key.
func (StaticCredentialProvider) Password ¶ added in v0.1.9
func (c StaticCredentialProvider) Password() (string, error)
func (StaticCredentialProvider) Username ¶ added in v0.1.9
func (c StaticCredentialProvider) Username() (string, error)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
test
|
|
mocks/cosmos
Package mock_gremcos is a generated GoMock package.
|
Package mock_gremcos is a generated GoMock package. |
mocks/interfaces
Package mock_interfaces is a generated GoMock package.
|
Package mock_interfaces is a generated GoMock package. |
mocks/metrics
Package mock_metrics is a generated GoMock package.
|
Package mock_metrics is a generated GoMock package. |