/*
loadEnvFile reads `filename` into a map by parsing each line
represented with the `key=val` syntax. Lines starting with `#`
are treated as comments, but if `#` appears after the first character
*/
loadEnvFile reads `filename` into a map by parsing each line
represented with the `key=val` syntax. Lines starting with `#`
are treated as comments, but if `#` appears after the first character
/ * loadEnvFile reads ` filename ` into a map by parsing each line represented with the ` key = val ` syntax . Lines starting with ` # ` are treated as comments but if ` # ` appears after the first character * /
func LoadEnvFile(filename string) (env map[string]string, err error) {
	env = make(map[string]string)
	file, err := os.Open(filename)
	if err != nil {
		return
	}
	defer file.Close()
	s := bufio.NewScanner(file)
	for s.Scan() {
		line := bytes.TrimSpace(s.Bytes())
		if bytes.HasPrefix(line, []byte("#")) {
			continue
		}
		if isKeyVal := envFileLineFormat.Match(line); !isKeyVal {
			continue
		}
		keyVal := bytes.Split(line, []byte("="))
		name, val := keyVal[0], keyVal[1]
		env[string(name)] = string(val)
	}
	return
}
func LoadEnvFile ( filename string ) ( env map [ string ] string , err error ) { env = make ( map [ string ] string ) file , err := os . Open ( filename ) if err != nil { return } defer file . Close ( ) s := bufio . NewScanner ( file ) for s . Scan ( ) { line := bytes . TrimSpace ( s . Bytes ( ) ) if bytes . HasPrefix ( line , [ ] byte ( " " ) ) { continue } if isKeyVal := envFileLineFormat . Match ( line ) ; ! isKeyVal { continue } keyVal := bytes . Split ( line , [ ] byte ( " " ) ) name , val := keyVal [ 0 ] , keyVal [ 1 ] env [ string ( name ) ] = string ( val ) } return }
loadEnvFile reads `filename` into a map by parsing each line
represented with the `key=val` syntax.
loadEnvFile reads ` filename ` into a map by parsing each line represented with the ` key = val ` syntax .