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

Added Com,Need TLV working

parent 903e4e64
No related branches found
No related tags found
No related merge requests found
package main package main
import ( import (
"net/http" "fmt"
"github.com/gin-gonic/gin" "io/ioutil"
"fmt" "log"
"os" "net/http"
"os"
"strconv"
"github.com/gin-gonic/gin"
) )
var arrFile []string
var idServ string
var port string
// album represents data about a record album. // album represents data about a record album.
type album struct { type album struct {
ID string `json:"id"` ID string `json:"id"`
Title string `json:"title"` Neighb []int `json:"price"`
Artist string `json:"artist"`
Price float64 `json:"price"`
} }
// albums slice to seed record album data. // albums slice to seed record album data.
var albums = []album{ var albums = []album{
{ID: "1", Title: "Blue Train", Artist: "John Coltrane",Price}, {ID: "1", Neighb: []int{2, 3, 4}},
{ID: "2", Title: "Jeru", Artist: "Gerry Mulligan", Price: 17.99}, {ID: "2", Neighb: []int{1, 5, 6}},
{ID: "3", Title: "Sarah Vaughan and Clifford Brown", Artist: "Sarah Vaughan", Price: 39.99}, {ID: "3", Neighb: []int{1, 6, 7}},
{ID: "4", Neighb: []int{1, 7}},
{ID: "5", Neighb: []int{2, 6}},
{ID: "6", Neighb: []int{2, 3, 5}},
{ID: "7", Neighb: []int{3, 4}},
} }
// getAlbums responds with the list of all albums as JSON. func reqNeighb(c *gin.Context) {
func getAlbums(c *gin.Context) { for i := 0; i < len(albums); i++ {
c.IndentedJSON(http.StatusOK, albums) if albums[i].ID == idServ {
fmt.Println("Test") for j := 0; j < len(albums[i].Neighb); j++ {
resp, err := http.Get("http://localhost:808" + strconv.Itoa(albums[i].Neighb[j]) + "/req/" + idServ + "/" + strconv.Itoa(j))
printErr(err)
fmt.Println(resp.Status)
}
}
}
//c.IndentedJSON(http.StatusOK, albums)
} }
func receiveReq(c *gin.Context) {
fmt.Println(c.Param("parent"))
fmt.Println(c.Param("tlv"))
c.Status(http.StatusOK)
}
func printErr(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() { func main() {
argsWithoutProg := os.Args[1:]
fmt.Println(argsWithoutProg[0])
router := gin.Default()
router.GET("/albums", getAlbums)
router.Run("localhost:8080") idServ = os.Args[1]
nbIdServ, err := strconv.Atoi(idServ)
files, err := ioutil.ReadDir("Storage1/")
printErr(err)
for _, file := range files {
arrFile = append(arrFile, file.Name())
}
port = strconv.Itoa(8080 + nbIdServ)
router := gin.Default()
router.GET("/req", reqNeighb)
router.GET("/req/:parent/:tlv", receiveReq)
fmt.Println(port)
/*
resp, err := http.Get("http://localhost:8080/req")
printErr(err)
body, err := ioutil.ReadAll(resp.Body)
printErr(err)
fmt.Println(body)
*/
router.Run("localhost:" + port)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment