-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_product.go
More file actions
32 lines (27 loc) · 777 Bytes
/
Copy pathget_product.go
File metadata and controls
32 lines (27 loc) · 777 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
package sendowl
import (
"fmt"
"golang.org/x/net/context"
)
// GetProductRequest is an API representation of a get product request.
type GetProductRequest struct {
ID ProductID
}
// GetProductResponse is an API representation of a get product response.
type GetProductResponse struct {
Product `json:"product"`
}
// GetProduct uses req to get a product, returning a GetProductResponse and
// non-nil error if there was a problem.
func (c Client) GetProduct(ctx context.Context, req GetProductRequest) (*GetProductResponse, error) {
u := fmt.Sprintf("./products/%s", req.ID)
r, err := c.newRequest("GET", u, nil)
if err != nil {
return nil, err
}
var resp GetProductResponse
if err := c.do(ctx, r, &resp); err != nil {
return nil, err
}
return &resp, nil
}