loadLocalFile loads environment variables from a local file if IMGPROXY_ENV_LOCAL_FILE_PATH is set
()
| 35 | |
| 36 | // loadLocalFile loads environment variables from a local file if IMGPROXY_ENV_LOCAL_FILE_PATH is set |
| 37 | func loadLocalFile() error { |
| 38 | var path string |
| 39 | |
| 40 | IMGPROXY_ENV_LOCAL_FILE_PATH.Parse(&path) |
| 41 | |
| 42 | if len(path) == 0 { |
| 43 | return nil |
| 44 | } |
| 45 | |
| 46 | // Read the local environment file |
| 47 | data, err := os.ReadFile(path) |
| 48 | if err != nil { |
| 49 | return fmt.Errorf("can't read local environment file: %w", err) |
| 50 | } |
| 51 | |
| 52 | // If the file is empty, nothing to load |
| 53 | if len(data) == 0 { |
| 54 | return nil |
| 55 | } |
| 56 | |
| 57 | return unmarshalEnv(string(data), "local file") |
| 58 | } |
| 59 | |
| 60 | // unmarshalEnv loads environment variables from a string to process environment |
| 61 | func unmarshalEnv(env, source string) error { |
no test coverage detected