Structured NATS

This commit is contained in:
mr
2026-01-28 15:49:21 +01:00
parent 1c9d7b63c0
commit e3fe49c239
2 changed files with 18 additions and 14 deletions

View File

@@ -61,10 +61,8 @@ func (s State) String() string {
type API struct{}
func (a *API) Discovered(infos []*beego.ControllerInfo) {
respondToDiscovery := func(m map[string]string) {
if len(m) == 0 {
a.SubscribeRouter(infos)
}
respondToDiscovery := func(m NATSResponse) {
a.SubscribeRouter(infos)
}
a.ListenRouter(respondToDiscovery)
a.SubscribeRouter(infos)
@@ -91,8 +89,8 @@ func (a *API) GetState() (State, int, error) {
return ALIVE, 200, nil // If everything is up, return alive
}
func (a *API) ListenRouter(exec func(msg map[string]string)) {
go NewNATSCaller().ListenNats(map[NATSMethod]func(msg map[string]string){
func (a *API) ListenRouter(exec func(msg NATSResponse)) {
go NewNATSCaller().ListenNats(map[NATSMethod]func(msg NATSResponse){
DISCOVERY: exec,
})
}
@@ -113,7 +111,14 @@ func (a *API) SubscribeRouter(infos []*beego.ControllerInfo) {
}
}
}
go nats.SetNATSPub(DISCOVERY, discovery)
b, _ := json.Marshal(discovery)
go nats.SetNATSPub(DISCOVERY, NATSResponse{
FromApp: beego.AppPath,
Datatype: -1,
Method: int(DISCOVERY),
Payload: b,
})
}
// CheckRemotePeer checks the state of a remote peer