feat: implement core backend architecture and project management services for the History API
Build and Release / release (push) Successful in 1m33s
Build and Release / release (push) Successful in 1m33s
This commit is contained in:
+33
-5
@@ -1,10 +1,10 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"history-api/assets"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
@@ -13,15 +13,17 @@ import (
|
||||
func LoadEnv() error {
|
||||
envData, err := assets.GetFileContent("resources/.env")
|
||||
if err != nil {
|
||||
return errors.New("error read .env file")
|
||||
return nil
|
||||
}
|
||||
envMap, err := godotenv.Parse(strings.NewReader(envData))
|
||||
if err != nil {
|
||||
return errors.New("error parsing .env content")
|
||||
return fmt.Errorf("error parsing .env content: %w", err)
|
||||
}
|
||||
|
||||
for key, value := range envMap {
|
||||
os.Setenv(key, value)
|
||||
if os.Getenv(key) == "" {
|
||||
os.Setenv(key, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -41,4 +43,30 @@ func GetConfigWithDefault(config, defaultValue string) string {
|
||||
return defaultValue
|
||||
}
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
func GetIntConfigWithDefault(config string, defaultValue int) int {
|
||||
data := strings.TrimSpace(os.Getenv(config))
|
||||
if data == "" {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
value, err := strconv.Atoi(data)
|
||||
if err != nil {
|
||||
return defaultValue
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func GetBoolConfigWithDefault(config string, defaultValue bool) bool {
|
||||
data := strings.TrimSpace(os.Getenv(config))
|
||||
if data == "" {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
value, err := strconv.ParseBool(data)
|
||||
if err != nil {
|
||||
return defaultValue
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user