Skip to content

Commit f2d5451

Browse files
committed
shared helpers for int based envs
1 parent e7be5bb commit f2d5451

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/shared/pkg/env/env.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package env
22

3-
import "os"
3+
import (
4+
"os"
5+
"strconv"
6+
)
47

58
var environment = GetEnv("ENVIRONMENT", "local")
69

@@ -23,3 +26,16 @@ func GetEnv(key, defaultValue string) string {
2326
}
2427
return value
2528
}
29+
30+
func GetEnvAsInt(key string, defaultValue int) (int, error) {
31+
if v := os.Getenv(key); v != "" {
32+
value, err := strconv.Atoi(v)
33+
if err != nil {
34+
return defaultValue, err
35+
}
36+
37+
return value, nil
38+
}
39+
40+
return defaultValue, nil
41+
}

0 commit comments

Comments
 (0)