11package environment_variables
22
33import (
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
3838func (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