/
get_product_list.go
78 lines (67 loc) · 2 KB
/
get_product_list.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2020 go-myjvn authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
package myjvn
import (
"context"
"encoding/xml"
)
// PLProduct stores the data from API response.
type PLProduct struct {
Text string `xml:",chardata"`
PName string `xml:"pname,attr"`
CPE string `xml:"cpe,attr"`
PID string `xml:"pid,attr"`
}
// PLVendor stores the data from API response.
type PLVendor struct {
Text string `xml:",chardata"`
VName string `xml:"vname,attr"`
CPE string `xml:"cpe,attr"`
VID string `xml:"vid,attr"`
Products []*PLProduct `xml:"Product"`
}
// PLVendorInfo stores the data from API response.
type PLVendorInfo struct {
Text string `xml:",chardata"`
Lang string `xml:"lang,attr"`
Vendors []*PLVendor `xml:"Vendor"`
}
// ProductList stores the data from API response.
type ProductList struct {
XMLName xml.Name `xml:"Result"`
Text string `xml:",chardata"`
Version string `xml:"version,attr"`
XSI string `xml:"xsi,attr"`
XMLNS string `xml:"xmlns,attr"`
MJRes string `xml:"mjres,attr"`
AttrStatus string `xml:"status,attr"`
SchemaLocation string `xml:"schemaLocation,attr"`
VendorInfo PLVendorInfo `xml:"VendorInfo"`
Status Status `xml:"Status"`
}
// GetProductList downloads a product list.
// See: https://jvndb.jvn.jp/apis/getProductList_api_hnd.html
func (c *Client) GetProductList(ctx context.Context, opts ...Option) (*ProductList, error) {
p := ¶meter{
Method: "getProductList",
Feed: "hnd",
}
for _, opt := range opts {
opt(p)
}
u, err := addOptions(defaultAPIPath, p)
if err != nil {
return nil, err
}
req, err := c.newRequest("GET", u)
if err != nil {
return nil, err
}
productList := new(ProductList)
err = c.do(ctx, req, nil, productList)
if err != nil {
return nil, err
}
return productList, nil
}