consul

package module
v0.0.0-...-b8d94d1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

This package provides Consul dynamic data-source implementation for Sentinel.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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