Skip to content

Commit e0f707d

Browse files
committed
switch dbval to integer
1 parent 19de0e9 commit e0f707d

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

apps/jan-api-gateway/application/app/infrastructure/cache/redis_cache_service.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cache
33
import (
44
"context"
55
"fmt"
6-
"strconv"
76
"strings"
87
"time"
98

@@ -34,12 +33,8 @@ func NewRedisCacheService() *RedisCacheService {
3433
opts.Password = pwd
3534
}
3635

37-
if dbVal := environment_variables.EnvironmentVariables.REDIS_DB; dbVal != "" {
38-
db, err := strconv.Atoi(dbVal)
39-
if err != nil {
40-
panic(fmt.Sprintf("invalid REDIS_DB value: %v", err))
41-
}
42-
opts.DB = db
36+
if dbVal := environment_variables.EnvironmentVariables.REDIS_DB; dbVal != 0 {
37+
opts.DB = dbVal
4338
}
4439

4540
if len(opts.Addrs) > 1 && opts.DB != 0 {

apps/jan-api-gateway/application/config/environment_variables/env.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package environment_variables
22

33
import (
4-
"fmt"
54
"os"
65
"reflect"
76
"strconv"
87
"strings"
98
"time"
109

10+
"menlo.ai/jan-api-gateway/app/utils/logger"
1111
"menlo.ai/jan-api-gateway/config"
1212
)
1313

@@ -32,7 +32,7 @@ type EnvironmentVariable struct {
3232
// Redis configuration
3333
REDIS_URL string
3434
REDIS_PASSWORD string
35-
REDIS_DB string
35+
REDIS_DB int
3636
}
3737

3838
func (ev *EnvironmentVariable) LoadFromEnv() {
@@ -43,7 +43,7 @@ func (ev *EnvironmentVariable) LoadFromEnv() {
4343
envKey := field.Name
4444
envValue := os.Getenv(envKey)
4545
if envValue == "" {
46-
fmt.Printf("Missing SYSENV: %s\n", envKey)
46+
logger.GetLogger().Warnf("Missing SYSENV: %s", envKey)
4747
}
4848
if envValue != "" {
4949
switch v.Field(i).Kind() {
@@ -52,14 +52,14 @@ func (ev *EnvironmentVariable) LoadFromEnv() {
5252
case reflect.Int:
5353
intV, err := strconv.Atoi(envValue)
5454
if err != nil {
55-
fmt.Printf("Invalid int value for %s: %s\n", envKey, envValue)
55+
logger.GetLogger().Errorf("Invalid int value for %s: %s", envKey, envValue)
5656
} else {
5757
v.Field(i).SetInt(int64(intV))
5858
}
5959
case reflect.Bool:
6060
boolVal, err := strconv.ParseBool(envValue)
6161
if err != nil {
62-
fmt.Printf("Invalid boolean value for %s: %s\n", envKey, envValue)
62+
logger.GetLogger().Errorf("Invalid boolean value for %s: %s", envKey, envValue)
6363
} else {
6464
v.Field(i).SetBool(boolVal)
6565
}
@@ -70,10 +70,10 @@ func (ev *EnvironmentVariable) LoadFromEnv() {
7070
hosts := strings.Split(envValue, ",")
7171
v.Field(i).Set(reflect.ValueOf(hosts))
7272
} else {
73-
fmt.Printf("Unsupported slice type for %s\n", field.Name)
73+
logger.GetLogger().Errorf("Unsupported slice type for %s", field.Name)
7474
}
7575
default:
76-
fmt.Printf("Unsupported field type: %s\n", field.Name)
76+
logger.GetLogger().Errorf("Unsupported field type: %s", field.Name)
7777
}
7878
}
7979
}

0 commit comments

Comments
 (0)