default http behavior on is my self

This commit is contained in:
mr
2024-08-21 08:54:29 +02:00
parent c6ea2195ed
commit e31815f576
5 changed files with 50 additions and 46 deletions

View File

@@ -21,7 +21,8 @@ func (ao *Peer) IsMySelf() bool {
}
func (p *Peer) LaunchPeerExecution(peerID string, dataID string, url string, dt utils.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
return (&PeerCache{}).LaunchPeerExecution(peerID, dataID, url, dt, method, body, caller)
p.UUID = peerID
return (&PeerCache{}).LaunchPeerExecution(peerID, p.IsMySelf(), dataID, url, dt, method, body, caller)
}
func (ao *Peer) GetID() string {

View File

@@ -21,6 +21,7 @@ type PeerExecution struct {
Method tools.METHOD
Url string
Body map[string]interface{}
IsMySelf bool
Caller tools.HTTPCaller
PeerID string
DataType utils.DataType
@@ -41,7 +42,15 @@ func (p *PeerCache) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
return data
}
func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string, url string, dt utils.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
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) {
if strings.Contains(url, "localhost") || strings.Contains(url, "127.0.0.1") {
if isMySelf {
url = "http://" + dt.API() // default behavior on basic API container name
} else {
return nil, errors.New("Peer " + peerID + " is not reachable")
}
}
var err error
b := []byte{}
methods := caller.URLS[dt.String()]
@@ -67,6 +76,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string, url string
Method: method,
Url: url + methods[method],
Body: body,
IsMySelf: isMySelf,
Caller: *caller,
PeerID: peerID,
DataType: dt,
@@ -88,7 +98,8 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string, url string
func (p *PeerCache) retryPeerExecution() {
execs := []*PeerExecution{}
for _, v := range singleton.Executions {
d, err := p.LaunchPeerExecution(v.PeerID, v.DataID, v.Url, v.DataType, v.Method, v.Body, &v.Caller)
d, err := p.LaunchPeerExecution(v.PeerID, v.IsMySelf, v.DataID, v.Url, v.DataType, v.Method, v.Body, &v.Caller)
if err == nil {
execs = append(execs, d)
} else {