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
24045816
Commit
24045816
authored
2 years ago
by
Xavier Perret
Browse files
Options
Downloads
Patches
Plain Diff
added function to upload files
parent
94a52f98
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
+36
-18
36 additions, 18 deletions
app/object-storage/object-storage.go
with
36 additions
and
18 deletions
app/object-storage/object-storage.go
+
36
−
18
View file @
24045816
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"bufio"
"bufio"
"bytes"
"bytes"
"context"
"context"
"encoding/json"
"fmt"
"fmt"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
...
@@ -15,32 +16,44 @@ import (
...
@@ -15,32 +16,44 @@ import (
"time"
"time"
)
)
func
addTransactionToBlobStorage
(
transaction
Transaction
)
{
func
addTransactionToBlobStorage
(
transaction
Transaction
,
database
Database
,
os
ObjectStorage
)
Database
{
database
=
append
(
database
,
transaction
)
writeDatabaseToBlobStorage
(
database
,
os
)
return
database
}
}
func
removeTransactionFromBlobStorage
(
transaction
Transaction
)
{
func
removeTransactionFromBlobStorage
(
transaction
Transaction
,
database
Database
)
Database
{
return
database
}
}
func
fakeTransaction
(
transactionToFake
Transaction
,
fakeTransaction
Transaction
)
bool
{
func
fakeTransaction
(
transactionToFake
Transaction
,
fakeTransaction
Transaction
,
database
Database
)
Database
{
return
fal
se
return
databa
se
}
}
func
writeDatabaseToFile
(
filepath
string
,
db
Database
)
{
func
writeDatabaseToFile
(
filepath
string
,
db
Database
)
{
}
}
func
readDatabaseFromFile
(
filepath
string
)
Database
{
func
readDatabaseFromFile
(
filepath
string
)
Database
{
return
nil
return
Database
{}
}
}
func
readDatabaseFromBlobStorage
()
Database
{
func
readDatabaseFromBlobStorage
()
Database
{
return
nil
return
Database
{}
}
}
func
writeDatabaseToBlobStorage
()
{
func
writeDatabaseToBlobStorage
(
database
Database
,
os
ObjectStorage
)
{
ctx
:=
context
.
Background
()
fmt
.
Printf
(
"Creating a dummy file to test the upload and download
\n
"
)
data
,
err
:=
json
.
Marshal
(
database
)
// Upload to data to blob storage
_
,
err
=
os
.
BlockBlobClient
.
UploadBufferToBlockBlob
(
ctx
,
data
,
azblob
.
HighLevelUploadToBlockBlobOption
{})
if
err
!=
nil
{
log
.
Fatalf
(
"Failure to upload to blob: %+v"
,
err
)
}
}
}
// Azure Storage Quickstart Sample - Demonstrate how to upload, list, download, and delete blobs.
// Azure Storage Quickstart Sample - Demonstrate how to upload, list, download, and delete blobs.
...
@@ -119,16 +132,21 @@ func TestObjectStorage() {
...
@@ -119,16 +132,21 @@ func TestObjectStorage() {
blobName
:=
"quickstartblob"
+
"-"
+
randomString
()
blobName
:=
"quickstartblob"
+
"-"
+
randomString
()
objectStorage
:=
InitializeObjectStorage
(
blobName
,
azureCreds
)
objectStorage
:=
InitializeObjectStorage
(
blobName
,
azureCreds
)
fmt
.
Printf
(
"Creating a dummy file to test the upload and download
\n
"
)
var
db
Database
t1
:=
Transaction
{
data
:=
[]
byte
(
"
\n
hello world this is a blob
\n
"
)
Id
:
"1"
,
Sender
:
"0"
,
// Upload to data to blob storage
Receiver
:
"1"
,
_
,
err
=
blobClient
.
UploadBufferToBlockBlob
(
ctx
,
data
,
azblob
.
HighLevelUploadToBlockBlobOption
{})
Amount
:
"1000"
,
}
if
err
!=
nil
{
t2
:=
Transaction
{
log
.
Fatalf
(
"Failure to upload to blob: %+v"
,
err
)
Id
:
"2"
,
}
Sender
:
"0"
,
Receiver
:
"1"
,
Amount
:
"1000"
,
}
db
=
addTransactionToBlobStorage
(
t1
,
db
)
db
=
addTransactionToBlobStorage
(
t2
,
db
)
// List the blobs in the container
// List the blobs in the container
fmt
.
Println
(
"Listing the blobs in the container:"
)
fmt
.
Println
(
"Listing the blobs in the container:"
)
...
...
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