package peer import ( "encoding/json" "cloud.o-forge.io/core/oc-lib/models/utils" "cloud.o-forge.io/core/oc-lib/static" "cloud.o-forge.io/core/oc-lib/tools" "github.com/google/uuid" ) 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"` } func (ao *Peer) IsMySelf() bool { id, _ := static.GetMyLocalJsonPeer() 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) { p.UUID = peerID return (&PeerCache{}).LaunchPeerExecution(peerID, p.IsMySelf(), dataID, url, dt, method, body, caller) } func (ao *Peer) GetID() string { return ao.UUID } func (r *Peer) GenerateID() { r.UUID = uuid.New().String() } func (d *Peer) GetName() string { return d.Name } func (d *Peer) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() data.Init(utils.PEER, caller) return data } func (dma *Peer) Deserialize(j map[string]interface{}) utils.DBObject { b, err := json.Marshal(j) if err != nil { return nil } json.Unmarshal(b, dma) return dma } func (dma *Peer) Serialize() map[string]interface{} { var m map[string]interface{} b, err := json.Marshal(dma) if err != nil { return nil } json.Unmarshal(b, &m) return m }