From 5a532ae192f7357201e10253fa2de3a30833fdae Mon Sep 17 00:00:00 2001 From: mr Date: Fri, 30 Aug 2024 10:35:12 +0200 Subject: [PATCH] oclib latest --- controllers/shared_workspace.go | 59 +++++++++++++++++---------------- go.mod | 2 +- go.sum | 4 +++ main.go | 5 +++ 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/controllers/shared_workspace.go b/controllers/shared_workspace.go index 5225d86..94d7eaa 100644 --- a/controllers/shared_workspace.go +++ b/controllers/shared_workspace.go @@ -36,7 +36,7 @@ func (o *SharedWorkspaceController) Search() { // @router /:id [put] func (o *SharedWorkspaceController) Put() { // store and return Id or post with UUID - var paths = map[string]map[tools.METHOD]string{ + var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers utils.SHARED_WORKSPACE.String(): { tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id", tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/", @@ -56,7 +56,7 @@ func (o *SharedWorkspaceController) Put() { var res map[string]interface{} id := o.Ctx.Input.Param(":id") json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res) - caller := tools.NewHTTPCaller(paths) + caller := tools.NewHTTPCaller(paths) // caller used to send to peers fmt.Println("UPDATE", res) o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, caller) o.ServeJSON() @@ -68,7 +68,7 @@ func (o *SharedWorkspaceController) Put() { // @Success 200 {shared workspace} models.shared_workspace // @router / [post] func (o *SharedWorkspaceController) Post() { - var paths = map[string]map[tools.METHOD]string{ + var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services utils.SHARED_WORKSPACE.String(): { tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id", tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/", @@ -85,7 +85,7 @@ func (o *SharedWorkspaceController) Post() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", }, } - caller := tools.NewHTTPCaller(paths) + caller := tools.NewHTTPCaller(paths) // caller used to send to peers var res map[string]interface{} json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res) @@ -120,7 +120,7 @@ func (o *SharedWorkspaceController) Get() { // @Success 200 {shared workspace} models.shared_workspace // @router /:id/workspace/:id2 [delete] func (o *SharedWorkspaceController) RemoveWorkspace() { - var paths = map[string]map[tools.METHOD]string{ + var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services utils.SHARED_WORKSPACE.String(): { tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id", tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/", @@ -137,13 +137,13 @@ func (o *SharedWorkspaceController) RemoveWorkspace() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", }, } - caller := tools.NewHTTPCaller(paths) + caller := tools.NewHTTPCaller(paths) // caller used to send to peers id := o.Ctx.Input.Param(":id") id2 := o.Ctx.Input.Param(":id2") r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) shared := r.ToSharedWorkspace() newWorkspace := []string{} - if slices.Contains(shared.Workspaces, id) { + if slices.Contains(shared.Workspaces, id2) { for _, w := range shared.Workspaces { if w != id2 { newWorkspace = append(newWorkspace, w) @@ -162,7 +162,7 @@ func (o *SharedWorkspaceController) RemoveWorkspace() { // @Success 200 {shared workspace} models.shared_workspace // @router /:id/workflow/:id2 [delete] func (o *SharedWorkspaceController) RemoveWorkflow() { - var paths = map[string]map[tools.METHOD]string{ + var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services utils.SHARED_WORKSPACE.String(): { tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id", tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/", @@ -179,13 +179,14 @@ func (o *SharedWorkspaceController) RemoveWorkflow() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", }, } - caller := tools.NewHTTPCaller(paths) + caller := tools.NewHTTPCaller(paths) // caller used to send to peers id := o.Ctx.Input.Param(":id") id2 := o.Ctx.Input.Param(":id2") r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) + fmt.Println("RemoveWorkflow", r) shared := r.ToSharedWorkspace() newWorkflows := []string{} - if slices.Contains(shared.Workflows, id) { + if slices.Contains(shared.Workflows, id2) { for _, w := range shared.Workflows { if w != id2 { newWorkflows = append(newWorkflows, w) @@ -204,7 +205,7 @@ func (o *SharedWorkspaceController) RemoveWorkflow() { // @Success 200 {shared workspace} models.shared_workspace // @router /:id/peer/:id2 [delete] func (o *SharedWorkspaceController) RemovePeer() { - var paths = map[string]map[tools.METHOD]string{ + var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services utils.SHARED_WORKSPACE.String(): { tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id", tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/", @@ -221,7 +222,7 @@ func (o *SharedWorkspaceController) RemovePeer() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", }, } - caller := tools.NewHTTPCaller(paths) + caller := tools.NewHTTPCaller(paths) // caller used to send to peers id := o.Ctx.Input.Param(":id") id2 := o.Ctx.Input.Param(":id2") r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) @@ -255,7 +256,7 @@ func (o *SharedWorkspaceController) RemovePeer() { // @Success 200 {shared workspace} models.shared_workspace // @router /:id/rule/:id2 [delete] func (o *SharedWorkspaceController) RemoveRule() { - var paths = map[string]map[tools.METHOD]string{ + var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services utils.SHARED_WORKSPACE.String(): { tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id", tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/", @@ -272,13 +273,13 @@ func (o *SharedWorkspaceController) RemoveRule() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", }, } - caller := tools.NewHTTPCaller(paths) + caller := tools.NewHTTPCaller(paths) // caller used to send to peers id := o.Ctx.Input.Param(":id") id2 := o.Ctx.Input.Param(":id2") r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) shared := r.ToSharedWorkspace() newRules := []string{} - if shared != nil && slices.Contains(shared.Rules, id) { + if shared != nil && slices.Contains(shared.Rules, id2) { for _, rule := range shared.Rules { if rule != id2 { newRules = append(newRules, rule) @@ -297,7 +298,7 @@ func (o *SharedWorkspaceController) RemoveRule() { // @Success 200 {shared workspace} models.shared_workspace // @router /:id/workspace/:id2 [post] func (o *SharedWorkspaceController) AddWorkspace() { - var paths = map[string]map[tools.METHOD]string{ + var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services utils.SHARED_WORKSPACE.String(): { tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id", tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/", @@ -314,7 +315,7 @@ func (o *SharedWorkspaceController) AddWorkspace() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", }, } - caller := tools.NewHTTPCaller(paths) + caller := tools.NewHTTPCaller(paths) // caller used to send to peers id := o.Ctx.Input.Param(":id") id2 := o.Ctx.Input.Param(":id2") r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) @@ -324,7 +325,7 @@ func (o *SharedWorkspaceController) AddWorkspace() { return } shared := r.ToSharedWorkspace() - if shared != nil && !slices.Contains(shared.Workspaces, id) { + if shared != nil && !slices.Contains(shared.Workspaces, id2) { shared.Workspaces = append(shared.Workspaces, id2) } o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller) @@ -338,7 +339,7 @@ func (o *SharedWorkspaceController) AddWorkspace() { // @Success 200 {shared workspace} models.shared_workspace // @router /:id/workflow/:id2 [post] func (o *SharedWorkspaceController) AddWorkflow() { - var paths = map[string]map[tools.METHOD]string{ + var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services utils.SHARED_WORKSPACE.String(): { tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id", tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/", @@ -355,13 +356,13 @@ func (o *SharedWorkspaceController) AddWorkflow() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", }, } - caller := tools.NewHTTPCaller(paths) + caller := tools.NewHTTPCaller(paths) // caller used to send to peers id := o.Ctx.Input.Param(":id") id2 := o.Ctx.Input.Param(":id2") fmt.Println("AddWorkflow", id, id2) r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) shared := r.ToSharedWorkspace() - if shared != nil && !slices.Contains(shared.Workflows, id) { + if shared != nil && !slices.Contains(shared.Workflows, id2) { shared.Workflows = append(shared.Workflows, id2) } fmt.Println("AddWorkflow", shared.Workflows) @@ -377,7 +378,7 @@ func (o *SharedWorkspaceController) AddWorkflow() { // @Success 200 {shared workspace} models.shared_workspace // @router /:id/peer/:id2 [post] func (o *SharedWorkspaceController) AddPeer() { - var paths = map[string]map[tools.METHOD]string{ + var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services utils.SHARED_WORKSPACE.String(): { tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id", tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/", @@ -394,12 +395,12 @@ func (o *SharedWorkspaceController) AddPeer() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", }, } - caller := tools.NewHTTPCaller(paths) + caller := tools.NewHTTPCaller(paths) // caller used to send to peers id := o.Ctx.Input.Param(":id") id2 := o.Ctx.Input.Param(":id2") r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) shared := r.ToSharedWorkspace() - if shared != nil && !slices.Contains(shared.Peers, id) { + if shared != nil && !slices.Contains(shared.Peers, id2) { shared.Peers = append(shared.Peers, id2) } o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller) @@ -413,7 +414,7 @@ func (o *SharedWorkspaceController) AddPeer() { // @Success 200 {shared workspace} models.shared_workspace // @router /:id/rule/:id2 [post] func (o *SharedWorkspaceController) AddRule() { - var paths = map[string]map[tools.METHOD]string{ + var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers utils.SHARED_WORKSPACE.String(): { tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id", tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/", @@ -430,12 +431,12 @@ func (o *SharedWorkspaceController) AddRule() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer", }, } - caller := tools.NewHTTPCaller(paths) + caller := tools.NewHTTPCaller(paths) // caller used to send to peers id := o.Ctx.Input.Param(":id") id2 := o.Ctx.Input.Param(":id2") r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id) shared := r.ToSharedWorkspace() - if shared != nil && !slices.Contains(shared.Rules, id) { + if shared != nil && !slices.Contains(shared.Rules, id2) { shared.Rules = append(shared.Rules, id2) } o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller) @@ -448,7 +449,7 @@ func (o *SharedWorkspaceController) AddRule() { // @Success 200 {shared workspace} delete success! // @router /:id [delete] func (o *SharedWorkspaceController) Delete() { - var paths = map[string]map[tools.METHOD]string{ + var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers utils.SHARED_WORKSPACE.String(): { tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id", tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/", @@ -466,7 +467,7 @@ func (o *SharedWorkspaceController) Delete() { }, } id := o.Ctx.Input.Param(":id") - caller := tools.NewHTTPCaller(paths) + caller := tools.NewHTTPCaller(paths) // caller used to send to peers o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id, caller) o.ServeJSON() } diff --git a/go.mod b/go.mod index 65ddaee..bf34f1e 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( ) require ( - cloud.o-forge.io/core/oc-lib v0.0.0-20240827121739-3c5c065b8d24 // indirect + cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/beego/bee/v2 v2.1.0 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/go.sum b/go.sum index cdeb82d..6808be3 100644 --- a/go.sum +++ b/go.sum @@ -140,6 +140,10 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240827112206-45d53fc9a985 h1:4OzzVFOaI/QR/ cloud.o-forge.io/core/oc-lib v0.0.0-20240827112206-45d53fc9a985/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= cloud.o-forge.io/core/oc-lib v0.0.0-20240827121739-3c5c065b8d24 h1:naqxVtN3ew0eYVir+z2aagL13gCe1MdKv3Dp/sIBLxw= cloud.o-forge.io/core/oc-lib v0.0.0-20240827121739-3c5c065b8d24/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240828114159-ede91cde4583 h1:5DVFZLJ4tySspQwk0H1HRR+arWSRsYsujP4N8zxvy2Q= +cloud.o-forge.io/core/oc-lib v0.0.0-20240828114159-ede91cde4583/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349 h1:bEIY1lCsA78/mJqFE0gV6likAv5ZifH3RMnLJxiSk3o= +cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= diff --git a/main.go b/main.go index a542c9d..6971ad5 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,12 @@ func main() { o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), "", ) + // Init OC with hostname and port for discovery purpose oclib.Init("oc-shared", o.GetStringDefault("HOSTNAME", "localhost"), o.GetStringDefault("PORT", "8091")) + /* PATHS ARE REFERENCE FOR INNER SERVICE OF DISTANT OC + * PATHS ARE USED TO CALL OTHER OC SERVICES + * NAMES ARE CANONICAL NAMES OF THE SERVICES + */ oclib.AddPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), o.GetStringDefault("SHARED_WORKSPACE_URL", ":8091")) oclib.AddPath(oclib.LibDataEnum(oclib.WORKSPACE), o.GetStringDefault("WORKSPACE_URL", ":8089")) oclib.AddPath(oclib.LibDataEnum(oclib.WORKFLOW), o.GetStringDefault("WORKFLOW_URL", ":8088"))