| 145 | } |
| 146 | |
| 147 | func (c *Config) loadFile(path string, source Source) error { |
| 148 | if path == "" { |
| 149 | return nil |
| 150 | } |
| 151 | |
| 152 | data, err := os.ReadFile(path) |
| 153 | if err != nil { |
| 154 | if os.IsNotExist(err) { |
| 155 | return nil |
| 156 | } |
| 157 | return fmt.Errorf("could not read config %s: %w", path, err) |
| 158 | } |
| 159 | |
| 160 | var file struct { |
| 161 | BaseURL string `json:"base_url"` |
| 162 | } |
| 163 | if err := json.Unmarshal(data, &file); err != nil { |
| 164 | return fmt.Errorf("could not parse config %s: %w", path, err) |
| 165 | } |
| 166 | |
| 167 | if file.BaseURL != "" { |
| 168 | c.BaseURL = file.BaseURL |
| 169 | c.sources["base_url"] = source |
| 170 | } |
| 171 | |
| 172 | return nil |
| 173 | } |
| 174 | |
| 175 | func (c *Config) SourceOf(key string) Source { |
| 176 | if c.sources == nil { |