Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
perso-distributed-systems
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
Show more breadcrumbs
xavier.perret
perso-distributed-systems
Commits
8ea1a529
Commit
8ea1a529
authored
2 years ago
by
Xavier Perret
Browse files
Options
Downloads
Patches
Plain Diff
fixed translate
parent
474a41a7
Branches
Branches containing commit
No related tags found
1 merge request
!2
added file to separate client function from the server
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lab1/app/utilities/utilities.go
+6
-13
6 additions, 13 deletions
lab1/app/utilities/utilities.go
with
6 additions
and
13 deletions
lab1/app/utilities/utilities.go
+
6
−
13
View file @
8ea1a529
...
@@ -97,29 +97,22 @@ func PrintConnection(connection net.Conn, connectionNumber int) {
...
@@ -97,29 +97,22 @@ func PrintConnection(connection net.Conn, connectionNumber int) {
fmt
.
Println
(
"*****************************************"
)
fmt
.
Println
(
"*****************************************"
)
}
}
// TranslateMessageToAckTransaction translates a message to an ack transaction
// the geniuses who made unmarshable take int as float64
func
TranslateMessageToAckTransaction
(
mess
Message
)
AckTransaction
{
func
TranslateMessageToAckTransaction
(
mess
Message
)
AckTransaction
{
var
transactionId
string
var
transactionId
string
var
amountOfCorrectNode
int
var
amountOfCorrectNode
int
var
totalNodes
int
var
totalNode
int
var
err
error
var
body
map
[
string
]
interface
{}
=
mess
.
MessageBody
.
(
map
[
string
]
interface
{})
var
body
map
[
string
]
interface
{}
=
mess
.
MessageBody
.
(
map
[
string
]
interface
{})
transactionId
=
body
[
"id"
]
.
(
string
)
transactionId
=
body
[
"id"
]
.
(
string
)
amountOfCorrectNode
,
err
=
strconv
.
Atoi
(
body
[
"amountOfCorrectNode"
]
.
(
string
))
amountOfCorrectNode
=
int
(
body
[
"amountOfCorrectNode"
]
.
(
float64
))
if
err
!=
nil
{
totalNode
=
int
(
body
[
"totalNodes"
]
.
(
float64
))
fmt
.
Println
(
"Error while converting amountOfCorrectNode to int"
,
err
)
return
AckTransaction
{}
}
totalNodes
,
err
=
strconv
.
Atoi
(
body
[
"totalNodes"
]
.
(
string
))
if
err
!=
nil
{
fmt
.
Println
(
"Error while converting totalNodes to int"
,
err
)
return
AckTransaction
{}
}
return
AckTransaction
{
return
AckTransaction
{
Id
:
transactionId
,
Id
:
transactionId
,
AmountOfCorrectNode
:
amountOfCorrectNode
,
AmountOfCorrectNode
:
amountOfCorrectNode
,
TotalNodes
:
totalNode
s
,
TotalNodes
:
totalNode
,
}
}
}
}
...
...
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