Discovery set up
This commit is contained in:
80
controllers/distributed_peer.go
Normal file
80
controllers/distributed_peer.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"oc-peer/infrastructure"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// Operations about workflow
|
||||
type DistributedPeerController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title Search
|
||||
// @Description search workspace
|
||||
// @Param search path string true "the word search you want to get"
|
||||
// @Param is_draft query string false
|
||||
// @Success 200 {workspace} models.workspace
|
||||
// @router /search/:search [get]
|
||||
func (o *DistributedPeerController) Search() {
|
||||
//user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
// store and return Id or post with UUIDLibDataEnum
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
service := infrastructure.GetDHTService()
|
||||
code := 400
|
||||
err := "no DHT Service available"
|
||||
if service != nil {
|
||||
if p, errr := service.DiscoverPeers(context.Background(), search); errr == nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": p,
|
||||
"code": 200,
|
||||
"error": nil,
|
||||
}
|
||||
o.ServeJSON()
|
||||
return
|
||||
} else {
|
||||
err = errr.Error()
|
||||
}
|
||||
}
|
||||
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": []interface{}{},
|
||||
"code": code,
|
||||
"error": err,
|
||||
}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find peer by peerid
|
||||
// @Param id path string true "the peer id you want to get"
|
||||
// @Success 200 {peer} models.peer
|
||||
// @router /:name [get]
|
||||
func (o *DistributedPeerController) Get() {
|
||||
name := o.Ctx.Input.Param(":name")
|
||||
service := infrastructure.GetDHTService()
|
||||
code := 400
|
||||
err := "no DHT Service available"
|
||||
if service != nil {
|
||||
if p, errr := service.GetPeer(context.Background(), name); errr == nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": p,
|
||||
"code": 200,
|
||||
"error": nil,
|
||||
}
|
||||
o.ServeJSON()
|
||||
return
|
||||
} else {
|
||||
err = errr.Error()
|
||||
}
|
||||
}
|
||||
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
"code": code,
|
||||
"error": err,
|
||||
}
|
||||
o.ServeJSON()
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func (o *PeerController) Get() {
|
||||
// @Param id path string true "the peer id you want to partner"
|
||||
// @Success 200 {peer} models.peer
|
||||
// @router /:id/partner [post]
|
||||
func (o *PeerController) Partner() {
|
||||
func (o *PeerController) Nano() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.PEER), user, peerID, groups, nil).UpdateOne(map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user