Skip to content
Snippets Groups Projects
Commit 24045816 authored by Xavier Perret's avatar Xavier Perret
Browse files

added function to upload files

parent 94a52f98
No related branches found
No related tags found
1 merge request!2added file to separate client function from the server
...@@ -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 false return database
} }
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("\nhello 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:")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment