forked from bsm/openrtb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quantity.go
37 lines (31 loc) · 1.05 KB
/
quantity.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
package openrtb
import (
"encoding/json"
"errors"
)
var (
ErrMissingMultiplier = errors.New("openrtb: qty.multiplier is required")
ErrMissingMeasurementVendor = errors.New("openrtb: qty.vendor is required when qty.sourcetype is 1 (Measurement Vendor)")
)
type MeasurementSourceType int
const (
MeasurementSourceTypeUnknown MeasurementSourceType = 0
MeasurementSourceTypeMeasurementVendor MeasurementSourceType = 1
MeasurementSourceTypePublisher MeasurementSourceType = 2
MeasurementSourceTypeExchange MeasurementSourceType = 3
)
type Quantity struct {
Multiplier float64 `json:"multiplier"`
SourceType MeasurementSourceType `json:"sourcetype,omitempty"`
Vendor string `json:"vendor,omitempty"`
Ext *json.RawMessage `json:"ext,omitempty"`
}
func (qty *Quantity) Validate() error {
if qty.Multiplier == 0 {
return ErrMissingMultiplier
}
if qty.SourceType == MeasurementSourceTypeMeasurementVendor && qty.Vendor == "" {
return ErrMissingMeasurementVendor
}
return nil
}