用量封顶接口
更新时间:2026-10-27
设置用量封顶配置
Go
1cli := GetDefaultClient()
2resp, err := cli.SetLimitConsumption(&api.LimitConsumption{
3 Site: "your_site.com",
4 Object: "site", // "site" 表示整站;设置某个域名则填具体域名,如 "1.your_site.com"
5 Enabled: true,
6 Type: "flow", // flow 流量 / bandwidth 带宽 / pv 请求数
7 Threshold: "100GB",
8 StatisticalCycle: 300, // 单位秒,合法值 300 / 3600 / 86400;Type 为 bandwidth 时固定 300
9 Action: "stop",
10})
11result, _ := json.Marshal(resp)
12fmt.Printf("result: %s\n", result)
13fmt.Printf("err:%+v\n", err)
关闭用量封顶时各字段仍需传全,Enabled 置为 false:
Go
1cli := GetDefaultClient()
2resp, err := cli.SetLimitConsumption(&api.LimitConsumption{
3 Site: "your_site.com",
4 Object: "site",
5 Enabled: false,
6 Type: "flow",
7 Threshold: "100GB",
8 StatisticalCycle: 300,
9 Action: "stop",
10})
11result, _ := json.Marshal(resp)
12fmt.Printf("result: %s\n", result)
13fmt.Printf("err:%+v\n", err)
api.LimitConsumption 字段说明:
| 字段 | 类型 | 是否必选 | 说明 |
|---|---|---|---|
| Site | String | 是 | 站点名称。 |
| Object | String | 是 | 生效对象。site 表示整站;其他值为站点下的域名。 |
| Enabled | Bool | 是 | 开启/关闭用量封顶。true 开启,false 关闭。 |
| Type | String | 是 | 检测类型。合法值:flow(流量)、bandwidth(带宽)、pv(请求数)。 |
| Threshold | String | 是 | 检测阈值。flow 单位 MB/GB/TB;bandwidth 单位 Mbps/Gbps/Tbps;pv 填数值字符串(如 1234)。 |
| StatisticalCycle | Int | 是 | 检测周期(秒)。合法值 300/3600/86400;Type 为 bandwidth 时固定 300。 |
| Action | String | 是 | 达到阈值触发的动作,固定值 stop(停止加速域名)。 |
查询用量封顶配置
Go
1cli := GetDefaultClient()
2resp, err := cli.GetLimitConsumption(&api.LimitConsumptionQuery{
3 Site: "your_site.com",
4 Object: "", // 可选,仅支持填加速域名作为过滤条件
5 PageNo: 1, // 可选,默认 1
6 PageSize: 20, // 可选,默认 10
7})
8if err != nil {
9 fmt.Printf("err:%+v\n", err)
10 return
11}
12result, _ := json.Marshal(resp)
13fmt.Printf("result: %s\n", result)
api.LimitConsumptionQuery 字段说明:
| 字段 | 类型 | 是否必选 | 说明 |
|---|---|---|---|
| Site | String | 是 | 站点名称。 |
| Object | String | 否 | 生效对象过滤条件,仅支持填加速域名。 |
| PageNo | Int | 否 | 分页编号,默认 1。 |
| PageSize | Int | 否 | 每页返回数目,默认 10。 |
api.LimitConsumptionQueryResult 字段说明:
| 字段 | 类型 | 说明 |
|---|---|---|
| Rules | []api.LimitConsumptionRule | 用量封顶规则列表。 |
| TotalCount | Int | 规则总数,用于分页。 |
| PageNo | Int | 分页编号。 |
| PageSize | Int | 每页返回数目。 |
| AllObjectList | []String | 所有生效对象列表,site 表示站点,其余为域名。 |
api.LimitConsumptionRule 字段说明:
| 字段 | 类型 | 说明 |
|---|---|---|
| Object | String | 生效对象。site 表示整站;其他值为站点下的域名。 |
| Enabled | Bool | 用量封顶是否开启。 |
| Activated | Bool | 是否已触发阈值并执行 Action。true 已触发,false 未触发。 |
| Type | String | 检测类型:flow(流量)、bandwidth(带宽)、pv(请求数)。 |
| Threshold | String | 检测阈值,单位随 Type 变化。 |
| StatisticalCycle | Int | 检测周期(秒)。 |
| Action | String | 达到阈值触发的动作,固定值 stop。 |
删除用量封顶配置
Go
1cli := GetDefaultClient()
2resp, err := cli.DeleteLimitConsumption(&api.LimitConsumptionDelete{
3 Site: "your_site.com",
4 Object: "site", // "site" 表示整站;删除某个域名则填具体域名,如 "1.your_site.com"
5})
6result, _ := json.Marshal(resp)
7fmt.Printf("result: %s\n", result)
8fmt.Printf("err:%+v\n", err)
api.LimitConsumptionDelete 字段说明:
| 字段 | 类型 | 是否必选 | 说明 |
|---|---|---|---|
| Site | String | 是 | 站点名称。 |
| Object | String | 是 | 删除对象。site 表示整站;其他值为站点下的域名。 |
评价此篇文章
