Files
grapher/backend/utils.go
2024-10-15 23:34:46 +02:00

31 lines
560 B
Go

package main
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/joho/godotenv"
)
func LoadEnv(fpath string) (map[string]string, error) {
res := make(map[string]string)
fpath = filepath.Clean(fpath)
log.Printf("Trying to open env file at '%s'", fpath)
file, err := os.Open(fpath)
if err != nil {
return res, fmt.Errorf("error opening env file: %w", err)
}
defer file.Close()
res, err = godotenv.Parse(file)
if err != nil {
return res, fmt.Errorf("error parsing env file: %w", err)
}
return res, nil
}