aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjloup <jeanloup.jamet@gmail.com>2018-04-30 22:28:59 +0200
committerjloup <jeanloup.jamet@gmail.com>2018-04-30 22:28:59 +0200
commit323b7f4032d19c06523f2eaaf1d20d32e1330b54 (patch)
treea8d966c703755c5986505f8ed742b666800df12b
parent4215df47c93c6ea26f21c74a9d52f78d1d103dde (diff)
downloadFront-323b7f4032d19c06523f2eaaf1d20d32e1330b54.tar.gz
Front-323b7f4032d19c06523f2eaaf1d20d32e1330b54.tar.zst
Front-323b7f4032d19c06523f2eaaf1d20d32e1330b54.zip
Redis connection.
-rw-r--r--Gopkg.lock17
-rw-r--r--Gopkg.toml4
-rw-r--r--cmd/app/conf.toml4
-rw-r--r--cmd/app/main.go9
-rw-r--r--db/db.go30
5 files changed, 56 insertions, 8 deletions
diff --git a/Gopkg.lock b/Gopkg.lock
index 8d11158..d8ceccf 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -71,6 +71,21 @@
71 version = "v6.10.0" 71 version = "v6.10.0"
72 72
73[[projects]] 73[[projects]]
74 name = "github.com/go-redis/redis"
75 packages = [
76 ".",
77 "internal",
78 "internal/consistenthash",
79 "internal/hashtag",
80 "internal/pool",
81 "internal/proto",
82 "internal/singleflight",
83 "internal/util"
84 ]
85 revision = "877867d2845fbaf86798befe410b6ceb6f5c29a3"
86 version = "v6.10.2"
87
88[[projects]]
74 name = "github.com/golang/protobuf" 89 name = "github.com/golang/protobuf"
75 packages = ["proto"] 90 packages = ["proto"]
76 revision = "925541529c1fa6821df4e44ce2723319eb2be768" 91 revision = "925541529c1fa6821df4e44ce2723319eb2be768"
@@ -162,6 +177,6 @@
162[solve-meta] 177[solve-meta]
163 analyzer-name = "dep" 178 analyzer-name = "dep"
164 analyzer-version = 1 179 analyzer-version = 1
165 inputs-digest = "e3fa83f0fc133d3c408abdc47e5c2ca08062fec7c34ea04c21ea122492ab863d" 180 inputs-digest = "587bbc93998cd884863b3559ec6ef87ebf381b7bca10587a7e79c2c227c64ead"
166 solver-name = "gps-cdcl" 181 solver-name = "gps-cdcl"
167 solver-version = 1 182 solver-version = 1
diff --git a/Gopkg.toml b/Gopkg.toml
index 4feee4d..9721956 100644
--- a/Gopkg.toml
+++ b/Gopkg.toml
@@ -64,3 +64,7 @@
64[[constraint]] 64[[constraint]]
65 branch = "master" 65 branch = "master"
66 name = "github.com/shopspring/decimal" 66 name = "github.com/shopspring/decimal"
67
68[[constraint]]
69 name = "github.com/go-redis/redis"
70 version = "6.10.2"
diff --git a/cmd/app/conf.toml b/cmd/app/conf.toml
index 47964b4..bdbf58b 100644
--- a/cmd/app/conf.toml
+++ b/cmd/app/conf.toml
@@ -8,6 +8,10 @@ password="cryptoportfolio-dev"
8database="cryptoportfolio" 8database="cryptoportfolio"
9address="localhost:5432" 9address="localhost:5432"
10 10
11[redis]
12type="tcp"
13address="cryptoportfolio.immae.eu:7617"
14
11[api] 15[api]
12domain="localhost" 16domain="localhost"
13jwt_secret="secret" 17jwt_secret="secret"
diff --git a/cmd/app/main.go b/cmd/app/main.go
index 4bd77bd..65e8b5a 100644
--- a/cmd/app/main.go
+++ b/cmd/app/main.go
@@ -26,9 +26,10 @@ type ApiConfig struct {
26} 26}
27 27
28type Config struct { 28type Config struct {
29 App AppConfig 29 App AppConfig
30 Api ApiConfig 30 Api ApiConfig
31 Db db.DBConfig 31 Db db.DBConfig
32 Redis db.RedisConfig
32 33
33 utils.LogConfiguration 34 utils.LogConfiguration
34 Address string 35 Address string
@@ -64,7 +65,7 @@ func init() {
64 65
65 api.SetJwtSecretKey(C.Api.JwtSecret) 66 api.SetJwtSecretKey(C.Api.JwtSecret)
66 67
67 db.Init(C.Db) 68 db.Init(C.Db, C.Redis)
68 69
69 if C.Mode == "production" { 70 if C.Mode == "production" {
70 gin.SetMode(gin.ReleaseMode) 71 gin.SetMode(gin.ReleaseMode)
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 (
4 migrate "github.com/go-pg/migrations" 4 migrate "github.com/go-pg/migrations"
5 "github.com/go-pg/pg" 5 "github.com/go-pg/pg"
6 "github.com/go-pg/pg/orm" 6 "github.com/go-pg/pg/orm"
7 "github.com/go-redis/redis"
7 "github.com/jloup/utils" 8 "github.com/jloup/utils"
8) 9)
9 10
10var DB *pg.DB
11
12var log = utils.StandardL().WithField("module", "db") 11var log = utils.StandardL().WithField("module", "db")
13 12
13var (
14 DB *pg.DB
15 Redis *redis.Client
16)
17
14type DBConfig struct { 18type DBConfig struct {
15 Address string 19 Address string
16 Database string 20 Database string
@@ -18,7 +22,13 @@ type DBConfig struct {
18 Password string 22 Password string
19} 23}
20 24
21func Init(config DBConfig) { 25type RedisConfig struct {
26 Type string // tcp or unix
27 Address string
28 Password string
29}
30
31func Init(config DBConfig, redisConfig RedisConfig) {
22 var err error 32 var err error
23 33
24 DB = connect(config) 34 DB = connect(config)
@@ -27,6 +37,20 @@ func Init(config DBConfig) {
27 if err != nil { 37 if err != nil {
28 log.Fatalf("cannot migratedb '%v'\n", err) 38 log.Fatalf("cannot migratedb '%v'\n", err)
29 } 39 }
40
41 Redis = redis.NewClient(&redis.Options{
42 Network: redisConfig.Type,
43 Addr: redisConfig.Address,
44 Password: redisConfig.Password,
45 DB: 0,
46 })
47
48 _, err = Redis.Ping().Result()
49
50 if err != nil {
51 log.Fatalf("redis init error %s", err)
52 }
53
30} 54}
31 55
32func migratedb() error { 56func migratedb() error {