/
registry.go
81 lines (68 loc) · 2.11 KB
/
registry.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
69
70
71
72
73
74
75
76
77
78
79
80
81
package eregistry
import (
"context"
"io"
"google.golang.org/grpc/resolver"
"github.com/gotomicro/ego/server"
)
// Registry register/unregister service
// registry impl should control rpc timeout
type Registry interface {
RegisterService(context.Context, *server.ServiceInfo) error
UnregisterService(context.Context, *server.ServiceInfo) error
ListServices(context.Context, Target) ([]*server.ServiceInfo, error)
WatchServices(context.Context, Target) (chan Endpoints, error)
SyncServices(context.Context, SyncServicesOptions) error
io.Closer
}
const (
// ProtocolGRPC ...
ProtocolGRPC = "grpc"
// ProtocolHTTP ...
ProtocolHTTP = "http"
)
// Target ...
type Target struct {
Protocol string // "http"|"grpc"
Scheme string // "etcd"|"k8s"|"dns"
Endpoint string // "<SVC-NAME>:<PORT>"
Authority string
}
// SyncServicesOptions ...
type SyncServicesOptions struct {
GrpcResolverNowOptions resolver.ResolveNowOptions
}
// GetServiceKey ETCD注册需要使用
// Deprecated: Use *server.ServiceInfo.GetServiceKey()
func GetServiceKey(prefix string, s *server.ServiceInfo) string {
return s.GetServiceKey(prefix)
}
// GetServiceValue ETCD注册需要使用
// Deprecated: Use *server.ServiceInfo.GetServiceValue()
func GetServiceValue(s *server.ServiceInfo) string {
return s.GetServiceValue()
}
//func GetService(s string) *server.ServiceInfo {
// var si server.ServiceInfo
// _ = json.Unmarshal([]byte(s), &si)
// return &si
//}
// Configuration ...
type Configuration struct {
Routes []Route `json:"routes"` // 配置客户端路由策略
Labels map[string]string `json:"labels"` // 配置服务端标签: 分组
}
// Route represents route configuration
type Route struct {
// 路由方法名
Method string `json:"method" toml:"method"`
// 路由权重组, 按比率在各个权重组中分配流量
WeightGroups []WeightGroup `json:"weightGroups" toml:"weightGroups"`
// 路由部署组, 将流量导入部署组
Deployment string `json:"deployment" toml:"deployment"`
}
// WeightGroup ...
type WeightGroup struct {
Group string `json:"group" toml:"group"`
Weight int `json:"weight" toml:"weight"`
}