Discovery Nats automate

This commit is contained in:
mr 2024-08-22 16:28:21 +02:00
parent d9b26e3fce
commit 3232cce1b4
2 changed files with 11 additions and 5 deletions

View File

@ -31,7 +31,7 @@ func (d *Discovery) GetName() string {
func (d *Discovery) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New()
data.Init(utils.BOOKING, caller)
data.Init(utils.DISCOVERY, caller)
return data
}

View File

@ -79,24 +79,30 @@ func (p *PeerCache) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
func (p *PeerCache) LaunchPeerExecution(peerID string, isMySelf bool, dataID string, url string,
dt utils.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
url = p.urlFormat(url, dt)
var err error
b := []byte{}
methods := caller.URLS[dt.String()]
if _, ok := methods[method]; !ok {
return nil, errors.New("no path found")
}
meth := methods[method]
if meth == "" {
return nil, errors.New("no path found")
} else {
meth = strings.ReplaceAll(meth, ":id", dataID)
}
url = p.urlFormat(url+meth, dt)
if !p.checkPeerStatus(peerID, caller) {
return nil, errors.New("peer is not reachable")
}
if method == tools.POST {
b, err = caller.CallPost(url, methods[method], body)
b, err = caller.CallPost(url, "", body)
}
if method == tools.GET {
b, err = caller.CallGet(url, strings.ReplaceAll(methods[method], ":id", dataID))
b, err = caller.CallGet(url, "")
}
if method == tools.DELETE {
b, err = caller.CallDelete(url, strings.ReplaceAll(methods[method], ":id", dataID))
b, err = caller.CallDelete(url, "")
}
var m map[string]interface{}
json.Unmarshal(b, &m)