queryStruct sends a query to the Incus server, then converts the response metadata into the specified target struct. The function logs the retrieved data, returns the etag of the response, and handles any errors during this process.
(method string, path string, data any, ETag string, target any)
| 380 | // queryStruct sends a query to the Incus server, then converts the response metadata into the specified target struct. |
| 381 | // The function logs the retrieved data, returns the etag of the response, and handles any errors during this process. |
| 382 | func (r *ProtocolIncus) queryStruct(method string, path string, data any, ETag string, target any) (string, error) { |
| 383 | resp, etag, err := r.query(method, path, data, ETag) |
| 384 | if err != nil { |
| 385 | return "", err |
| 386 | } |
| 387 | |
| 388 | err = resp.MetadataAsStruct(&target) |
| 389 | if err != nil { |
| 390 | return "", err |
| 391 | } |
| 392 | |
| 393 | // Log the data |
| 394 | logger.Debugf("Got response struct from Incus") |
| 395 | logger.Debugf("%s", logger.Pretty(target)) |
| 396 | |
| 397 | return etag, nil |
| 398 | } |
| 399 | |
| 400 | // queryOperation sends a query to the Incus server and then converts the response metadata into an Operation object. |
| 401 | // It sets up an early event listener, performs the query, processes the response, and manages the lifecycle of the event listener. |
no test coverage detected