| | |
| | | package gopherdiscovery |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "log" |
| | | "time" |
| | | |
| | |
| | | nodes StringSet |
| | | // publisher, we are going to publish the changes of the set here |
| | | publisher *Publisher |
| | | |
| | | svInfo map[string]interface{} |
| | | } |
| | | |
| | | type Publisher struct { |
| | |
| | | var err error |
| | | var msg []byte |
| | | var responses StringSet |
| | | var si ServiceInfo |
| | | |
| | | err = d.sock.Send([]byte("are you ok?")) |
| | | if err != nil { |
| | |
| | | return |
| | | } |
| | | } else { |
| | | responses.Add(string(msg)) |
| | | if json.Unmarshal(msg, &si) == nil { |
| | | responses.Add(si.ServiceId) |
| | | d.services.svInfo[si.ServiceId] = si.Info |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | s := &Services{ |
| | | nodes: NewStringSet(), |
| | | publisher: publisher, |
| | | svInfo: make(map[string]interface{}, 0), |
| | | } |
| | | |
| | | return s |
| | |
| | | return d.services.nodes |
| | | } |
| | | |
| | | func (d *DiscoveryServer) SvInfo() map[string]interface{} { |
| | | m := make(map[string]interface{}) |
| | | for k,v := range d.services.svInfo { |
| | | m[k] = v |
| | | } |
| | | return m |
| | | } |
| | | |
| | | func (d *DiscoveryServer) PublishMsg(msg string) { |
| | | d.services.publisher.Publish([]byte(msg)) |
| | | } |