Skip to content
Snippets Groups Projects
Commit 75d9ca6d authored by ivan.rigo's avatar ivan.rigo
Browse files

Final Push

parent 019c7717
No related branches found
No related tags found
No related merge requests found
package main package main
/*Programme ayant pour but d'implémenter Gnutella en GO et utilisant REST pour communiquer
Réalisé par : Ivan Rigo et John Jenni
*/
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
...@@ -33,17 +37,20 @@ var err error ...@@ -33,17 +37,20 @@ var err error
var assignTransM sync.Mutex var assignTransM sync.Mutex
var endResult string var endResult string
// Required Full route to communicate
func getRequest(urlTxt string) { func getRequest(urlTxt string) {
resp, err := http.Get(urlTxt) resp, err := http.Get(urlTxt)
printErr(err) printErr(err)
fmt.Println(resp.Status) fmt.Println(resp.Status)
} }
// Print the result of the search
func showReq(c *gin.Context) { func showReq(c *gin.Context) {
fmt.Println(endResult) fmt.Println(endResult)
c.IndentedJSON(http.StatusOK, endResult) c.IndentedJSON(http.StatusOK, endResult)
} }
// Start the search
func initReq(c *gin.Context) { func initReq(c *gin.Context) {
msgId = rand.Intn(100) + data.ID msgId = rand.Intn(100) + data.ID
transmitter = -1 transmitter = -1
...@@ -65,6 +72,7 @@ func receiveReq(c *gin.Context) { ...@@ -65,6 +72,7 @@ func receiveReq(c *gin.Context) {
msgIdInt, err := strconv.Atoi(c.Param("msgId")) msgIdInt, err := strconv.Atoi(c.Param("msgId"))
printErr(err) printErr(err)
// msgID aloow to recognize first call of new search
assignTransM.Lock() assignTransM.Lock()
if msgId != msgIdInt { if msgId != msgIdInt {
msgId = msgIdInt msgId = msgIdInt
...@@ -100,7 +108,7 @@ func receiveReq(c *gin.Context) { ...@@ -100,7 +108,7 @@ func receiveReq(c *gin.Context) {
c.Status(http.StatusOK) c.Status(http.StatusOK)
} }
//Called by child when ressource is find //Called by child when ressource is found
func foundReq(c *gin.Context) { func foundReq(c *gin.Context) {
if transmitter == -1 { if transmitter == -1 {
if endResult == "" { if endResult == "" {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment