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
94a52f98
Commit
94a52f98
authored
2 years ago
by
Xavier Perret
Browse files
Options
Downloads
Patches
Plain Diff
bim
parent
7ee8289c
Branches
Branches containing commit
No related tags found
1 merge request
!2
added file to separate client function from the server
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/object-storage/object-storage.go
+36
-12
36 additions, 12 deletions
app/object-storage/object-storage.go
app/types/datastructures.go
+17
-0
17 additions, 0 deletions
app/types/datastructures.go
with
53 additions
and
12 deletions
app/object-storage/object-storage.go
+
36
−
12
View file @
94a52f98
...
@@ -63,11 +63,12 @@ func createBlobStorageClient() {
...
@@ -63,11 +63,12 @@ func createBlobStorageClient() {
}
}
func
TestObjectStorage
()
{
func
InitAzureCredentials
(
storageAccountName
string
)
AzureCredentials
{
fmt
.
Printf
(
"Azure Blob storage
quick start sample
\n
"
)
fmt
.
Printf
(
"Azure Blob storage
initialization
\n
"
)
url
:=
"https://hepiadistributedsystems.blob.core.windows.net/"
//replace <StorageAccountName> with your Azure storage account name
//replace <StorageAccountName> with your Azure storage account name
ctx
:=
context
.
Background
()
// hepiadistributedsystems
url
:=
"https://"
+
storageAccountName
+
".blob.core.windows.net/"
// Create a default request pipeline using your storage account name and account key.
// Create a default request pipeline using your storage account name and account key.
credential
,
err
:=
azidentity
.
NewDefaultAzureCredential
(
nil
)
credential
,
err
:=
azidentity
.
NewDefaultAzureCredential
(
nil
)
...
@@ -80,24 +81,47 @@ func TestObjectStorage() {
...
@@ -80,24 +81,47 @@ func TestObjectStorage() {
log
.
Fatal
(
"Invalid credentials with error: "
+
err
.
Error
())
log
.
Fatal
(
"Invalid credentials with error: "
+
err
.
Error
())
}
}
newAzureCredentials
:=
AzureCredentials
{
Url
:
url
,
Credential
:
credential
,
ServiceClient
:
serviceClient
,
}
return
newAzureCredentials
}
func
InitializeObjectStorage
(
baseObjectStorageName
string
,
azureCreds
AzureCredentials
)
ObjectStorage
{
ctx
:=
context
.
Background
()
// Create the container
// Create the container
containerName
:=
fmt
.
Sprintf
(
"quickstart-%s"
,
randomString
())
containerName
:=
fmt
.
Sprintf
(
"quickstart-%s"
,
randomString
())
fmt
.
Printf
(
"Creating a container named %s
\n
"
,
containerName
)
fmt
.
Printf
(
"Creating a container named %s
\n
"
,
containerName
)
containerClient
:=
s
erviceClient
.
NewContainerClient
(
containerName
)
containerClient
:=
azureCreds
.
S
erviceClient
.
NewContainerClient
(
containerName
)
_
,
err
=
containerClient
.
Create
(
ctx
,
nil
)
_
,
err
:
=
containerClient
.
Create
(
ctx
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
fmt
.
Printf
(
"Creating a dummy file to test the upload and download
\n
"
)
blobClient
,
err
:=
azblob
.
NewBlockBlobClient
(
azureCreds
.
Url
+
containerName
+
"/"
+
baseObjectStorageName
,
azureCreds
.
Credential
,
nil
)
data
:=
[]
byte
(
"
\n
hello world this is a blob
\n
"
)
blobName
:=
"quickstartblob"
+
"-"
+
randomString
()
blobClient
,
err
:=
azblob
.
NewBlockBlobClient
(
url
+
containerName
+
"/"
+
blobName
,
credential
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
return
ObjectStorage
{
ContainerName
:
baseObjectStorageName
,
ContainerClient
:
containerClient
,
BlockBlobClient
:
blobClient
,
}
}
func
TestObjectStorage
()
{
// url := "https://hepiadistributedsystems.blob.core.windows.net/" //replace <StorageAccountName> with your Azure storage account name
azureCreds
:=
InitAzureCredentials
(
"hepiadistributedsystems"
)
blobName
:=
"quickstartblob"
+
"-"
+
randomString
()
objectStorage
:=
InitializeObjectStorage
(
blobName
,
azureCreds
)
fmt
.
Printf
(
"Creating a dummy file to test the upload and download
\n
"
)
data
:=
[]
byte
(
"
\n
hello world this is a blob
\n
"
)
// Upload to data to blob storage
// Upload to data to blob storage
_
,
err
=
blobClient
.
UploadBufferToBlockBlob
(
ctx
,
data
,
azblob
.
HighLevelUploadToBlockBlobOption
{})
_
,
err
=
blobClient
.
UploadBufferToBlockBlob
(
ctx
,
data
,
azblob
.
HighLevelUploadToBlockBlobOption
{})
...
...
This diff is collapsed.
Click to expand it.
app/types/datastructures.go
+
17
−
0
View file @
94a52f98
package
types
package
types
import
(
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
// Message - MessageBody can be of any type but will be use here for Transaction, AckTransaction
// Message - MessageBody can be of any type but will be use here for Transaction, AckTransaction
type
Message
struct
{
type
Message
struct
{
MessageType
string
`json:"messageType"`
MessageType
string
`json:"messageType"`
...
@@ -22,3 +27,15 @@ type AckTransaction struct {
...
@@ -22,3 +27,15 @@ type AckTransaction struct {
}
}
type
Database
[]
Transaction
type
Database
[]
Transaction
type
AzureCredentials
struct
{
Url
string
Credential
*
azidentity
.
DefaultAzureCredential
ServiceClient
azblob
.
ServiceClient
}
type
ObjectStorage
struct
{
ContainerName
string
ContainerClient
azblob
.
ContainerClient
BlockBlobClient
azblob
.
BlockBlobClient
}
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