Documentation ¶
Index ¶
- Constants
- Variables
- func New(config *Config) plugin.Plugin
- type Config
- type Consul
- func (c *Consul) GetBestCandidateNode(ctx *context.Context) (string, error)
- func (c *Consul) GetNodes() ([]string, error)
- func (c *Consul) IsUpdated() bool
- func (c *Consul) OnBeforeDial(ctx *context.Context, h context.Handler)
- func (c *Consul) Plugin() plugin.Plugin
- func (c *Consul) SetServerURL(ctx *context.Context, host string)
- func (c *Consul) UpdateCache(nodes []string)
- func (c *Consul) UseBestCandidateNode(ctx *context.Context) error
- type Retrier
Constants ¶
const Version = "2.0.1"
Version defines the package semantic version
Variables ¶
var CacheTTL = 10 * time.Minute
CacheTTL stores the default Consul catalog refresh cycle TTL. Default to 10 minutes.
var DefaultConfig = api.DefaultConfig
DefaultConfig provides a custom
var DefaultRetrier = retry.ConstantBackoff
DefaultRetrier stores the default retry strategy used by the plugin. By default will use a constant retry strategy with a maximum of 3 retry attempts.
var Scheme = "http"
Scheme represents the URI scheme used by default.
Functions ¶
Types ¶
type Config ¶
type Config struct { // Retry enables/disables HTTP request retry policy. Defaults to true. Retry bool // Cache enables/disables the Consul catalog internal cache // avoiding recurrent request to Consul server. Cache bool // Service stores the Consul's service name identifier. E.g: web. Service string // Tag stores the optional Consul's service tag to use when asking to Consul server. Tag string // Scheme stores the default HTTP URI scheme to be used when asking to Consul server. // Defaults to: http. Scheme string // Retrier stores the retry strategy to be used. // Defaults to: ContanstBackOff with max 3 retries. Retrier retry.Retrier // CacheTTL stores the max Consul catalog cache TTL. CacheTTL time.Duration // Client stores the official Consul client Config instance. Client *api.Config // Query stores the official Consul client query options when asking to Consul server. Query *api.QueryOptions }
Config represents the plugin supported settings.
func NewBasicConfig ¶
NewBasicConfig creates a new basic default config with the given Consul server hostname.
type Consul ¶
type Consul struct { // mutex is used internallt to avoid race coditions for multithread scenarios. sync.Mutex // Config stores the Consul's plugin specific settings. Config *Config // Client stores the official Consul client. Client *api.Client // contains filtered or unexported fields }
Consul represents the Consul plugin adapter for gentleman, which encapsulates the official Consul client and plugin specific settings.
func (*Consul) GetBestCandidateNode ¶
GetBestCandidateNode retrieves and returns the best service node candidate asking to Consul server catalog or reading catalog from cache.
func (*Consul) GetNodes ¶
GetNodes returns a list of nodes for the current service from Consul server or from cache (if enabled and not expired).
func (*Consul) IsUpdated ¶
IsUpdated returns true if the current list of catalog services is up-to-date, based on the cache TTL.
func (*Consul) OnBeforeDial ¶
OnBeforeDial is a middleware function handler that replaces the outgoing request URL and provides a new http.RoundTripper if necessary in order to handle request failures and retry it accordingly.
func (*Consul) SetServerURL ¶
SetServerURL sets the request URL fields based on the given Consul service instance.
func (*Consul) UpdateCache ¶
UpdateCache updates the list of catalog services.
type Retrier ¶
type Retrier struct { // Consul stores the Consul client wrapper instance. Consul *Consul // Context stores the HTTP current gentleman context. Context *context.Context // Retry stores the retry strategy to be used. Retry retry.Retrier }
Retrier provides a retry.Retrier capable interface that encapsulates Consul client and user defined strategy.
func NewRetrier ¶
NewRetrier creates a default retrier for the given Consul client and context.