simplify call to peer
This commit is contained in:
@@ -2,6 +2,7 @@ package peer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/static"
|
||||
@@ -11,9 +12,33 @@ import (
|
||||
|
||||
type Peer struct {
|
||||
utils.AbstractObject
|
||||
Url string `json:"url,omitempty" bson:"url,omitempty" validate:"required,base64url"`
|
||||
PublicKey string `json:"public_key,omitempty" bson:"public_key,omitempty"`
|
||||
Services map[string]int `json:"services,omitempty" bson:"services,omitempty"`
|
||||
Url string `json:"url,omitempty" bson:"url,omitempty" validate:"required,base64url"`
|
||||
PublicKey string `json:"public_key,omitempty" bson:"public_key,omitempty"`
|
||||
Services map[string]int `json:"services,omitempty" bson:"services,omitempty"`
|
||||
FailedExecution []PeerExecution `json:"failed_execution,omitempty" bson:"failed_execution,omitempty"`
|
||||
}
|
||||
|
||||
func (ao *Peer) AddExecution(exec PeerExecution) {
|
||||
found := false
|
||||
for _, v := range ao.FailedExecution {
|
||||
if v.Url == exec.Url && v.Method == exec.Method && fmt.Sprint(v.Body) == fmt.Sprint(exec.Body) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
ao.FailedExecution = append(ao.FailedExecution, exec)
|
||||
}
|
||||
}
|
||||
|
||||
func (ao *Peer) RemoveExecution(exec PeerExecution) {
|
||||
new := []PeerExecution{}
|
||||
for i, v := range ao.FailedExecution {
|
||||
if !(v.Url == exec.Url && v.Method == exec.Method && fmt.Sprint(v.Body) == fmt.Sprint(exec.Body)) {
|
||||
new = append(new, ao.FailedExecution[i])
|
||||
}
|
||||
}
|
||||
ao.FailedExecution = new
|
||||
}
|
||||
|
||||
func (ao *Peer) IsMySelf() bool {
|
||||
@@ -21,9 +46,9 @@ func (ao *Peer) IsMySelf() bool {
|
||||
return ao.UUID == id
|
||||
}
|
||||
|
||||
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) {
|
||||
func (p *Peer) LaunchPeerExecution(peerID string, dataID string, dt utils.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
|
||||
p.UUID = peerID
|
||||
return (&PeerCache{}).LaunchPeerExecution(peerID, p.IsMySelf(), dataID, url, dt, method, body, caller)
|
||||
return (&PeerCache{}).LaunchPeerExecution(peerID, dataID, dt, method, body, caller)
|
||||
}
|
||||
|
||||
func (ao *Peer) GetID() string {
|
||||
|
||||
Reference in New Issue
Block a user