(url string, kind entities.Kind, cache camconfig.CacheConfig)
| 248 | } |
| 249 | |
| 250 | func loadRemoteWithCache(url string, kind entities.Kind, cache camconfig.CacheConfig) (map[string]RepoEntry, error) { |
| 251 | if cache.Enabled { |
| 252 | if cached, err := loadFromCache(url, kind, cache); err == nil && cached != nil { |
| 253 | return cached, nil |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | client := fetching.New() |
| 258 | tmp, err := os.CreateTemp("", "cam-repocfg-*.json") |
| 259 | if err != nil { |
| 260 | return nil, err |
| 261 | } |
| 262 | tmpPath := tmp.Name() |
| 263 | tmp.Close() |
| 264 | defer os.Remove(tmpPath) |
| 265 | |
| 266 | if err := client.FetchFile(url, tmpPath); err != nil { |
| 267 | return nil, err |
| 268 | } |
| 269 | |
| 270 | data, err := os.ReadFile(tmpPath) |
| 271 | if err != nil { |
| 272 | return nil, err |
| 273 | } |
| 274 | |
| 275 | repos, err := parseRepoJSON(data) |
| 276 | if err != nil { |
| 277 | return nil, err |
| 278 | } |
| 279 | |
| 280 | if cache.Enabled { |
| 281 | _ = saveToCache(url, kind, cache, data) |
| 282 | } |
| 283 | |
| 284 | return repos, nil |
| 285 | } |
| 286 | |
| 287 | // ---------- disk cache ------------------------------------------------------- |
| 288 |
no test coverage detected