github.com/bububa/oceanengine/marketing-api@v0.0.0-20210315120513-0b953137f7a6/model/report/audience/list_request.go (about) 1 package audience 2 3 import ( 4 "encoding/json" 5 "net/url" 6 "strconv" 7 "time" 8 ) 9 10 type ListRequest struct { 11 AdvertiserID uint64 `json:"advertiser_id,omitempty"` // 广告主ID 12 StartDate time.Time `json:"start_date,omitempty"` // 起始日期,从0时起,格式2020-08-15; 默认15天前,即不指定起止时间获取最近15天数据 13 EndDate time.Time `json:"end_date,omitempty"` // 结束日期,至24时止,格式2020-08-29; 默认昨天,即不指定起止时间获取最近15天数据; 起始时间与结束时间之差小于15天,否则报错并提示"max time span is 15 days" 14 Filtering *Filtering `json:"filtering,omitempty"` // 过滤条件 15 Metrics []string `json:"metrics,omitempty"` // 查询指标列表 16 Page int `json:"page,omitempty"` // 页码;默认值: 1 17 PageSize int `json:"page_size,omitempty"` // 页面大小,即每页展示的数据量,限制为1-100; 默认值: 20 18 } 19 20 func (r ListRequest) Encode() string { 21 values := &url.Values{} 22 values.Set("advertiser_id", strconv.FormatUint(r.AdvertiserID, 10)) 23 if !r.StartDate.IsZero() { 24 values.Set("start_date", r.StartDate.Format("2006-01-02")) 25 } 26 if !r.EndDate.IsZero() { 27 values.Set("end_date", r.EndDate.Format("2006-01-02")) 28 } 29 if r.Filtering != nil { 30 filtering, _ := json.Marshal(r.Filtering) 31 values.Set("filtering", string(filtering)) 32 } 33 if r.Metrics != nil { 34 metrics, _ := json.Marshal(r.Metrics) 35 values.Set("metrics", string(metrics)) 36 } 37 if r.Page > 0 { 38 values.Set("page", strconv.Itoa(r.Page)) 39 } 40 if r.PageSize > 0 { 41 values.Set("page_size", strconv.Itoa(r.PageSize)) 42 } 43 return values.Encode() 44 }