consul

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Example (ConsulDatasource_CustomizeClient)
client, err := api.NewClient(&api.Config{
	Address: "127.0.0.1:8500",
})
if err != nil {
	fmt.Println("Failed to instance consul client")
	os.Exit(1)
}
ds, err := NewDatasource("property_key",
	// customize consul client
	WithConsulClient(client),
	// preset property handlers
	WithPropertyHandlers(),
	// reset queryOptions, defaultQueryOptions as default
	WithQueryOptions(&api.QueryOptions{}),
)

if err != nil {
	fmt.Println("Failed to instance consul datasource")
	os.Exit(1)
}

if err := ds.Initialize(); err != nil {
	fmt.Println("Failed to initialize consul datasource")
	os.Exit(1)
}
Output:

Example (ConsulDatasource_CustomizeConfig)
ds, err := NewDatasource("property_key",
	// customize consul config
	WithConsulConfig(&api.Config{
		Address: "127.0.0.1:8500",
	}),
	// preset property handlers
	WithPropertyHandlers(),
	// reset queryOptions, defaultQueryOptions as default
	WithQueryOptions(&api.QueryOptions{
		WaitIndex: 0,
		// override default WaitTime(5min)
		WaitTime: time.Second * 90,
	}),
)

if err != nil {
	fmt.Println("Failed to instance consul datasource")
	os.Exit(1)
}

if err := ds.Initialize(); err != nil {
	fmt.Println("Failed to initialize consul datasource")
	os.Exit(1)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNilConsulClient     = errors.New("nil consul client")
	ErrInvalidConsulConfig = errors.New("invalid consul config")
	ErrKeyDoesNotExist     = errors.New("key does not exist")
)

Functions

func NewDatasource

func NewDatasource(propertyKey string, opts ...Option) (datasource.DataSource, error)

Types

type KVQuerier

type KVQuerier interface {
	Get(key string, q *api.QueryOptions) (*api.KVPair, *api.QueryMeta, error)
	List(prefix string, q *api.QueryOptions) (api.KVPairs, *api.QueryMeta, error)
}

type Option

type Option func(*options)

func WithConsulClient

func WithConsulClient(client *api.Client) Option

WithConsulClient injects consul client instance

func WithConsulConfig

func WithConsulConfig(config *api.Config) Option

WithConsulConfig injects consul client config

func WithPropertyHandlers

func WithPropertyHandlers(handlers ...datasource.PropertyHandler) Option

WithPropertyHandlers injects property handlers

func WithQueryOptions

func WithQueryOptions(queryOptions *api.QueryOptions) Option

WithQueryOptions sets options for consulClient.Get method

Jump to

Keyboard shortcuts

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