]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/commitdiff
Redis connection.
authorjloup <jeanloup.jamet@gmail.com>
Mon, 30 Apr 2018 20:28:59 +0000 (22:28 +0200)
committerjloup <jeanloup.jamet@gmail.com>
Mon, 30 Apr 2018 20:28:59 +0000 (22:28 +0200)
Gopkg.lock
Gopkg.toml
cmd/app/conf.toml
cmd/app/main.go
db/db.go

index 8d111580cea86693d0b5c750273e398d887a19bc..d8ceccf32e28edae7013e707fab92e2fd5c52f8b 100644 (file)
   revision = "24dfe0572921e42ffe1035f7afbd40f9d97cb8c8"
   version = "v6.10.0"
 
+[[projects]]
+  name = "github.com/go-redis/redis"
+  packages = [
+    ".",
+    "internal",
+    "internal/consistenthash",
+    "internal/hashtag",
+    "internal/pool",
+    "internal/proto",
+    "internal/singleflight",
+    "internal/util"
+  ]
+  revision = "877867d2845fbaf86798befe410b6ceb6f5c29a3"
+  version = "v6.10.2"
+
 [[projects]]
   name = "github.com/golang/protobuf"
   packages = ["proto"]
 [solve-meta]
   analyzer-name = "dep"
   analyzer-version = 1
-  inputs-digest = "e3fa83f0fc133d3c408abdc47e5c2ca08062fec7c34ea04c21ea122492ab863d"
+  inputs-digest = "587bbc93998cd884863b3559ec6ef87ebf381b7bca10587a7e79c2c227c64ead"
   solver-name = "gps-cdcl"
   solver-version = 1
index 4feee4d8d35575ed61cbe41fa961058705f0db5a..9721956104f2d9a8aa1b1bbb99780353821e12da 100644 (file)
@@ -64,3 +64,7 @@
 [[constraint]]
   branch = "master"
   name = "github.com/shopspring/decimal"
+
+[[constraint]]
+  name = "github.com/go-redis/redis"
+  version = "6.10.2"
index 47964b49fd040a495d426c50cc09a19cd91ce6a3..bdbf58b802696ab352f5906dbf66f9630fdfb49c 100644 (file)
@@ -8,6 +8,10 @@ password="cryptoportfolio-dev"
 database="cryptoportfolio"
 address="localhost:5432"
 
+[redis]
+type="tcp"
+address="cryptoportfolio.immae.eu:7617"
+
 [api]
 domain="localhost"
 jwt_secret="secret"
index 4bd77bd31fed677535a22f14fb0ab979efc7c34d..65e8b5a49af92b4dbda73472595b33883aebea77 100644 (file)
@@ -26,9 +26,10 @@ type ApiConfig struct {
 }
 
 type Config struct {
-       App AppConfig
-       Api ApiConfig
-       Db  db.DBConfig
+       App   AppConfig
+       Api   ApiConfig
+       Db    db.DBConfig
+       Redis db.RedisConfig
 
        utils.LogConfiguration
        Address string
@@ -64,7 +65,7 @@ func init() {
 
        api.SetJwtSecretKey(C.Api.JwtSecret)
 
-       db.Init(C.Db)
+       db.Init(C.Db, C.Redis)
 
        if C.Mode == "production" {
                gin.SetMode(gin.ReleaseMode)
index 7f87201a354abb1d7a64a0e1166972ea758fa83f..078cd5895885f5308a13729c3acca58ed2544266 100644 (file)
--- a/db/db.go
+++ b/db/db.go
@@ -4,13 +4,17 @@ import (
        migrate "github.com/go-pg/migrations"
        "github.com/go-pg/pg"
        "github.com/go-pg/pg/orm"
+       "github.com/go-redis/redis"
        "github.com/jloup/utils"
 )
 
-var DB *pg.DB
-
 var log = utils.StandardL().WithField("module", "db")
 
+var (
+       DB    *pg.DB
+       Redis *redis.Client
+)
+
 type DBConfig struct {
        Address  string
        Database string
@@ -18,7 +22,13 @@ type DBConfig struct {
        Password string
 }
 
-func Init(config DBConfig) {
+type RedisConfig struct {
+       Type     string // tcp or unix
+       Address  string
+       Password string
+}
+
+func Init(config DBConfig, redisConfig RedisConfig) {
        var err error
 
        DB = connect(config)
@@ -27,6 +37,20 @@ func Init(config DBConfig) {
        if err != nil {
                log.Fatalf("cannot migratedb '%v'\n", err)
        }
+
+       Redis = redis.NewClient(&redis.Options{
+               Network:  redisConfig.Type,
+               Addr:     redisConfig.Address,
+               Password: redisConfig.Password,
+               DB:       0,
+       })
+
+       _, err = Redis.Ping().Result()
+
+       if err != nil {
+               log.Fatalf("redis init error %s", err)
+       }
+
 }
 
 func migratedb() error {