This commit is contained in:
2026-03-23 18:55:27 +07:00
parent 6dc0322fe5
commit 3626c12319
47 changed files with 2741 additions and 0 deletions

36
pkg/config/config.go Normal file
View File

@@ -0,0 +1,36 @@
package config
import (
"errors"
"fmt"
"history-api/assets"
"os"
"strings"
"github.com/joho/godotenv"
)
func LoadEnv() error {
envData, err := assets.GetFileContent("resources/.env")
if err != nil {
return errors.New("error read .env file")
}
envMap, err := godotenv.Parse(strings.NewReader(envData))
if err != nil {
return errors.New("error parsing .env content")
}
for key, value := range envMap {
os.Setenv(key, value)
}
return nil
}
func GetConfig(config string) (string, error) {
var data string = os.Getenv(config)
if data == "" {
return "", fmt.Errorf("config (%s) dose not exit", config)
}
return data, nil
}