github.com/prebid/prebid-server/v2@v2.18.0/openrtb_ext/site.go (about) 1 package openrtb_ext 2 3 import ( 4 "errors" 5 6 "github.com/buger/jsonparser" 7 ) 8 9 // ExtSite defines the contract for bidrequest.site.ext 10 type ExtSite struct { 11 // AMP should be 1 if the request comes from an AMP page, and 0 if not. 12 AMP int8 `json:"amp"` 13 } 14 15 func (es *ExtSite) UnmarshalJSON(b []byte) error { 16 if len(b) == 0 { 17 return errors.New("request.site.ext must have some data in it") 18 } 19 if value, dataType, _, _ := jsonparser.Get(b, "amp"); (dataType != jsonparser.NotExist && dataType != jsonparser.Number) || (len(value) != 1) { 20 return errors.New(`request.site.ext.amp must be either 1, 0, or undefined`) 21 } else { 22 switch value[0] { 23 case byte(48): // 0 24 es.AMP = 0 25 case byte(49): // 1 26 es.AMP = 1 27 default: 28 return errors.New(`request.site.ext.amp must be either 1, 0, or undefined`) 29 } 30 } 31 return nil 32 }