github.com/unionj-cloud/go-doudou@v1.3.8-0.20221011095552-0088008e5b31/toolkit/dotenv/dotenv.go (about) 1 package dotenv 2 3 import ( 4 "github.com/joho/godotenv" 5 "io" 6 "os" 7 "path/filepath" 8 "strings" 9 ) 10 11 func Load(env string) { 12 wd, _ := os.Getwd() 13 _ = godotenv.Load(filepath.Join(wd, ".env."+env+".local")) 14 if "test" != env { 15 _ = godotenv.Load(filepath.Join(wd, ".env.local")) 16 } 17 _ = godotenv.Load(filepath.Join(wd, ".env."+env)) 18 _ = godotenv.Load() // The Original .env 19 } 20 21 func LoadAsMap(reader io.Reader) (map[string]interface{}, error) { 22 envMap, err := godotenv.Parse(reader) 23 if err != nil { 24 return nil, err 25 } 26 result := make(map[string]interface{}) 27 for key, value := range envMap { 28 result[strings.ToLower(strings.ReplaceAll(key, "_", "."))] = value 29 } 30 return result, nil 31 }