From 5a8e2ca771c6aecd774b275fc31faad935f54bc3 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Thu, 26 Sep 2019 23:32:50 +0200 Subject: [PATCH] Remove redis --- README.md | 2 +- cmd/modern-go-application/config.go | 14 -------- config.toml.dist | 5 --- docker-compose.yml | 3 -- go.mod | 1 - go.sum | 2 -- internal/platform/redis/config.go | 37 ------------------- internal/platform/redis/config_test.go | 39 -------------------- internal/platform/redis/pool.go | 49 -------------------------- 9 files changed, 1 insertion(+), 151 deletions(-) delete mode 100644 internal/platform/redis/config.go delete mode 100755 internal/platform/redis/config_test.go delete mode 100755 internal/platform/redis/pool.go diff --git a/README.md b/README.md index 329a3e8b..db76ae3f 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ To help adopting these practices, this repository also serves as a boilerplate f - support for multiple server/daemon instances (using [oklog/run](https://github.com/oklog/run)) - messaging (using [ThreeDotsLabs/watermill](https://github.com/ThreeDotsLabs/watermill)) - MySQL database connection (using [go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)) -- Redis connection (using [gomodule/redigo](https://github.com/gomodule/redigo)) +- ~~Redis connection (using [gomodule/redigo](https://github.com/gomodule/redigo))~~ removed due to lack of usage (see [#120](../../issues/120)) ## First steps diff --git a/cmd/modern-go-application/config.go b/cmd/modern-go-application/config.go index 98c11a57..81071bd3 100644 --- a/cmd/modern-go-application/config.go +++ b/cmd/modern-go-application/config.go @@ -13,7 +13,6 @@ import ( "github.com/sagikazarmark/modern-go-application/internal/platform/database" "github.com/sagikazarmark/modern-go-application/internal/platform/log" "github.com/sagikazarmark/modern-go-application/internal/platform/opencensus" - "github.com/sagikazarmark/modern-go-application/internal/platform/redis" "github.com/sagikazarmark/modern-go-application/internal/platform/watermill" ) @@ -63,9 +62,6 @@ type configuration struct { // Database connection information Database database.Config - // Redis configuration - Redis redis.Config - // Watermill configuration Watermill struct { RouterConfig watermill.RouterConfig @@ -94,11 +90,6 @@ func (c configuration) Validate() error { return err } - // Uncomment to enable redis config validation - // if err := c.Redis.Validate(); err != nil { - // return err - // } - return nil } @@ -177,11 +168,6 @@ func configure(v *viper.Viper, p *pflag.FlagSet) { "collation": "utf8mb4_general_ci", }) - // Redis configuration - _ = v.BindEnv("redis.host") - v.SetDefault("redis.port", 6379) - _ = v.BindEnv("redis.password") - // Watermill configuration v.RegisterAlias("watermill.routerConfig.closeTimeout", "shutdownTimeout") } diff --git a/config.toml.dist b/config.toml.dist index 8192d91a..e35039e8 100644 --- a/config.toml.dist +++ b/config.toml.dist @@ -33,8 +33,3 @@ user = "root" pass = "" name = "app" params = { collation = "utf8mb4_general_ci" } - -[redis] -host = "127.0.0.1" -port = 6379 -password = [] diff --git a/docker-compose.yml b/docker-compose.yml index bfbe8b01..7aa35b0f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,9 +8,6 @@ services: MYSQL_ALLOW_EMPTY_PASSWORD: "yes" MYSQL_DATABASE: app - redis: - image: redis:5.0 - dockerhost: image: qoomon/docker-host:2.3.0 cap_add: [ 'NET_ADMIN', 'NET_RAW' ] diff --git a/go.mod b/go.mod index 131a65cf..f9535a30 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,6 @@ require ( github.com/go-kit/kit v0.9.0 github.com/go-sql-driver/mysql v1.4.1 github.com/golang/protobuf v1.3.2 - github.com/gomodule/redigo v2.0.0+incompatible github.com/goph/idgen v0.3.0 github.com/gorilla/mux v1.7.3 github.com/inconshreveable/mousetrap v1.0.0 // indirect diff --git a/go.sum b/go.sum index 30b74518..0b2e3dee 100644 --- a/go.sum +++ b/go.sum @@ -95,8 +95,6 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0= -github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= diff --git a/internal/platform/redis/config.go b/internal/platform/redis/config.go deleted file mode 100644 index e1719597..00000000 --- a/internal/platform/redis/config.go +++ /dev/null @@ -1,37 +0,0 @@ -package redis - -import ( - "fmt" - - "emperror.dev/errors" -) - -// Config holds information necessary for connecting to Redis. -type Config struct { - // Host is the Redis host. - Host string - - // Port is the Redis port. - Port int - - // Password list supports passing multiple passwords making password changes easier - Password []string -} - -// Validate checks that the configuration is valid. -func (c Config) Validate() error { - if c.Host == "" { - return errors.New("redis host is required") - } - - if c.Port == 0 { - return errors.New("redis port is required") - } - - return nil -} - -// Server returns the host-port pair for the connection. -func (c Config) Server() string { - return fmt.Sprintf("%s:%d", c.Host, c.Port) -} diff --git a/internal/platform/redis/config_test.go b/internal/platform/redis/config_test.go deleted file mode 100755 index d291e9fd..00000000 --- a/internal/platform/redis/config_test.go +++ /dev/null @@ -1,39 +0,0 @@ -package redis - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestConfig_Validate(t *testing.T) { - tests := map[string]Config{ - "redis host is required": { - Port: 6379, - }, - "redis port is required": { - Host: "127.0.0.1", - }, - } - - for name, test := range tests { - name, test := name, test - - t.Run(name, func(t *testing.T) { - err := test.Validate() - - assert.EqualError(t, err, name) - }) - } -} - -func TestConfig_Server(t *testing.T) { - config := Config{ - Host: "127.0.0.1", - Port: 6379, - } - - server := config.Server() - - assert.Equal(t, "127.0.0.1:6379", server) -} diff --git a/internal/platform/redis/pool.go b/internal/platform/redis/pool.go deleted file mode 100755 index 0c6eaea1..00000000 --- a/internal/platform/redis/pool.go +++ /dev/null @@ -1,49 +0,0 @@ -package redis - -import ( - "time" - - "emperror.dev/errors" - "github.com/gomodule/redigo/redis" -) - -// NewPool creates a new redis connection pool. -func NewPool(config Config) *redis.Pool { - return &redis.Pool{ - MaxIdle: 10, - Wait: true, // Wait for the connection pool, no connection pool exhausted error - Dial: func() (redis.Conn, error) { - c, err := redis.Dial( - "tcp", - config.Server(), - ) - if err != nil { - return nil, errors.Wrap(err, "failed to dial redis server") - } - - if len(config.Password) > 0 { - var err error - - for _, password := range config.Password { - _, err = c.Do("AUTH", password) - if err == nil { - break - } - } - - if err != nil { - _ = c.Close() - - return nil, errors.Wrap(err, "none of the provided passwords were accepted by the server") - } - } - - return c, nil - }, - TestOnBorrow: func(c redis.Conn, t time.Time) error { - _, err := c.Do("PING") - - return err - }, - } -}