Giter VIP home page Giter VIP logo

azure-aws's Introduction

Azure-AWS

Azure-AWS module for use storages. you can use both storage easiler!

Getting Started

Azure와 AWS S3에 접근하기 위한 인증 정보 준비

Prerequisites

AWS S3를 이용하기 위해서는 config 파일과 credentials 파일에 AWS의 IAM에 대한 정보를 저장해 놓아야 함

  • ~/.aws/config

    [default]
    region = ap-northeast-2
    output = json
  • ~/.aws/credentials

    [default]
    aws_access_key_id = BASE64
    aws_secret_access_key = BASE64

Azure를 이용하기 위해서는 config 파일에 SAS token에 대한 정보를 json 형식으로 저장해 놓아야 함

  • $PROJECTPATH/config.json

    {
      "ConnectionString": "URL",
      "SASToken": "URL",
      "BlobServiceSASURL": "URL",
      "FileServiceSASURL": "URL",
      "QueueServiceSASURL": "URL",
      "TableServiceSASURL": "URL"
    }

Usage

Azure와 AWS S3의 사용 예제

Azure

클라이언트 생성
package main

import (
	"mini-contents-hub/azure"
)

clientAZURE := azure.GetClient("./configs/config.json") //Azure의 SAS Token을 저장한 json 파일의 경로
Container 탐색
containers := azure.GetContainers(clientAZURE)

for _, container := range containers {
		println(container) // print container line by line
}
Container 생성
azure.CreateContainer(clientAZURE, "container-name")
Container 삭제
azure.DeleteContainer(clientAZURE, "container-name")
Blob 탐색
blobs := azure.GetBlobs(clientAZURE, "container-name")

for _, blob := range blobs {
		println(blob) // print blob line by line
}
Blob 업로드
azure.UploadBlob(clientAZURE, "container-name", "file-name.txt", []byte("Hello DATA Replaced!"))
Blob 다운로드
data := azure.DownloadBlob(clientAZURE, "container-name", "file-name.txt")
println(string(data))

//실행결과
//Hello DATA Replaced!
Blob 삭제
azure.DeleteBlob(clientAZURE, "container-name", "file-name.txt")
모든 Container와 Blob 출력
package main

import (
	"mini-contents-hub/azure"
)

func main() {
	clientAZURE := azure.GetClient("./configs/config.json")
	for _, container := range containers {
		println(container) // print container line by line
		blobs := azure.GetBlobs(clientAZURE, container)

		for _, blob := range blobs {
			println(blob) // print blob line by line
		}
	}
}

AWS S3

클라이언트 생성
package main

import (
	"mini-contents-hub/aws"
)

clientAWS := aws.GetClient() //AWS client uses ~/.aws/config file. 
Bucket 탐색
buckets := aws.GetBuckets(clientAWS) // Get bucket list as a slice type

for _, bucket := range buckets {
  println(bucket)// print bucket line by line
}
Bucket 생성
aws.CreateBucket(clientAWS, "unique-bucket-name", "ap-northeast-2")
Avaliable regions
const (
	BucketLocationConstraintAfSouth1     BucketLocationConstraint = "af-south-1"
	BucketLocationConstraintApEast1      BucketLocationConstraint = "ap-east-1"
	BucketLocationConstraintApNortheast1 BucketLocationConstraint = "ap-northeast-1"
	BucketLocationConstraintApNortheast2 BucketLocationConstraint = "ap-northeast-2"
	BucketLocationConstraintApNortheast3 BucketLocationConstraint = "ap-northeast-3"
	BucketLocationConstraintApSouth1     BucketLocationConstraint = "ap-south-1"
	BucketLocationConstraintApSoutheast1 BucketLocationConstraint = "ap-southeast-1"
	BucketLocationConstraintApSoutheast2 BucketLocationConstraint = "ap-southeast-2"
	BucketLocationConstraintCaCentral1   BucketLocationConstraint = "ca-central-1"
	BucketLocationConstraintCnNorth1     BucketLocationConstraint = "cn-north-1"
	BucketLocationConstraintCnNorthwest1 BucketLocationConstraint = "cn-northwest-1"
	BucketLocationConstraintEu           BucketLocationConstraint = "EU"
	BucketLocationConstraintEuCentral1   BucketLocationConstraint = "eu-central-1"
	BucketLocationConstraintEuNorth1     BucketLocationConstraint = "eu-north-1"
	BucketLocationConstraintEuSouth1     BucketLocationConstraint = "eu-south-1"
	BucketLocationConstraintEuWest1      BucketLocationConstraint = "eu-west-1"
	BucketLocationConstraintEuWest2      BucketLocationConstraint = "eu-west-2"
	BucketLocationConstraintEuWest3      BucketLocationConstraint = "eu-west-3"
	BucketLocationConstraintMeSouth1     BucketLocationConstraint = "me-south-1"
	BucketLocationConstraintSaEast1      BucketLocationConstraint = "sa-east-1"
	BucketLocationConstraintUsEast2      BucketLocationConstraint = "us-east-2"
	BucketLocationConstraintUsGovEast1   BucketLocationConstraint = "us-gov-east-1"
	BucketLocationConstraintUsGovWest1   BucketLocationConstraint = "us-gov-west-1"
	BucketLocationConstraintUsWest1      BucketLocationConstraint = "us-west-1"
	BucketLocationConstraintUsWest2      BucketLocationConstraint = "us-west-2"
)
Bucket 삭제
aws.DeleteBucket(clientAWS, "unique-bucket-name")
Object 탐색
objects := aws.GetObjects(clientAWS, "unique-bucket-name")
for _, object := range objects { //read object from bucket
  println(object) //print object line by line
}
Object 업로드
aws.UploadObject(clientAWS, "unique-bucket-name", "file-name.txt", []byte("Hello Binary!"))
Object 다운로드
data := aws.DownloadObject(clientAWS, "unique-bucket-name", "file-name.txt")

println(string(data))

//실행결과
//Hello Binary!
Object 삭제
aws.DeleteObject(clientAWS, "unique-bucket-name", "file-name.txt")
Public URL 얻기
publicURL = aws.GetPublicURL(clientAWS, "unique-bucket-name", "file-name.txt")

azure-aws's People

Contributors

janghanbin avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.