/
connection.go
49 lines (43 loc) · 1 KB
/
connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package client
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sns"
"github.com/go-redis/redis"
"os"
)
var (
RedisConnection *redis.Client
SnsClient *sns.SNS
dialect string
host string
port string
user string
password string
err error
redisHost string
BaseDB *Database
)
func init() {
// Check and Load the Client Connection
dialect = os.Getenv("_DB_DIALECT")
host = os.Getenv("_DB_HOST")
port = os.Getenv("_DB_PORT")
user = os.Getenv("_DB_USER")
password = os.Getenv("_DB_PASSWORD")
redisHost = os.Getenv("_REDIS_URI")
CreateRedisConnection()
}
func CreateRedisConnection() {
if redisHost != ""{
RedisConnection = redis.NewClient(&redis.Options{
Addr: redisHost,
DB: 0, // use default DB
})
}
}
func CreateAwsSession() {
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
SnsClient = sns.New(sess)
}