/
media_types.go
70 lines (64 loc) · 2.32 KB
/
media_types.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
// Code generated by goagen v1.3.0, DO NOT EDIT.
//
// API "pos": Application Media Types
//
// Command:
// $ goagen
// --design=github.com/psavelis/goa-pos-poc/design
// --out=$(GOPATH)src\github.com\psavelis\goa-pos-poc
// --version=v1.3.0
package client
import (
"github.com/goadesign/goa"
"net/http"
"unicode/utf8"
)
// Purchase media type (default view)
//
// Identifier: application/json; view=default
type Purchase struct {
// API href of Purchase
Href string `json:"href"`
// Operation reference code
Locator string `bson:"locator,omitempty" json:"locator"`
// Total amount paid
PurchaseValue float64 `bson:"purchase_value,omitempty" json:"purchase_value"`
// Purchase status
Status string `bson:"status,omitempty" json:"status"`
// Unique transaction identifier
TransactionID string `bson:"_id,omitempty" json:"transaction_id"`
}
// Validate validates the Purchase media type instance.
func (mt *Purchase) Validate() (err error) {
if mt.TransactionID == "" {
err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "transaction_id"))
}
if mt.Locator == "" {
err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "locator"))
}
if mt.Status == "" {
err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "status"))
}
if mt.Href == "" {
err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "href"))
}
if utf8.RuneCountInString(mt.Locator) < 1 {
err = goa.MergeErrors(err, goa.InvalidLengthError(`response.locator`, mt.Locator, utf8.RuneCountInString(mt.Locator), 1, true))
}
if utf8.RuneCountInString(mt.Locator) > 30 {
err = goa.MergeErrors(err, goa.InvalidLengthError(`response.locator`, mt.Locator, utf8.RuneCountInString(mt.Locator), 30, false))
}
if mt.PurchaseValue < 0.010000 {
err = goa.MergeErrors(err, goa.InvalidRangeError(`response.purchase_value`, mt.PurchaseValue, 0.010000, true))
}
if ok := goa.ValidatePattern(`^[0-9a-fA-F]{24}$`, mt.TransactionID); !ok {
err = goa.MergeErrors(err, goa.InvalidPatternError(`response.transaction_id`, mt.TransactionID, `^[0-9a-fA-F]{24}$`))
}
return
}
// DecodePurchase decodes the Purchase instance encoded in resp body.
func (c *Client) DecodePurchase(resp *http.Response) (*Purchase, error) {
var decoded Purchase
err := c.Decoder.Decode(&decoded, resp.Body, resp.Header.Get("Content-Type"))
return &decoded, err
}