45 lines
984 B
Go
45 lines
984 B
Go
package main
|
|
|
|
import (
|
|
"github.com/joho/godotenv"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/minio/minio-go/v7"
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
)
|
|
|
|
func main() {
|
|
|
|
accessKeyID, secretAccessKey := getCredentials()
|
|
endpoint := "s3.us-west-002.backblazeb2.com"
|
|
|
|
// Initialize minio client object.
|
|
minioClient, err := minio.New(endpoint, &minio.Options{
|
|
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
|
|
Secure: true,
|
|
})
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
log.Printf("%#v\n", minioClient) // minioClient is now set up
|
|
}
|
|
|
|
func getCredentials() (string, string) {
|
|
// get credentials from env vars
|
|
err := godotenv.Load()
|
|
if err != nil {
|
|
log.Fatalf("error loading .env file: (%s)", err.Error())
|
|
}
|
|
keyName := os.Getenv("KEY_NAME")
|
|
if keyName == "" {
|
|
log.Fatal("missing or empty KEY_NAME")
|
|
}
|
|
applicationKey := os.Getenv("APPLICATION_KEY")
|
|
if applicationKey == "" {
|
|
log.Fatal("missing or empty APPLICATION_KEY")
|
|
}
|
|
return keyName, applicationKey
|
|
}
|