ranvier

package module
v0.0.0-...-841437a Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

README

Ranvier Go client

This package houses all of the code necessary for communicating with the Ranvier server.

Installation

go get github.com/eddieowens/ranvier/client

Usage

package main

import (
  "fmt"
  "github.com/eddieowens/ranvier/client"
  "os"
)

func main() {
  c, err := client.NewClient(&client.ClientOptions{
    Hostname:        "localhost:8080",
    ConfigDirectory: os.TempDir(),
  })
  
  if err != nil {
  	panic(err)
  }
  
  // Listens to the Ranvier server for changes to the 'users' config file. If someone were to make an update to this 
  // config file, the client will receive a message, and update its internal cache for the next query. 
  _, err = c.Connect(&client.ConnOptions{
  	Names: []string{"users"},
  })
  
  if err != nil {
  	panic(err)
  }
  
  // Query Ranvier using a jsonpath query to retrieve the config.
  conf, err := c.Query(&client.QueryOptions{
  	Name: "users",
  	Query: "$.db",
  })
  
  if err != nil {
  	panic(err)
  }
  
  // Prints 'users'
  fmt.Println(conf.Name)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Establish a websocket connection between the client and the Ranvier server. Whenever the Ranvier server detects
	// changes to the configuration you care about (specified in the options), it will notify your client and update its
	// state. If the connection could not be made, an error is returned.
	Connect(options *ConnOptions) (*Connection, error)

	// Sever the connection between the client and the Ranvier server. The client will no longer receive updates from the
	// Ranvier server after the connection is disconnected.
	Disconnect(conn *Connection)

	// Query Ranvier for some config. The query is a valid jsonpath query (https://restfulapi.net/json-jsonpath/). If the
	// query is unable to find any config, nil is returned. If the query is invalid, an error is returned.
	//
	// All queries are cached within the client and will be hit unless specified in the options. The order of operations
	// for retrieving a query are
	//   client cache -> Ranvier server -> local disk
	// If the query is unsuccessful in all of these operations, nil is returned.
	//
	// All successful queries will be written to disk.
	Query(options *QueryOptions) (*model.Config, error)
}

func NewClient

func NewClient(options *ClientOptions) (Client, error)

Create a new Ranvier client with the provided options. It is advised to only use a single client as all queries made by the client are cached.

type ClientOptions

type ClientOptions struct {
	// The required hostname to your Ranvier server(s). Should not include the protocol, e.g. if Ranvier is pointed at the
	// url https://ranvier.mycompany.com, this hostname should strictly be ranvier.mycompany.com. Or if it's
	// https://ranvier:8080, this field should be set to ranvier:8080.
	Hostname string

	// The directory that your local config files will be stored on disk. Config is stored on disk to prevent a strong
	// reliance on the server. This directory will default to a temp directory.
	ConfigDirectory string
}

type ConnOptions

type ConnOptions struct {
	// The names of the configuration files that you want updates for. Whenever the configuration tied to this name is
	// updated, the Connection will receive a message of the new configuration.
	Names []string

	// The amount of time to wait between connection retries if the websocket were to disconnect. Defaults to 30 seconds.
	RetryInterval time.Duration
}

type Connection

type Connection struct {
	// The channel for all incoming configuration changes. Listen for messages on this channel to get realtime updates on
	// configuration changes.
	OnUpdate chan model.ConfigEvent
	// contains filtered or unexported fields
}

type IntegrationSuite

type IntegrationSuite struct {
	suite.Suite
	Hostname string
	Port     string
	Host     string
	Resource *dockertest.Resource
	Pool     *dockertest.Pool
}

func (*IntegrationSuite) SetupSuite

func (i *IntegrationSuite) SetupSuite()

func (*IntegrationSuite) TearDownSuite

func (i *IntegrationSuite) TearDownSuite()

type QueryOptions

type QueryOptions struct {
	IgnoreCache bool
	Name        string
	Query       string
}

Jump to

Keyboard shortcuts

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