(id uint64)
| 121 | } |
| 122 | |
| 123 | func updateAPI(id uint64) error { |
| 124 | c, err := getClient() |
| 125 | if err != nil { |
| 126 | return err |
| 127 | } |
| 128 | |
| 129 | api, err := c.GetAPI(id) |
| 130 | if err != nil { |
| 131 | return err |
| 132 | } |
| 133 | |
| 134 | // 下线API |
| 135 | c.NewAPIBuilder().Use(*api).Down().Commit() |
| 136 | // 上线API |
| 137 | c.NewAPIBuilder().Use(*api).UP().Commit() |
| 138 | |
| 139 | // 修改你期望修改的字段 |
| 140 | sb := c.NewAPIBuilder().Use(*api) |
| 141 | // 匹配所有host |
| 142 | sb.MatchDomain("user.xxx.com") |
| 143 | // 增加访问黑名单 |
| 144 | sb.AddBlacklist("192.168.0.1", "192.168.1.*", "192.168.*") |
| 145 | // 增加访问报名单 |
| 146 | sb.AddWhitelist("192.168.3.1", "192.168.3.*", "192.168.*") |
| 147 | // 移除黑白名单 |
| 148 | sb.RemoveBlacklist("192.168.0.1") // 剩余:"192.168.1.*", "192.168.*" |
| 149 | sb.RemoveWhitelist("192.168.3.1") // 剩余:"192.168.3.*", "192.168.*" |
| 150 | |
| 151 | // 增加默认值 |
| 152 | sb.DefaultValue([]byte("{\"value\", \"default\"}")) |
| 153 | // 为默认值增加header |
| 154 | sb.AddDefaultValueHeader("token", "xxxxx") |
| 155 | // 为默认值增加Cookie |
| 156 | sb.AddDefaultValueCookie("sid", "xxxxx") |
| 157 | |
| 158 | // 设置鉴权filter,那么名为jwt的插件就会拦截这个请求,检查并解析jwt的token |
| 159 | sb.AuthPlugin("jwt") |
| 160 | |
| 161 | // 设置这个API访问需要的权限,同时满足perm1和perm2的用户才可以访问这个API,需要配合业务自己的权限插件 |
| 162 | sb.AddPerm("PERM1") |
| 163 | sb.AddPerm("PERM2") |
| 164 | |
| 165 | // 给分发到cluster 1 的节点增加校验 |
| 166 | // 必须包含name的query string param,并且必须是字母 |
| 167 | param := metapb.Parameter{ |
| 168 | Name: "name", |
| 169 | Source: metapb.QueryString, |
| 170 | } |
| 171 | sb.AddDispatchNodeValidation(1, param, "[a-zA-Z]+", true) |
| 172 | |
| 173 | // 必须json body的json必须包含name属性,并且必须是字母 |
| 174 | // 可以是级联属性,必须 user.name,那么就表示json body的json中必须包含 {"user": {"name": "xxxx"}} |
| 175 | param = metapb.Parameter{ |
| 176 | Name: "name", |
| 177 | Source: metapb.JSONBody, |
| 178 | } |
| 179 | sb.AddDispatchNodeValidation(1, param, "[a-zA-Z]+", true) |
| 180 |
nothing calls this directly
no test coverage detected