Documentation ¶
Overview ¶
Package client implements client for Policy Information Point (PIP) server.
Index ¶
- Variables
- type CacheHitHandler
- type Client
- type ConnErrHandler
- type Option
- func WithAddress(a string) Option
- func WithBufferSize(n int) Option
- func WithCacheHitHandler(h CacheHitHandler) Option
- func WithCacheTTL(d time.Duration) Option
- func WithCacheTTLAndMaxSize(d time.Duration, size int) Option
- func WithConnErrHandler(f ConnErrHandler) Option
- func WithConnTimeout(d time.Duration) Option
- func WithDNSRadar() Option
- func WithHotSpotBalancer(addrs ...string) Option
- func WithK8sRadar() Option
- func WithMaxQueue(n int) Option
- func WithMaxRequestSize(n int) Option
- func WithNetwork(n string) Option
- func WithResponseCheckInterval(d time.Duration) Option
- func WithResponseTimeout(d time.Duration) Option
- func WithRoundRobinBalancer(addrs ...string) Option
- func WithWriteInterval(d time.Duration) Option
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConnected occurs if method connect is called after connection has been // established. ErrConnected = errors.New("connection has been already established") // ErrNotConnected occurs if method get is called before connection has been // established. ErrNotConnected = errors.New("connection hasn't been established yet") )
Functions ¶
This section is empty.
Types ¶
type CacheHitHandler ¶
type CacheHitHandler func(path string, args []pdp.AttributeValue, v pdp.AttributeValue, err error)
CacheHitHandler defines a function prototype to call on each cache hit if cache has been enabled.
type Client ¶
type Client interface { // Connect establishes connection to given PIP server. Connect() error // Close terminates previously established connection if any. Close silently // returns if connection hasn't been established yet or if it has been // already closed. Close() // Get requests information from PIP. Get(path string, args []pdp.AttributeValue) (pdp.AttributeValue, error) }
Client defines abstract PIP service client interface.
type ConnErrHandler ¶
ConnErrHandler is a function to process errors within a connection.
type Option ¶
type Option func(*options)
An Option allows to set such options as address, balancer and so on.
func WithAddress ¶
WithAddress returns an Option which sets destination address.
func WithBufferSize ¶
WithBufferSize returns an Option which sets size of input and output buffers. By default it is 1 MB.
func WithCacheHitHandler ¶
func WithCacheHitHandler(h CacheHitHandler) Option
WithCacheHitHandler returns an Option which sets handler for cache hits.
func WithCacheTTL ¶
WithCacheTTL returns an Option which adds cache with given TTL for cached requests. Cache size isn't limited in the case and can consume all available memory on machine.
func WithCacheTTLAndMaxSize ¶
WithCacheTTLAndMaxSize returns an Option which adds cache with given TTL and size limit for entire cache in MB. When the limit is reached then new requests override the oldest ones.
func WithConnErrHandler ¶
func WithConnErrHandler(f ConnErrHandler) Option
WithConnErrHandler returns an Option which sets custom handler for transport errors.
func WithConnTimeout ¶
WithConnTimeout returns an Option which sets connection timeout.
func WithDNSRadar ¶
func WithDNSRadar() Option
WithDNSRadar returns an Option which turns on DNS discovery (DNS radar). The radar periodicaly looks up for IP addresses using system resolver (works only for TCP networks). It uses an address given by WithAddress option as host name for DNS qurey. If the query gives several IP addresses, PIP client balances load using balancer given by With*Balancer option. Addresses which come from With*Balancer option are used only as initial set of addresses to connect to. If further DNS queries don't return those addresses client stops using them.
func WithHotSpotBalancer ¶
WithHotSpotBalancer returns an Option which sets hot spot balancer. The balancer puts requests to the same connection until its queue is full and then goes to the next connection. If no addresses provided with the option client connects to all IP addresses it can get by host name from WithAddress option. For "unix" network the option is ignored.
func WithK8sRadar ¶
func WithK8sRadar() Option
WithK8sRadar returns an Option which turns on kubernetes discovery. The discovery works only inside kubernetes cluster and requires "get", "watch" and "list" access to "pods" resource. It treats address from WithAddress option as selector encoded in following form "<valueN>.<keyN>. ... .<value2>.<key2>.<value1>.<key1>.<namespacea>" (it should contain at least one key value pair and namespace). Similarly to DNS in case of several pods given balancer is used and addresses coming with balancer options become initiall addresses. However the discovery drops connection to an initiall address only if kubernetes tells that the pod with the IP goes down.
func WithMaxQueue ¶
WithMaxQueue returns an Option which limits number of requests client can send in parallel.
func WithMaxRequestSize ¶
WithMaxRequestSize returns an Option which limits request size in bytes to given value. Default 10KB.
func WithNetwork ¶
WithNetwork returns an Option which sets destination network. The client supports "tcp", "tcp4", "tcp6" and "unix" netwroks.
func WithResponseCheckInterval ¶
WithResponseCheckInterval returns an Option which sets inteval of timeout checks.
func WithResponseTimeout ¶
WithResponseTimeout returns an Option which sets timeout for a response. If client gets no response within the interval it drops connection.
func WithRoundRobinBalancer ¶
WithRoundRobinBalancer returns an Option which sets round robin balancer. If no addresses provided with the option client connects to all IP addresses it can get by host name from WithAddress option. For "unix" network the option is ignored.
func WithWriteInterval ¶
WithWriteInterval returns an Option which sets duration after which data from write buffer are sent to network even if write buffer isn't full. Default 50 us.