consulkv

package
v0.0.0-...-f179113 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package consulkv contains implementation of remotekv.Interface for Consul key-value storage.

Index

Constants

View Source
const (
	// MaxTTL is the maximum TTL that can be set for a session.
	MaxTTL = 1 * timeutil.Day

	// MinTTL is the minimum TTL that can be set for a session.
	MinTTL = 10 * time.Second
)

Consul-related constants.

See https://developer.hashicorp.com/consul/api-docs/session#ttl.

View Source
const ErrRateLimited errors.Error = "rate limited"

ErrRateLimited is returned by KV.Get when the request is rate limited.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// URL to the Consul key-value storage.
	URL *url.URL

	// SessionURL is the URL to the Consul session API.
	SessionURL *url.URL

	// Client is the HTTP client for requests to the Consul key-value storage.
	Client *agdhttp.Client

	// Limiter rate limits requests to the Consul key-value storage.
	Limiter *rate.Limiter

	// TTL defines for how long information about a single client is kept.  It
	// must be between [MinTTL] and [MaxTTL].
	TTL time.Duration

	// MaxRespSize is the maximum size of response from Consul key-value
	// storage.
	MaxRespSize datasize.ByteSize
}

Config is the configuration structure for Consul key-value storage. All fields must be non-empty.

type KV

type KV struct {
	// contains filtered or unexported fields
}

KV is the Consul remote KV implementation.

func NewKV

func NewKV(conf *Config) (kv *KV, err error)

NewKV returns a new Consul key-value storage.

func (*KV) Get

func (kv *KV) Get(ctx context.Context, key string) (val []byte, ok bool, err error)

Get implements the remotekv.Interface interface for *KV. Any error returned will have the underlying type of [httpError].

func (*KV) Set

func (kv *KV) Set(ctx context.Context, key string, val []byte) (err error)

Set implements the remotekv.Interface interface for *KV. Any error returned will have the underlying type of [httpError].

type KeyReadResponse

type KeyReadResponse struct {
	Value []byte `json:"Value"`
}

KeyReadResponse is the item of the array that Consul returns as a response to a GET request to its KV database.

See https://developer.hashicorp.com/consul/api-docs/kv#read-key.

Jump to

Keyboard shortcuts

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