Discovery Nats automate

This commit is contained in:
mr 2024-08-22 15:18:59 +02:00
parent fb555be86c
commit a42b6198cb

View File

@ -33,6 +33,20 @@ type PeerCache struct {
Executions []*PeerExecution
}
func (p *PeerCache) urlFormat(url string) string {
if strings.Contains(url, "localhost") || strings.Contains(url, "127.0.0.1") {
url = strings.ReplaceAll(url, "localhost", utils.PEER.API())
url = strings.ReplaceAll(url, "127.0.0.1", utils.PEER.API())
r := regexp.MustCompile("(:[0-9]+)")
t := r.FindString(url)
if t != "" {
url = strings.Replace(url, t, ":8080", -1)
}
r.ReplaceAllString(url, ":8080")
}
return url
}
func (p *PeerCache) checkPeerStatus(peerID string, caller *tools.HTTPCaller) bool {
api := tools.API{}
access := (&Peer{}).GetAccessor(nil)
@ -51,17 +65,7 @@ func (p *PeerCache) checkPeerStatus(peerID string, caller *tools.HTTPCaller) boo
if meth == "" {
return false
}
url := res.(*Peer).Url + meth
if strings.Contains(url, "localhost") || strings.Contains(url, "127.0.0.1") {
url = strings.ReplaceAll(url, "localhost", utils.PEER.API())
url = strings.ReplaceAll(url, "127.0.0.1", utils.PEER.API())
r := regexp.MustCompile("(:[0-9]+)")
t := r.FindString(url)
if t != "" {
url = strings.Replace(url, t, ":8080", -1)
}
r.ReplaceAllString(url, ":8080")
}
url := p.urlFormat(res.(*Peer).Url + meth)
fmt.Println("checkPeerStatus AFT 4", url)
state := api.CheckRemotePeer(url)
fmt.Println("checkPeerStatus AFT 4", state, tools.DEAD)
@ -78,16 +82,7 @@ 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) {
fmt.Println("LaunchPeerExecution", url, 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", dt.API())
url = strings.ReplaceAll(url, "127.0.0.1", dt.API())
r := regexp.MustCompile("(:[0-9]+)")
t := r.FindString(url)
if t != "" {
url = strings.Replace(url, t, ":8080", -1)
}
r.ReplaceAllString(url, ":8080")
}
url = p.urlFormat(url)
fmt.Println("LaunchPeerExecution AFT", url, dt.API())
var err error
b := []byte{}