Discovery Nats automate

This commit is contained in:
mr 2024-08-22 16:13:07 +02:00
parent d89826db44
commit d9b26e3fce

View File

@ -33,10 +33,10 @@ type PeerCache struct {
Executions []*PeerExecution Executions []*PeerExecution
} }
func (p *PeerCache) urlFormat(url string) string { func (p *PeerCache) urlFormat(url string, dt utils.DataType) string {
if strings.Contains(url, "localhost") || strings.Contains(url, "127.0.0.1") { if strings.Contains(url, "localhost") || strings.Contains(url, "127.0.0.1") {
url = strings.ReplaceAll(url, "localhost", utils.PEER.API()) url = strings.ReplaceAll(url, "localhost", dt.API())
url = strings.ReplaceAll(url, "127.0.0.1", utils.PEER.API()) url = strings.ReplaceAll(url, "127.0.0.1", dt.API())
r := regexp.MustCompile("(:[0-9]+)") r := regexp.MustCompile("(:[0-9]+)")
t := r.FindString(url) t := r.FindString(url)
if t != "" { if t != "" {
@ -65,11 +65,9 @@ func (p *PeerCache) checkPeerStatus(peerID string, caller *tools.HTTPCaller) boo
if meth == "" { if meth == "" {
return false return false
} }
url := p.urlFormat(res.(*Peer).Url + meth) url := p.urlFormat(res.(*Peer).Url+meth, utils.PEER)
fmt.Println("checkPeerStatus AFT 4", url) fmt.Println("checkPeerStatus AFT 4", url)
state := api.CheckRemotePeer(url) state := api.CheckRemotePeer(url)
fmt.Println("checkPeerStatus AFT 4", state, tools.DEAD)
return state != tools.DEAD return state != tools.DEAD
} }
@ -81,13 +79,10 @@ 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) {
fmt.Println("LaunchPeerExecution", url, strings.Contains(url, "localhost") || strings.Contains(url, "127.0.0.1")) url = p.urlFormat(url, dt)
url = p.urlFormat(url)
fmt.Println("LaunchPeerExecution AFT", url, dt.API())
var err error var err error
b := []byte{} b := []byte{}
methods := caller.URLS[dt.String()] methods := caller.URLS[dt.String()]
fmt.Println("LaunchPeerExecution AFT 2", methods)
if _, ok := methods[method]; !ok { if _, ok := methods[method]; !ok {
return nil, errors.New("no path found") return nil, errors.New("no path found")
} }