fix: add getList with records wrapper + correct options format from browser capture
This commit is contained in:
@@ -44,6 +44,23 @@ func (c *client) getWithQuery(ctx context.Context, path string, query map[string
|
||||
return c.do(ctx, "GET", path, nil, result, query)
|
||||
}
|
||||
|
||||
// getList sends a GET request to a Rainyun list endpoint and extracts the "records" field.
|
||||
func (c *client) getList(ctx context.Context, path string, result any) error {
|
||||
var wrapper listResponse
|
||||
if err := c.do(ctx, "GET", path, nil, &wrapper, listOptions()); err != nil {
|
||||
return err
|
||||
}
|
||||
// Unmarshal the records array into the result
|
||||
recordsJSON, err := json.Marshal(wrapper.Records)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal records: %w", err)
|
||||
}
|
||||
if err := json.Unmarshal(recordsJSON, result); err != nil {
|
||||
return fmt.Errorf("unmarshal records: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *client) post(ctx context.Context, path string, body, result any) error {
|
||||
return c.do(ctx, "POST", path, body, result, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user