generated from dave/wails-template
Add env parsing
This commit is contained in:
30
backend/utils.go
Normal file
30
backend/utils.go
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user