Discovery Nats automate
This commit is contained in:
parent
d9b26e3fce
commit
3232cce1b4
@ -31,7 +31,7 @@ func (d *Discovery) GetName() string {
|
|||||||
|
|
||||||
func (d *Discovery) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Discovery) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New()
|
data := New()
|
||||||
data.Init(utils.BOOKING, caller)
|
data.Init(utils.DISCOVERY, caller)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
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) {
|
dt utils.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
|
||||||
url = p.urlFormat(url, dt)
|
|
||||||
var err error
|
var err error
|
||||||
b := []byte{}
|
b := []byte{}
|
||||||
methods := caller.URLS[dt.String()]
|
methods := caller.URLS[dt.String()]
|
||||||
if _, ok := methods[method]; !ok {
|
if _, ok := methods[method]; !ok {
|
||||||
return nil, errors.New("no path found")
|
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) {
|
if !p.checkPeerStatus(peerID, caller) {
|
||||||
return nil, errors.New("peer is not reachable")
|
return nil, errors.New("peer is not reachable")
|
||||||
}
|
}
|
||||||
if method == tools.POST {
|
if method == tools.POST {
|
||||||
b, err = caller.CallPost(url, methods[method], body)
|
b, err = caller.CallPost(url, "", body)
|
||||||
}
|
}
|
||||||
if method == tools.GET {
|
if method == tools.GET {
|
||||||
b, err = caller.CallGet(url, strings.ReplaceAll(methods[method], ":id", dataID))
|
b, err = caller.CallGet(url, "")
|
||||||
}
|
}
|
||||||
if method == tools.DELETE {
|
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{}
|
var m map[string]interface{}
|
||||||
json.Unmarshal(b, &m)
|
json.Unmarshal(b, &m)
|
||||||
|
Loading…
Reference in New Issue
Block a user