-
Notifications
You must be signed in to change notification settings - Fork 757
/
Copy pathrouting.go
68 lines (58 loc) · 1.32 KB
/
routing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"github.com/fagongzi/gateway/pkg/pb/metapb"
)
func createRouting() error {
c, err := getClient()
if err != nil {
return err
}
rb := c.NewRoutingBuilder()
// 必选项
// 下线
rb.Down()
// 上线
rb.Up()
// 拆分10%的流量到cluster 2,剩余90%的流量按照原有规则转发
rb.TrafficRate(10)
rb.To(2)
rb.Strategy(metapb.Split)
// 可选项
// 目标请求必须包含 v 的query string,且必须是v1,那么就是把v1的流量导流10%到cluster 2
param := metapb.Parameter{
Name: "v",
Source: metapb.QueryString,
}
rb.AddCondition(param, metapb.CMPEQ, "v1")
_, err = rb.Commit()
return err
}
func updateRouting(id uint64) error {
c, err := getClient()
if err != nil {
return err
}
routing, err := c.GetRouting(id)
if err != nil {
return err
}
rb := c.NewRoutingBuilder().Use(*routing)
// 必选项
// 下线
rb.Down()
// 上线
rb.Up()
// 拆分10%的流量到cluster 2,剩余90%的流量按照原有规则转发
rb.TrafficRate(10)
rb.To(2)
rb.Strategy(metapb.Split)
// 可选项
// 目标请求必须包含 v 的query string,且必须是v1,那么就是把v1的流量导流10%到cluster 2
param := metapb.Parameter{
Name: "v",
Source: metapb.QueryString,
}
rb.AddCondition(param, metapb.CMPEQ, "v1")
_, err = rb.Commit()
return err
}