Documentation ¶
Index ¶
- Constants
- func DefaultExecHandler(result sql.Result) (bool, error)
- func DefaultQueryHandler(rows *sql.Rows) (bool, error)
- type HTTP
- type HTTPConfig
- type Redis
- type RedisAuthConfig
- type RedisConfig
- type RedisGetOptions
- type RedisSetOptions
- type SQL
- type SQLConfig
- type SQLExecer
- type SQLExecerResultHandler
- type SQLPinger
- type SQLQueryer
- type SQLQueryerResultHandler
Constants ¶
const ( // RedisDefaultSetValue will be used if the "Set" check method is enabled // and "RedisSetOptions.Value" is _not_ set. RedisDefaultSetValue = "go-health/redis-check" )
Variables ¶
This section is empty.
Functions ¶
func DefaultExecHandler ¶ added in v1.0.2
DefaultExecHandler is the default SQLExecer result handler that assumes one row was affected in the passed query
Types ¶
type HTTP ¶
type HTTP struct {
Config *HTTPConfig
}
HTTP implements the "ICheckable" interface.
func NewHTTP ¶
func NewHTTP(cfg *HTTPConfig) (*HTTP, error)
NewHTTP creates a new HTTP checker that can be used for ".AddCheck(s)".
type HTTPConfig ¶
type HTTPConfig struct { URL *url.URL // Required Method string // Optional (default GET) Payload interface{} // Optional StatusCode int // Optional (default 200) Expect string // Optional Client *http.Client // Optional Timeout time.Duration // Optional (default 3s) }
HTTPConfig is used for configuring an HTTP check. The only required field is `URL`.
"Method" is optional and defaults to `GET` if undefined.
"Payload" is optional and can accept `string`, `[]byte` or will attempt to marshal the input to JSON for use w/ `bytes.NewReader()`.
"StatusCode" is optional and defaults to `200`.
"Expect" is optional; if defined, operates as a basic "body should contain <string>".
"Client" is optional; if undefined, a new client will be created using "Timeout".
"Timeout" is optional and defaults to "3s".
type Redis ¶
type Redis struct { Config *RedisConfig // contains filtered or unexported fields }
Redis implements the ICheckable interface
func NewRedis ¶
func NewRedis(cfg *RedisConfig) (*Redis, error)
NewRedis creates a new "go-redis/redis" checker that can be used w/ "AddChecks()".
type RedisAuthConfig ¶
type RedisAuthConfig struct { Addr string // `host:port` format Password string // leave blank if no password DB int // leave unset if no specific db }
RedisAuthConfig defines how to connect to redis.
type RedisConfig ¶
type RedisConfig struct { Auth *RedisAuthConfig Ping bool Set *RedisSetOptions Get *RedisGetOptions }
RedisConfig is used for configuring the go-redis check.
"Auth" is _required_; redis connection/auth config.
"Ping" is optional; the most basic check method, performs a `.Ping()` on the client.
"Get" is optional; perform a "GET" on a key; refer to the "RedisGetOptions" docs for details.
"Set" is optional; perform a "SET" on a key; refer to the "RedisSetOptions" docs for details.
Note: At least _one_ check method must be set/enabled; you can also enable _all_ of the check methods (ie. perform a ping, set this key and now try to retrieve that key).
type RedisGetOptions ¶
RedisGetOptions contains attributes that can alter the behavior of the redis "GET" check.
"Key" is _required_; the name of the key that we are attempting to "GET".
"Expect" is optional; optionally verify that the value for the key matches the Expect value.
"NoErrorMissingKey" is optional; by default, the "GET" check will error if the key we are fetching does not exist; flip this bool if that is normal/expected/ok.
type RedisSetOptions ¶
RedisSetOptions contains attributes that can alter the behavior of the redis "SET" check.
"Key" is _required_; the name of the key we are attempting to "SET".
"Value" is optional; what the value should hold; if not set, it will be set to "RedisDefaultSetValue".
"Expiration" is optional; if set, a TTL will be attached to the key.
type SQL ¶ added in v1.0.2
type SQL struct {
Config *SQLConfig
}
SQL implements the "ICheckable" interface
type SQLConfig ¶ added in v1.0.2
type SQLConfig struct { // Pinger is the value implementing SQLPinger Pinger SQLPinger // Queryer is the value implementing SQLQueryer Queryer SQLQueryer // Execer is the value implementing SQLExecer Execer SQLExecer // Query is the parameterized SQL query required // with both Queryer and Execer Query string // Params are the SQL query parameters, if any Params []interface{} // QueryerResultHandler handles the result of // the QueryContext function QueryerResultHandler SQLQueryerResultHandler // ExecerResultHandler handles the result of // the ExecContext function ExecerResultHandler SQLExecerResultHandler }
SQLConfig is used for configuring a database check. One of the Pinger, Queryer, or Execer fields is required.
If Execer is set, it will take precedence over Queryer and Pinger, Execer implements the SQLExecer interface in this package. The sql.DB and sql.TX structs both implement this interface.
Note that if the Execer is set, then the ExecerResultHandler and Query values MUST also be set
If Queryer is set, it will take precedence over Pinger. SQLQueryer implements the SQLQueryer interface in this package. The sql.DB and sql.TX structs both implement this interface.
Note that if the Queryer is set, then the QueryerResultHandler and Query values MUST also be set
Pinger implements the SQLPinger interface in this package. The sql.DB struct implements this interface.
type SQLExecer ¶ added in v1.0.2
type SQLExecer interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
SQLExecer is an interface that allows executing of queries in the database
type SQLExecerResultHandler ¶ added in v1.0.2
SQLExecerResultHandler is the BYO function to handle a database exec result
type SQLPinger ¶ added in v1.0.2
SQLPinger is an interface that allows direct pinging of the database