X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=db%2Fdb.go;h=078cd5895885f5308a13729c3acca58ed2544266;hb=323b7f4032d19c06523f2eaaf1d20d32e1330b54;hp=7f87201a354abb1d7a64a0e1166972ea758fa83f;hpb=4215df47c93c6ea26f21c74a9d52f78d1d103dde;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/db/db.go b/db/db.go index 7f87201..078cd58 100644 --- 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 {