From d96a4dfcf55b3b15fdf1f31481d7f2333e1ea20f Mon Sep 17 00:00:00 2001 From: Vladimir Garvardt Date: Fri, 22 Sep 2017 15:46:26 +0200 Subject: [PATCH] Init config defaults outside of checker function --- Gopkg.lock | 33 --------------------------------- Gopkg.toml | 38 -------------------------------------- checks/http/check.go | 14 +++++++------- checks/postgres/check.go | 8 ++++---- checks/rabbitmq/check.go | 39 +++++++++++++++++++-------------------- checks/redis/check.go | 8 ++++---- 6 files changed, 34 insertions(+), 106 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 328a6c3..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,33 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - name = "github.com/garyburd/redigo" - packages = ["internal","redis"] - revision = "433969511232c397de61b1442f9fd49ec06ae9ba" - version = "v1.1.0" - -[[projects]] - branch = "master" - name = "github.com/lib/pq" - packages = [".","oid"] - revision = "23da1db4f16d9658a86ae9b717c245fc078f10f1" - -[[projects]] - branch = "master" - name = "github.com/streadway/amqp" - packages = ["."] - revision = "2cbfe40c9341ad63ba23e53013b3ddc7989d801c" - -[[projects]] - branch = "v2" - name = "gopkg.in/mgo.v2" - packages = [".","bson","internal/json","internal/sasl","internal/scram"] - revision = "3f83fa5005286a7fe593b055f0d7771a7dce4655" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "fc205481720ab78f3ed99173e5f33005ac460b7983f35f9fee34e7610d322892" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 4ec5285..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,38 +0,0 @@ - -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - -[[constraint]] - name = "github.com/garyburd/redigo" - version = "1.1.0" - -[[constraint]] - branch = "master" - name = "github.com/lib/pq" - -[[constraint]] - branch = "master" - name = "github.com/streadway/amqp" - -[[constraint]] - branch = "v2" - name = "gopkg.in/mgo.v2" diff --git a/checks/http/check.go b/checks/http/check.go index eae91c8..8b96ce2 100644 --- a/checks/http/check.go +++ b/checks/http/check.go @@ -24,15 +24,15 @@ type Config struct { // - getting response status from defined URL // - verifying that status code is less than 500 func New(config Config) func() error { - return func() error { - if config.LogFunc == nil { - config.LogFunc = func(err error, details string, extra ...interface{}) {} - } + if config.LogFunc == nil { + config.LogFunc = func(err error, details string, extra ...interface{}) {} + } - if config.RequestTimeout == 0 { - config.RequestTimeout = time.Second * 5 - } + if config.RequestTimeout == 0 { + config.RequestTimeout = time.Second * 5 + } + return func() error { req, err := http.NewRequest(http.MethodGet, config.URL, nil) if err != nil { config.LogFunc(err, "Creating the request for the health check failed") diff --git a/checks/postgres/check.go b/checks/postgres/check.go index a16dde5..4ece946 100644 --- a/checks/postgres/check.go +++ b/checks/postgres/check.go @@ -32,11 +32,11 @@ type Config struct { // - selecting inserted row // - deleting inserted row func New(config Config) func() error { - return func() error { - if config.LogFunc == nil { - config.LogFunc = func(err error, details string, extra ...interface{}) {} - } + if config.LogFunc == nil { + config.LogFunc = func(err error, details string, extra ...interface{}) {} + } + return func() error { db, err := sql.Open("postgres", config.DSN) if err != nil { config.LogFunc(err, "PostgreSQL health check failed during connect") diff --git a/checks/rabbitmq/check.go b/checks/rabbitmq/check.go index a7d80f3..09403f3 100644 --- a/checks/rabbitmq/check.go +++ b/checks/rabbitmq/check.go @@ -41,32 +41,31 @@ type Config struct { // - publishing a message to the exchange with the defined routing key // - consuming published message func New(config Config) func() error { - return func() error { - if config.LogFunc == nil { - config.LogFunc = func(err error, details string, extra ...interface{}) {} - } + if config.LogFunc == nil { + config.LogFunc = func(err error, details string, extra ...interface{}) {} + } - if config.Exchange == "" { - config.Exchange = defaultExchange - } + if config.Exchange == "" { + config.Exchange = defaultExchange + } - if config.RoutingKey == "" { - host, err := os.Hostname() - if nil != err { - config.LogFunc(err, "RabbitMQ health check failed on settings default value for unset routing key") - return err - } - config.RoutingKey = host + if config.RoutingKey == "" { + host, err := os.Hostname() + if nil != err { + config.RoutingKey = "-unknown-" } + config.RoutingKey = host + } - if config.Queue == "" { - config.Queue = fmt.Sprintf("%s.%s", config.Exchange, config.RoutingKey) - } + if config.Queue == "" { + config.Queue = fmt.Sprintf("%s.%s", config.Exchange, config.RoutingKey) + } - if config.ConsumeTimeout == 0 { - config.ConsumeTimeout = time.Second * 3 - } + if config.ConsumeTimeout == 0 { + config.ConsumeTimeout = time.Second * 3 + } + return func() error { conn, err := amqp.Dial(config.DSN) if err != nil { config.LogFunc(err, "RabbitMQ health check failed on dial phase") diff --git a/checks/redis/check.go b/checks/redis/check.go index 9fbf95b..bd4d024 100644 --- a/checks/redis/check.go +++ b/checks/redis/check.go @@ -20,11 +20,11 @@ type Config struct { // - connection establishing // - doing the PING command and verifying the response func New(config Config) func() error { - return func() error { - if config.LogFunc == nil { - config.LogFunc = func(err error, details string, extra ...interface{}) {} - } + if config.LogFunc == nil { + config.LogFunc = func(err error, details string, extra ...interface{}) {} + } + return func() error { pool := &redis.Pool{ MaxIdle: 1, IdleTimeout: 10 * time.Second,