-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.go
45 lines (36 loc) · 1.08 KB
/
resources.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
package api
import (
"os"
"strconv"
"github.com/rs/zerolog/log"
"github.com/kodekoding/phastos/v2/go/cache"
"github.com/kodekoding/phastos/v2/go/database"
)
func (app *App) loadResources() {
var err error
// load DB + transactions
connString := os.Getenv("DATABASE_CONN_STRING_MASTER")
if connString != "" {
app.db, err = database.Connect()
if err != nil {
log.Fatal().Msgf("Can't load database: %s", err.Error())
}
// get transaction from DB
app.trx = app.db.GetTransaction()
}
redisConnection := os.Getenv("REDIS_CONN_STRING")
if redisConnection != "" {
redisTimeout, _ := strconv.Atoi(os.Getenv("REDIS_TIMEOUT"))
redisMaxActive, _ := strconv.Atoi(os.Getenv("REDIS_MAX_ACTIVE"))
redisMaxIdle, _ := strconv.Atoi(os.Getenv("REDIS_MAX_IDLE"))
cacheService := cache.New(
cache.WithAddress(redisConnection),
cache.WithTimeout(redisTimeout),
cache.WithMaxActive(redisMaxActive),
cache.WithMaxIdle(redisMaxIdle),
cache.WithPassword(os.Getenv("REDIS_PASSWORD")),
cache.WithUsername(os.Getenv("REDIS_USERNAME")),
)
app.WrapToApp(cacheService)
}
}