Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SysDistribueTPGnutella
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ivan.rigo
SysDistribueTPGnutella
Commits
a30c4db6
Commit
a30c4db6
authored
2 years ago
by
ivan.rigo
Browse files
Options
Downloads
Patches
Plain Diff
Added Com,Need TLV working
parent
903e4e64
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
web-service-gin/Storage1/Garbage.py
+0
-0
0 additions, 0 deletions
web-service-gin/Storage1/Garbage.py
web-service-gin/Storage1/Important.txt
+0
-0
0 additions, 0 deletions
web-service-gin/Storage1/Important.txt
web-service-gin/main.go
+67
-20
67 additions, 20 deletions
web-service-gin/main.go
with
67 additions
and
20 deletions
web-service-gin/Storage1/Garbage.py
0 → 100644
+
0
−
0
View file @
a30c4db6
This diff is collapsed.
Click to expand it.
web-service-gin/Storage1/Important.txt
0 → 100644
+
0
−
0
View file @
a30c4db6
This diff is collapsed.
Click to expand it.
web-service-gin/main.go
+
67
−
20
View file @
a30c4db6
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
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment