type httpClient interface {
Post(url, contentType string, body io.Reader) (*http.Response, error)
}
type cart struct {
httpClient
}
func (c *cart) checkout() string {
// do something before update inventory...
body := strings.NewReader(`{
"id": "line_sticker_001",
"quantity": -1
}`)
res, _ := c.Post("https://line.me/myshop/v1/inventory",
"application/json",
body)
return res.Status
}
func main() {
cli := http.DefaultClient
cart := &cart{cli}
cart.checkout()
}
cart.go