-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproduct.go
45 lines (37 loc) · 1 KB
/
product.go
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
39
40
41
42
43
44
45
package go_certcentral
import (
"encoding/json"
"io/ioutil"
"net/http"
)
const productURL = "/product"
type Product struct {
GroupName string `json:"group_name,omitempty"`
NameID string `json:"name_id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
ValidationType string `json:"validation_type,omitempty"`
ValidationName string `json:"validation_name,omitempty"`
ValidationDescription string `json:"validation_description,omitempty"`
}
func (c *Client) ListProducts() ([]Product, error) {
req, err := http.NewRequest(http.MethodGet, makeURL(productURL), nil)
if err != nil {
return nil, err
}
res, err := c.do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
resBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
type data struct {
Products []Product `json:"products"`
}
var d data
err = json.Unmarshal(resBody, &d)
return d.Products, err
}