-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbid_response.go
43 lines (36 loc) · 1.05 KB
/
bid_response.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
package gortb
import (
"errors"
)
// Validation errors for BidResponse
var (
ErrMissingResponseID = errors.New("bid response missing required ID")
ErrMissingSeatBids = errors.New("bid response missing required seat bids")
)
type BidResponse struct {
ID string `json:"id" binding:"required"`
SeatBids []SeatBid `json:"seatbid" binding:"required"`
BidID string `json:"bidid,omitempty"`
Cur string `json:"cur,omitempty" default:"USD"`
CustomData string `json:"customdata,omitempty"`
NBR int `json:"nbr,omitempty"`
Ext interface{} `json:"ext,omitempty"`
}
// Validate performs validation on the BidResponse object according to OpenRTB 2.5 rules
func (br *BidResponse) Validate() error {
// Check required ID field
if br.ID == "" {
return ErrMissingResponseID
}
// Check required SeatBids field
if len(br.SeatBids) == 0 {
return ErrMissingSeatBids
}
// Validate each SeatBid
for _, sb := range br.SeatBids {
if err := sb.Validate(); err != nil {
return err
}
}
return nil
}