配置插件
experimental:plugins:request-mark:moduleName: github.com/qxsugar/request-markversion: v0.0.1
配置中间件
middlewares:request-mark:plugin:request-mark:serviceName: apilogLevel: DEBUGredisAddr: redis.comredisPassword: "***"redisRulesKey: "abc"redisRuleMaxLen: 256redisLoadInterval: 15redisEnable: falsemarkKey: X-MARKheaderVersion: versionheaderIdentify: identifycookieIdentify: identify-cookiequery_identify: identify-queryrules:- serviceName: apiname: nameenable: truepriority: 100type: identifymarkvalue: betamaxVersion: 3.3.3minVersion: 2.2.2userIds:- A001- A002weight: 10path: alpha
使用中间件
routers:api1:rule: host(`api.test.cn`)service: svcentryPoints:- webmiddlewares:- request-markservices:svc:loadBalancer:servers:- url: "http://localhost:8999"
type Rule struct {ServiceName string `json:"service_name"` // 规则对应的服务名字,例:apiName string `json:"name"` // 规则名字,例:api灰度Enable bool `json:"enable"` // 规则开关,例:1,取值:【0,1】Priority int `json:"priority"` // 规则优先级,例:100Type RuleType `json:"type"` // 规则类型,例:path,取值:【version, identify, weight, path】MarkValue string `json:"mark_value"` // 规则标记值*,例:*alphaVersion string `json:"version"` // 版本,例:1.1.1-2.2.2UserIds string `json:"user_ids"` // 用户id列表, 例:uid01,uid02Weight int `json:"weight"` // 权重,例:30Path string `json:"path"`}
请求符合规则,将会带上mark信息。