Parses a file in the format of /etc/environment. Accepts a path to the file and returns a map of environment variables.
(path string)
| 19 | |
| 20 | // Parses a file in the format of /etc/environment. Accepts a path to the file and returns a map of environment variables. |
| 21 | func ParseEnvironmentFile(path string) (map[string]string, error) { |
| 22 | rtn := make(map[string]string) |
| 23 | file, err := os.Open(path) |
| 24 | if err != nil { |
| 25 | return nil, err |
| 26 | } |
| 27 | defer file.Close() |
| 28 | scanner := bufio.NewScanner(file) |
| 29 | for scanner.Scan() { |
| 30 | line := scanner.Text() |
| 31 | key, val := parseEnvironmentLine(line) |
| 32 | if key == "" { |
| 33 | continue |
| 34 | } |
| 35 | rtn[key] = val |
| 36 | } |
| 37 | return rtn, nil |
| 38 | } |
| 39 | |
| 40 | // Parses a file in the format of /etc/security/pam_env.conf or ~/.pam_environment. Accepts a path to the file and returns a map of environment variables. |
| 41 | func ParseEnvironmentConfFile(path string, opts *PamParseOpts) (map[string]string, error) { |