-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistryinfo_svc.go
42 lines (35 loc) · 1.17 KB
/
registryinfo_svc.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
package adaptiveservice
// SrvRegistryInfo : service registryInfo
const SrvRegistryInfo = "registryInfo"
var sharedInfo struct {
registryAddr string
providerID string
}
// reply with string
type reqRegistryInfo struct{}
func (msg *reqRegistryInfo) Handle(stream ContextStream) (reply interface{}) {
return sharedInfo.registryAddr
}
// publishRegistryInfoService declares the registry info service,
// from which user can get registry address.
func (s *Server) publishRegistryInfoService() error {
if len(s.registryAddr) == 0 {
panic("registry address not specified")
}
sharedInfo.registryAddr = s.registryAddr
knownMsgs := []KnownMessage{(*reqRegistryInfo)(nil)}
return s.publish(ScopeProcess|ScopeOS, BuiltinPublisher, SrvRegistryInfo, knownMsgs)
}
func discoverRegistryAddr(lg Logger) (addr string, err error) {
c := NewClient(WithScope(ScopeProcess|ScopeOS), WithLogger(lg)).SetDiscoverTimeout(0)
conn := <-c.Discover(BuiltinPublisher, SrvRegistryInfo)
if conn == nil {
return "", ErrServiceNotFound(BuiltinPublisher, SrvRegistryInfo)
}
defer conn.Close()
err = conn.SendRecv(&reqRegistryInfo{}, &addr)
return
}
func init() {
RegisterType((*reqRegistryInfo)(nil))
}