| 114 | } |
| 115 | |
| 116 | func (o *Loader) loadFile(dst map[string]string, file string) error { |
| 117 | // If a cfg file is set we read the file and copy directly into dst |
| 118 | if file != "" { |
| 119 | return o.readFile(file, dst) |
| 120 | } |
| 121 | |
| 122 | // Otherwise we need to mimic the current behavior of godotenv and |
| 123 | // look for a .env file. |
| 124 | // |
| 125 | // TODO(cstockton): I would prefer to remove the .env loading without some |
| 126 | // explicit devmode / local flag, or a way to disable via an option passed |
| 127 | // from the CLI. |
| 128 | buf := make(map[string]string) |
| 129 | if err := o.readFile(".env", buf); err != nil { |
| 130 | if errors.Is(err, os.ErrNotExist) { |
| 131 | return nil // current behavior is to ignore errors loading .env |
| 132 | } |
| 133 | return err |
| 134 | } |
| 135 | |
| 136 | o.merge(dst, buf, false) |
| 137 | return nil |
| 138 | } |
| 139 | |
| 140 | func (o *Loader) merge(dst, src map[string]string, override bool) { |
| 141 | if override { |