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
32280322
Commit
32280322
authored
2 years ago
by
Xavier Perret
Browse files
Options
Downloads
Patches
Plain Diff
added functions
parent
f6b25294
No related branches found
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
+43
-15
43 additions, 15 deletions
app/object-storage/object-storage.go
with
43 additions
and
15 deletions
app/object-storage/object-storage.go
+
43
−
15
View file @
32280322
...
...
@@ -28,6 +28,12 @@ func removeTransactionFromBlobStorage(transaction Transaction, database Database
}
func
fakeTransaction
(
transactionToFake
Transaction
,
fakeTransaction
Transaction
,
database
Database
)
Database
{
for
i
,
trans
:=
range
database
{
if
trans
.
Id
==
transactionToFake
.
Id
{
database
[
i
]
=
fakeTransaction
break
}
}
return
database
}
...
...
@@ -77,17 +83,6 @@ func writeDatabaseToBlobStorage(database Database, blob Blob) {
}
}
// Azure Storage Quickstart Sample - Demonstrate how to upload, list, download, and delete blobs.
//
// Documentation References:
// - What is a Storage Account - https://docs.microsoft.com/azure/storage/common/storage-create-storage-account
// - Blob Service Concepts - https://docs.microsoft.com/rest/api/storageservices/Blob-Service-Concepts
// - Blob Service Go SDK API - https://godoc.org/github.com/Azure/azure-storage-blob-go
// - Blob Service REST API - https://docs.microsoft.com/rest/api/storageservices/Blob-Service-REST-API
// - Scalability and performance targets - https://docs.microsoft.com/azure/storage/common/storage-scalability-targets
// - Azure Storage Performance and Scalability checklist https://docs.microsoft.com/azure/storage/common/storage-performance-checklist
// - Storage Emulator - https://docs.microsoft.com/azure/storage/common/storage-use-emulator
func
randomString
()
string
{
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
return
strconv
.
Itoa
(
r
.
Int
())
...
...
@@ -166,6 +161,18 @@ 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
()
{
ctx
:=
context
.
Background
()
// url := "https://hepiadistributedsystems.blob.core.windows.net/" //replace <StorageAccountName> with your Azure storage account name
...
...
@@ -189,12 +196,33 @@ func TestObjectStorage() {
db
=
addTransactionToBlobStorage
(
t1
,
db
,
objectStorage
)
db
=
addTransactionToBlobStorage
(
t2
,
db
,
objectStorage
)
fmt
.
Printf
(
"Press enter key to delete the blob fils, example container, and exit the application.
\n
"
)
fmt
.
Println
(
"Listing files in container"
)
db1
:=
readDatabaseFromBlobStorage
(
objectStorage
)
PrintingDatabaseToConsole
(
db1
)
fmt
.
Println
(
"Press enter to continue"
)
bufio
.
NewReader
(
os
.
Stdin
)
.
ReadBytes
(
'\n'
)
fmt
.
Println
(
"Going to fake a transaction (replacing the first with a new one)"
)
t3
:=
Transaction
{
Id
:
"0"
,
Sender
:
"0"
,
Receiver
:
"1"
,
Amount
:
"1000000"
,
}
db
=
fakeTransaction
(
t1
,
t3
,
db
)
writeDatabaseToBlobStorage
(
db
,
objectStorage
)
fmt
.
Println
(
"Listing files in container"
)
db2
:=
readDatabaseFromBlobStorage
(
objectStorage
)
PrintingDatabaseToConsole
(
db2
)
fmt
.
Println
(
"Press enter to continue"
)
bufio
.
NewReader
(
os
.
Stdin
)
.
ReadBytes
(
'\n'
)
fmt
.
Println
(
"Press enter key to delete the blob fils, example container, and exit the application."
)
bufio
.
NewReader
(
os
.
Stdin
)
.
ReadBytes
(
'\n'
)
fmt
.
Print
f
(
"Cleaning up.
\n
"
)
fmt
.
Print
ln
(
"Cleaning up."
)
// Delete the blob
fmt
.
Print
f
(
"Deleting the blob "
+
blobName
+
"
\n
"
)
fmt
.
Print
ln
(
"Deleting the blob "
+
blobName
)
_
,
err
:=
objectStorage
.
BlockBlobClient
.
Delete
(
ctx
,
nil
)
if
err
!=
nil
{
...
...
@@ -202,7 +230,7 @@ func TestObjectStorage() {
}
// Delete the container
fmt
.
Print
f
(
"Deleting the blob "
+
objectStorage
.
ContainerName
+
"
\n
"
)
fmt
.
Print
ln
(
"Deleting the blob "
+
objectStorage
.
ContainerName
)
_
,
err
=
objectStorage
.
ContainerClient
.
Delete
(
ctx
,
nil
)
if
err
!=
nil
{
...
...
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