diff --git a/web-service-gin/main.go b/web-service-gin/main.go index 2c16187d0f66b37a8f9fa1e431c63aea748e2123..861748b9384ee1a799d11a414ecae4252b304ef1 100644 --- a/web-service-gin/main.go +++ b/web-service-gin/main.go @@ -42,6 +42,15 @@ func initReq(c *gin.Context) { msgId = rand.Intn(100) parent = -1 printErr(err) + for _, x := range arrFile { + if x == c.Param("ressource") { + if !foundRsc { + fmt.Println("Ressource exist in Client") + } + foundRsc = true + break + } + } for i := 0; i < len(albums); i++ { if albums[i].ID == idServ { for j := 0; j < len(albums[i].Neighb); j++ { @@ -70,7 +79,7 @@ func receiveReq(c *gin.Context) { for _, x := range arrFile { if x == c.Param("ressource") { if !foundRsc { - go sendFound(c.Param("ressource")) + go sendFound(c.Param("ressource"), idServ) } foundRsc = true break @@ -97,13 +106,18 @@ func receiveReq(c *gin.Context) { //Called by child when ressource is find func foundReq(c *gin.Context) { + finderNb, err := strconv.Atoi(c.Param("finder")) + printErr(err) + portFinder := strconv.Itoa(basePort + finderNb) if parent == -1 { - fmt.Println("Ressource found ") + fmt.Println("Instance of " + c.Param("ressource") + " found in " + portFinder) + } else { + sendFound(c.Param("ressource"), c.Param("finder")) } } -func sendFound(ressource string) { - resp, err := http.Get("http://localhost:" + strconv.Itoa(basePort+parent) + "/foundReq/" + idServ + "/" + ressource) +func sendFound(ressource string, finder string) { + resp, err := http.Get("http://localhost:" + strconv.Itoa(basePort+parent) + "/foundReq/" + finder + "/" + ressource) printErr(err) fmt.Println(resp.Status) }