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

added functions

parent f6b25294
No related branches found
No related tags found
1 merge request!2added file to separate client function from the server
......@@ -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("\nListing 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.Printf("Cleaning up.\n")
fmt.Println("Cleaning up.")
// Delete the blob
fmt.Printf("Deleting the blob " + blobName + "\n")
fmt.Println("Deleting the blob " + blobName)
_, err := objectStorage.BlockBlobClient.Delete(ctx, nil)
if err != nil {
......@@ -202,7 +230,7 @@ func TestObjectStorage() {
}
// Delete the container
fmt.Printf("Deleting the blob " + objectStorage.ContainerName + "\n")
fmt.Println("Deleting the blob " + objectStorage.ContainerName)
_, err = objectStorage.ContainerClient.Delete(ctx, nil)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment