gremconnect

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package gremconnect has the connection related structs and functions.

Functions in this package relate to authentication and connection to the graph database of choice.

This package also includes the available dialers to use for the Grammes client such as the websocket dialer.

Index

Constants

This section is empty.

Variables

View Source
var (
	// GenUUID is a monkey patched function for the Google UUIDv4 generator.
	GenUUID = uuid.NewUUID
)

Functions

func PackageRequest

func PackageRequest(req Request, versionNumber string) (msg []byte, err error)

PackageRequest takes a request type and formats it into being able to be delivered to the TinkerPop server.

Types

type Auth

type Auth struct {
	Username string
	Password string
}

Auth contains the authentication data for the dialer.

type AuthInfo

type AuthInfo struct {
	ChallengeID string
	User        string
	Pass        string
}

AuthInfo holds all the information needed to use SASL authentication with the Gremlin server. ChallengeID is the requestID in the 407 status (AUTHENTICATE) response

type Dialer

type Dialer interface {
	// Actions
	Connect() error
	Close() error
	Write(msg []byte) error
	Read() (msg []byte, err error)
	Ping(errs chan error)

	// Checkers
	IsConnected() bool
	IsDisposed() bool

	// Getters
	Auth() (*Auth, error)
	Address() string
	GetQuit() chan struct{}

	// Configuration Setters
	SetAuth(username string, password string)
	SetTimeout(interval time.Duration)
	SetPingInterval(interval time.Duration)
	SetWritingWait(interval time.Duration)
	SetReadingWait(interval time.Duration)
}

Dialer will be used to dial in a connection between the client and gremlin server without directly using a websocket. This leaves room for mocking and altered methods of connecting to the server.

func NewWebSocketDialer

func NewWebSocketDialer(address string) Dialer

NewWebSocketDialer returns a new WebSocket dialer to use when establishing a connection to the Gremlin server. This function also assigns default values to the websocket if they're not assigned by DialerConfig functions.

type OptAuth

type OptAuth func(*AuthInfo) error

OptAuth holds data about the authentication

func OptAuthEnv

func OptAuthEnv() OptAuth

OptAuthEnv sets authentication info from environment variables GREMLIN_USER and GREMLIN_PASS

func OptAuthUserPass

func OptAuthUserPass(user, pass string) OptAuth

OptAuthUserPass sets authentication information from username and password

type Request

type Request struct {
	RequestID string                 `json:"requestId"`
	Op        string                 `json:"op"`
	Processor string                 `json:"processor"`
	Args      map[string]interface{} `json:"args"`
}

Request is a container for all evaluation request parameters to be sent to the Gremlin Server.

func PrepareAuthRequest

func PrepareAuthRequest(requestID string, username string, password string) (req Request, err error)

PrepareAuthRequest creates a request for the dialer to send to the Gremlin-Server.

func PrepareRequest

func PrepareRequest(query string, bindings, rebindings map[string]string) (req Request, id string, err error)

PrepareRequest packages a query and binding into the format that Gremlin Server accepts

type Response

type Response struct {
	Data      interface{}
	RequestID string
	Code      int
}

Response is the structure representation of the response json received from the Gremlin-Server.

func MarshalResponse

func MarshalResponse(msg []byte) (Response, error)

MarshalResponse creates a Response struct for every incoming Response for further manipulation

type WebSocket

type WebSocket struct {
	Quit chan struct{}

	sync.RWMutex
	// contains filtered or unexported fields
}

WebSocket will hold all of the data used to dial to the gremlin server and sustain a stable connection by pinging it regularly.

func (*WebSocket) Address

func (ws *WebSocket) Address() string

Address returns the host address used to establish a connection to.

func (*WebSocket) Auth

func (ws *WebSocket) Auth() (*Auth, error)

Auth returns the websocket's authentication information if it's on a secure connection.

func (*WebSocket) Close

func (ws *WebSocket) Close() error

Close disposes the websocket and closes the quit channel to signal the websocket's ping selection.

func (*WebSocket) Connect

func (ws *WebSocket) Connect() error

Connect will setup the gorilla websocket and other configurations to establish a connection to the given address.

func (*WebSocket) GetQuit

func (ws *WebSocket) GetQuit() chan struct{}

GetQuit returns the quit channel so the websocket can communicate to the client that the connection has quit.

func (*WebSocket) IsConnected

func (ws *WebSocket) IsConnected() bool

IsConnected returns whether the given websocket has an established connection.

func (*WebSocket) IsDisposed

func (ws *WebSocket) IsDisposed() bool

IsDisposed returns whether the given websocket has been disposed of its use.

func (*WebSocket) Ping

func (ws *WebSocket) Ping(errs chan error)

Ping runs a routine ping check to the established connection and sends error channel a signal if there's a detected error if not/how the server responds.

func (*WebSocket) Read

func (ws *WebSocket) Read() (msg []byte, err error)

Read uses the gorilla function to read a response from the established connection.

func (*WebSocket) SetAuth

func (ws *WebSocket) SetAuth(user, pass string)

SetAuth will set the authentication to this user and pass

func (*WebSocket) SetPingInterval

func (ws *WebSocket) SetPingInterval(interval time.Duration)

SetPingInterval sets how often the websocket will ping the server.

func (*WebSocket) SetReadingWait

func (ws *WebSocket) SetReadingWait(interval time.Duration)

SetReadingWait sets how long the reading will wait

func (*WebSocket) SetTimeout

func (ws *WebSocket) SetTimeout(interval time.Duration)

SetTimeout will set the dialing timeout

func (*WebSocket) SetWritingWait

func (ws *WebSocket) SetWritingWait(interval time.Duration)

SetWritingWait sets how long the wait is for waiting

func (*WebSocket) Write

func (ws *WebSocket) Write(msg []byte) error

Write uses the gorilla function to write a Binary message to the established connection.

Jump to

Keyboard shortcuts

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