generated from dave/wails-template
31 lines
560 B
Go
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
|
|
}
|