GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - chartmuseum/storage: Go library providing common interface for working across multiple cloud storage backends

BranchesTags
Open more actions menu

Latest commit

 

History

187 Commits
187 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
alibaba.go
alibaba.go
 
 
alibaba_test.go
alibaba_test.go
 
 
amazon.go
amazon.go
 
 
amazon_test.go
amazon_test.go
 
 
baidu.go
baidu.go
 
 
baidu_test.go
baidu_test.go
 
 
etcd.go
etcd.go
 
 
etcd_test.go
etcd_test.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
google.go
google.go
 
 
google_test.go
google_test.go
 
 
local.go
local.go
 
 
local_test.go
local_test.go
 
 
microsoft.go
microsoft.go
 
 
microsoft_test.go
microsoft_test.go
 
 
openstack.go
openstack.go
 
 
openstack_test.go
openstack_test.go
 
 
oracle.go
oracle.go
 
 
oracle_test.go
oracle_test.go
 
 
storage.go
storage.go
 
 
storage_test.go
storage_test.go
 
 
tencent.go
tencent.go
 
 
tencent_test.go
tencent_test.go
 
 

Repository files navigation

chartmuseum/storage

GitHub Actions status Go Report Card GoDoc

Go library providing a common interface for working across multiple storage backends.

Supported storage backends:

  • Alibaba Cloud OSS Storage (alibaba.go)
  • Amazon S3 (amazon.go)
  • Baidu Cloud BOS Storage (baidu.go)
  • DigitalOcean Spaces (amazon.go, using custom endpoint and us-east-1)
  • etcd (etcd.go)
  • Google Cloud Storage (google.go)
  • Local filesystem (local.go)
  • Microsoft Azure Blob Storage (microsoft.go)
  • Minio (amazon.go, using custom endpoint and us-east-1)
  • Netease Cloud NOS Storage (netease.go)
  • Openstack Object Storage (openstack.go)
  • Oracle Cloud Infrastructure Object Storage (oracle.go)
  • Tencent Cloud Object Storage (tencent.go)

This code was originally part of the Helm project: ChartMuseum, but has since been released as a standalone package for others to use in their own projects.

Primary Components

Backend (interface)

Backend is a common interface that is implemented by all the supported storage backends and their associated types:

type Backend interface {
    ListObjects(prefix string) ([]Object, error)
    GetObject(path string) (Object, error)
    PutObject(path string, content []byte) error
    DeleteObject(path string) error
}

Object (struct)

Object is a struct that represents a single storage object:

type Object struct {
    Path         string
    Content      []byte
    LastModified time.Time
}

ObjectSliceDiff (struct)

ObjectSliceDiff is a struct that represents overall changes between two Object slices:

type ObjectSliceDiff struct {
    Change  bool
    Removed []Object
    Added   []Object
    Updated []Object
}

GetObjectSliceDiff (function)

GetObjectSliceDiff is a function that takes two Object slices, compares them, and returns an ObjectSliceDiff:

func GetObjectSliceDiff(prev []Object, curr []Object, timestampTolerance time.Duration) ObjectSliceDiff

Usage

Simple example

The following is a simple program that will upload a file either to an Azure Blob Storage bucket (container) or a Google Cloud Storage bucket based on the command line options provided:

// Usage: go run example.go <cloud> <bucket> <file>

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"

	"github.com/chartmuseum/storage"
)

type (
	Uploader struct {
		Backend storage.Backend
	}
)

func NewUploader(cloud string, bucket string) *Uploader {
	var backend storage.Backend
	switch cloud {
	case "azure":
		backend = storage.NewMicrosoftBlobBackend(bucket, "")
	case "google":
		backend = storage.NewGoogleCSBackend(bucket, "")
	default:
		panic("cloud provider " + cloud + " not supported")
	}
	uploader := Uploader{Backend: backend}
	fmt.Printf("uploader created (cloud: %s, bucket: %s)\n", cloud, bucket)
	return &uploader
}

func (uploader *Uploader) Upload(filename string) {
	basename := filepath.Base(filename)
	content, err := ioutil.ReadFile(filename)
	if err != nil {
		panic(err)
	}
	err = uploader.Backend.PutObject(basename, content)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%s successfully uploaded\n", basename)
}

func main() {
	args := os.Args[1:]
	uploader := NewUploader(args[0], args[1])
	uploader.Upload(args[2])
}

Example of using to upload the file index.html to an Azure bucket:

go run example.go azure mycontainer index.html

Example of using to upload the file index.html to a Google Cloud bucket:

go run example.go google mybucket index.html

Per backend

Each supported storage backend has its own type that implements the Backend interface. All available types are described in detail on GoDoc.

In addition, authentication methods are based on the runtime environment and vary from cloud to cloud.

About

Go library providing common interface for working across multiple cloud storage backends

Topics

alibaba-ossazure-blobchartmuseumcloudgcsgogolangopenstackoracle-clouds3storage

Resources

Readme
Apache-2.0 license
Activity
Custom properties

Stars

231 stars

Watchers

6 watching

Forks

66 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.