-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathhardware.go
More file actions
38 lines (31 loc) · 813 Bytes
/
hardware.go
File metadata and controls
38 lines (31 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package replicate
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
type Hardware struct {
SKU string `json:"sku"`
Name string `json:"name"`
rawJSON json.RawMessage `json:"-"`
}
func (h *Hardware) RawJSON() json.RawMessage {
return h.rawJSON
}
var _ json.Unmarshaler = (*Hardware)(nil)
func (h *Hardware) UnmarshalJSON(data []byte) error {
h.rawJSON = data
type Alias Hardware
alias := &struct{ *Alias }{Alias: (*Alias)(h)}
return json.Unmarshal(data, alias)
}
// ListHardware returns a list of available hardware.
func (r *Client) ListHardware(ctx context.Context) (*[]Hardware, error) {
response := &[]Hardware{}
err := r.fetch(ctx, http.MethodGet, "/hardware", nil, response)
if err != nil {
return nil, fmt.Errorf("failed to list collections: %w", err)
}
return response, nil
}