Download this file
| 1 | package schedule |
| 2 | |
| 3 | import ( |
| 4 | "bufio" |
| 5 | "os" |
| 6 | "strings" |
| 7 | ) |
| 8 | |
| 9 | // readEnvFile parses a KEY=value EnvironmentFile (blank lines and #comments |
| 10 | // ignored). Copied from internal/activator/backend_exec.go's function of the |
| 11 | // same name — importing activator here would be a cycle (activator is a |
| 12 | // consumer of this package's runner), so the ~20-line parser is duplicated |
| 13 | // rather than shared. Keep the two in sync if either changes. |
| 14 | func readEnvFile(path string) (map[string]string, error) { |
| 15 | f, err := os.Open(path) |
| 16 | if err != nil { |
| 17 | return nil, err |
| 18 | } |
| 19 | defer f.Close() |
| 20 | m := map[string]string{} |
| 21 | sc := bufio.NewScanner(f) |
| 22 | for sc.Scan() { |
| 23 | line := strings.TrimSpace(sc.Text()) |
| 24 | if line == "" || strings.HasPrefix(line, "#") { |
| 25 | continue |
| 26 | } |
| 27 | if k, v, ok := strings.Cut(line, "="); ok { |
| 28 | m[strings.TrimSpace(k)] = strings.TrimSpace(v) |
| 29 | } |
| 30 | } |
| 31 | return m, sc.Err() |
| 32 | } |
| 33 | |