Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Close() error
- func (c *Client) Find(ip string) (reason string, err error)
- func (c *Client) Flush() error
- func (c *Client) Insert(ipRange, reason string) error
- func (c *Client) Remove(ipRange string) error
- func (c *Client) Reset() error
- func (c *Client) UpdateReasonOf(ip string, fn UpdateFunc) (err error)
- type Error
- type Options
- type UpdateFunc
Constants ¶
View Source
const ( // ErrConnectionFailed is returned when the connection to the redis database fails. ErrConnectionFailed = Error("failed to establish a connection to the redis database") // ErrDatabaseInit is returned when the initialization of the database boundaries fails. ErrDatabaseInit = Error("failed to initialize database ±inf boundaries") // ErrDatabaseInconsistent is returned when the initialization of the database boundaries fails. ErrDatabaseInconsistent = Error("the databe is in an inconsistent state") // ErrInvalidRange is returned when a passed string is not a valid range ErrInvalidRange = Error("invalid range passed, use either of these: <IP>, <IP>/<1-32>, <IP> - <IP>") // ErrIPv6NotSupported is returned if an IPv6 range or IP input is detected. ErrIPv6NotSupported = Error("IPv6 ranges are not supported") // ErrInvalidIP is returned when the passed argument is an invalid IP ErrInvalidIP = Error("invalid IP passed") // ErrNoResult is returned when a result slic is empty or some connection error occurs during retrieval of values. ErrNoResult = Error("could not retrieve any results from the database") // ErrIPNotFound is returned if the passed IP is not contained in any ranges ErrIPNotFound = Error("the given IP was not found in any database ranges") )
Variables ¶
View Source
var ( // IPRangesKey contains the key name of the sorted set that contains the IPs (integers) IPRangesKey = "________________IP_RANGES________________" // DeleteReason is given to a specific deltion range // on a second attept (not aromic) the range is then finally deleted. DeleteReason = "_________________DELETE_________________" )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an extended version of the redis.Client
func (*Client) Find ¶
Find searches for the requested IP in the database. If the IP is found within any previously inserted range, the associated reason is returned. If it is not found, an error is returned instead.
func (*Client) Insert ¶
Insert inserts a new IP range or IP into the database with an associated reason string
func (*Client) UpdateReasonOf ¶ added in v1.1.0
func (c *Client) UpdateReasonOf(ip string, fn UpdateFunc) (err error)
UpdateReasonOf updates the reason of the range that contains the passed ip.
type Error ¶
type Error string
Error is a wrapper for constant errors that are not supposed to be changed.
type Options ¶
type Options struct { // The network type, either tcp or unix. // Default is tcp. Network string // host:port address. Addr string // Dialer creates new network connection and has priority over // Network and Addr options. Dialer func() (net.Conn, error) // Hook that is called when new connection is established. OnConnect func(*redis.Conn) error // Optional password. Must match the password specified in the // requirepass server configuration option. Password string // Database to be selected after connecting to the server. DB int // Maximum number of retries before giving up. // Default is to not retry failed commands. MaxRetries int // Minimum backoff between each retry. // Default is 8 milliseconds; -1 disables backoff. MinRetryBackoff time.Duration // Maximum backoff between each retry. // Default is 512 milliseconds; -1 disables backoff. MaxRetryBackoff time.Duration // Dial timeout for establishing new connections. // Default is 5 seconds. DialTimeout time.Duration // Timeout for socket reads. If reached, commands will fail // with a timeout instead of blocking. Use value -1 for no timeout and 0 for default. // Default is 3 seconds. ReadTimeout time.Duration // Timeout for socket writes. If reached, commands will fail // with a timeout instead of blocking. // Default is ReadTimeout. WriteTimeout time.Duration // Maximum number of socket connections. // Default is 10 connections per every CPU as reported by runtime.NumCPU. PoolSize int // Minimum number of idle connections which is useful when establishing // new connection is slow. MinIdleConns int // Connection age at which client retires (closes) the connection. // Default is to not close aged connections. MaxConnAge time.Duration // Amount of time client waits for connection if all connections // are busy before returning an error. // Default is ReadTimeout + 1 second. PoolTimeout time.Duration // Amount of time after which client closes idle connections. // Should be less than server's timeout. // Default is 5 minutes. -1 disables idle timeout check. IdleTimeout time.Duration // Frequency of idle checks made by idle connections reaper. // Default is 1 minute. -1 disables idle connections reaper, // but idle connections are still discarded by the client // if IdleTimeout is set. IdleCheckFrequency time.Duration // TLS Config to use. When set TLS will be negotiated. TLSConfig *tls.Config }
Options configures the redis database connection
type UpdateFunc ¶ added in v1.1.0
UpdateFunc updates the previous reason to a new reason.
Click to show internal directories.
Click to hide internal directories.