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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xavier.perret
perso-distributed-systems
Commits
dd70fdad
Commit
dd70fdad
authored
2 years ago
by
Xavier Perret
Browse files
Options
Downloads
Patches
Plain Diff
updated method name and moved utilities function to proper package
parent
107a6fef
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
app/object-storage/object-storage.go
+13
-18
13 additions, 18 deletions
app/object-storage/object-storage.go
with
13 additions
and
18 deletions
app/object-storage/object-storage.go
+
13
−
18
View file @
dd70fdad
...
@@ -11,12 +11,19 @@ import (
...
@@ -11,12 +11,19 @@ import (
"log"
"log"
"math/rand"
"math/rand"
.
"node/types"
.
"node/types"
.
"node/utilities"
"os"
"os"
"strconv"
"strconv"
"time"
"time"
)
)
func
addTransactionToBlobStorage
(
transaction
Transaction
,
database
Database
,
os
Blob
)
Database
{
// AddTransactionToBlobStorage Add transaction to blob storage if it isn't in the database already and returns the database
func
AddTransactionToBlobStorage
(
transaction
Transaction
,
database
Database
,
os
Blob
)
Database
{
for
_
,
transactionInDatabase
:=
range
database
{
if
transactionInDatabase
.
Id
==
transaction
.
Id
{
return
database
}
}
database
=
append
(
database
,
transaction
)
database
=
append
(
database
,
transaction
)
writeDatabaseToBlobStorage
(
database
,
os
)
writeDatabaseToBlobStorage
(
database
,
os
)
return
database
return
database
...
@@ -33,7 +40,7 @@ func fakeTransaction(transactionToFake Transaction, fakeTransaction Transaction,
...
@@ -33,7 +40,7 @@ func fakeTransaction(transactionToFake Transaction, fakeTransaction Transaction,
return
database
return
database
}
}
func
r
eadDatabaseFromBlobStorage
(
blob
Blob
)
Database
{
func
R
eadDatabaseFromBlobStorage
(
blob
Blob
)
Database
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
// Download the blob
// Download the blob
...
@@ -208,18 +215,6 @@ func ListBlobs(blob Blob) {
...
@@ -208,18 +215,6 @@ func ListBlobs(blob Blob) {
}
}
}
}
func
PrintingDatabaseToConsole
(
database
Database
)
{
for
i
,
trans
:=
range
database
{
fmt
.
Println
(
"--------------------"
)
fmt
.
Printf
(
"
\n
Listing transactions number %d in database
\n
"
,
i
)
fmt
.
Printf
(
"Transaction id: %s
\n
"
,
trans
.
Id
)
fmt
.
Printf
(
"Transaction sender: %s
\n
"
,
trans
.
Sender
)
fmt
.
Printf
(
"Transaction receiver: %s
\n
"
,
trans
.
Receiver
)
fmt
.
Printf
(
"Transaction amount: %s
\n
"
,
trans
.
Amount
)
fmt
.
Println
(
"--------------------"
)
}
}
func
TestObjectStorage
()
{
func
TestObjectStorage
()
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
// url := "https://hepiadistributedsystems.blob.core.windows.net/" //replace <StorageAccountName> with your Azure storage account name
// url := "https://hepiadistributedsystems.blob.core.windows.net/" //replace <StorageAccountName> with your Azure storage account name
...
@@ -240,11 +235,11 @@ func TestObjectStorage() {
...
@@ -240,11 +235,11 @@ func TestObjectStorage() {
Receiver
:
"1"
,
Receiver
:
"1"
,
Amount
:
"1000"
,
Amount
:
"1000"
,
}
}
db
=
a
ddTransactionToBlobStorage
(
t1
,
db
,
objectStorage
)
db
=
A
ddTransactionToBlobStorage
(
t1
,
db
,
objectStorage
)
db
=
a
ddTransactionToBlobStorage
(
t2
,
db
,
objectStorage
)
db
=
A
ddTransactionToBlobStorage
(
t2
,
db
,
objectStorage
)
fmt
.
Println
(
"Listing files in container"
)
fmt
.
Println
(
"Listing files in container"
)
db1
:=
r
eadDatabaseFromBlobStorage
(
objectStorage
)
db1
:=
R
eadDatabaseFromBlobStorage
(
objectStorage
)
PrintingDatabaseToConsole
(
db1
)
PrintingDatabaseToConsole
(
db1
)
fmt
.
Println
(
"Press enter to continue"
)
fmt
.
Println
(
"Press enter to continue"
)
bufio
.
NewReader
(
os
.
Stdin
)
.
ReadBytes
(
'\n'
)
bufio
.
NewReader
(
os
.
Stdin
)
.
ReadBytes
(
'\n'
)
...
@@ -259,7 +254,7 @@ func TestObjectStorage() {
...
@@ -259,7 +254,7 @@ func TestObjectStorage() {
db
=
fakeTransaction
(
t1
,
t3
,
db
)
db
=
fakeTransaction
(
t1
,
t3
,
db
)
writeDatabaseToBlobStorage
(
db
,
objectStorage
)
writeDatabaseToBlobStorage
(
db
,
objectStorage
)
fmt
.
Println
(
"Listing files in container"
)
fmt
.
Println
(
"Listing files in container"
)
db2
:=
r
eadDatabaseFromBlobStorage
(
objectStorage
)
db2
:=
R
eadDatabaseFromBlobStorage
(
objectStorage
)
PrintingDatabaseToConsole
(
db2
)
PrintingDatabaseToConsole
(
db2
)
fmt
.
Println
(
"Press enter to continue"
)
fmt
.
Println
(
"Press enter to continue"
)
bufio
.
NewReader
(
os
.
Stdin
)
.
ReadBytes
(
'\n'
)
bufio
.
NewReader
(
os
.
Stdin
)
.
ReadBytes
(
'\n'
)
...
...
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