(url string, target any)
| 270 | } |
| 271 | |
| 272 | func fetchPocketBase(url string, target any) error { |
| 273 | url, err := validateMetadataURL(url) |
| 274 | if err != nil { |
| 275 | return err |
| 276 | } |
| 277 | |
| 278 | req, err := http.NewRequest(http.MethodGet, url, nil) |
| 279 | if err != nil { |
| 280 | return fmt.Errorf("failed to create request: %w", err) |
| 281 | } |
| 282 | |
| 283 | req.Header.Add("User-Agent", "pvetui") |
| 284 | |
| 285 | client := &http.Client{} |
| 286 | resp, err := client.Do(req) |
| 287 | if err != nil { |
| 288 | return fmt.Errorf("failed to fetch metadata: %w", err) |
| 289 | } |
| 290 | |
| 291 | defer func() { |
| 292 | _ = resp.Body.Close() |
| 293 | }() |
| 294 | |
| 295 | if resp.StatusCode != http.StatusOK { |
| 296 | body, _ := io.ReadAll(resp.Body) |
| 297 | |
| 298 | return fmt.Errorf("metadata API error: %s - %s", resp.Status, string(body)) |
| 299 | } |
| 300 | |
| 301 | if err := json.NewDecoder(resp.Body).Decode(target); err != nil { |
| 302 | return fmt.Errorf("failed to parse metadata response: %w", err) |
| 303 | } |
| 304 | |
| 305 | return nil |
| 306 | } |
| 307 | |
| 308 | // GetScriptCategories returns the available script categories. |
| 309 | func GetScriptCategories() []ScriptCategory { |
no test coverage detected