From 172bafe5e12b6b7d3d983f61aa6f8259949620f9 Mon Sep 17 00:00:00 2001 From: Noah Fontes Date: Fri, 2 Aug 2019 10:52:51 -0700 Subject: [PATCH] Revert "Remove unused StorageMeta, improve efficiency of SupportedSchemes() by using a RLock() not a RW lock." This reverts commit 3af186fed4c93fd4639dc923300a728729a63ac6. Revert "go fmt" This reverts commit fb75d512eff0e7cf2b1a23418c6660acd5d863e7. Revert "Add the storage API." This reverts commit b7fa2805c6b35833876ffbeeb5654d7974f046a3. --- storage/api.go | 72 ---------------------------------------------- storage/factory.go | 49 ------------------------------- 2 files changed, 121 deletions(-) delete mode 100644 storage/api.go delete mode 100644 storage/factory.go diff --git a/storage/api.go b/storage/api.go deleted file mode 100644 index 5974934..0000000 --- a/storage/api.go +++ /dev/null @@ -1,72 +0,0 @@ -package storage - -// Look here for various implementations: -// https://github.com/puppetlabs/nebula-libs/tree/master/storage" -// - -import ( - "context" - "io" -) - -type StorageErrorCode string - -const ( - AuthError StorageErrorCode = "AuthError" - NotFoundError StorageErrorCode = "NotFoundError" - TimeoutError StorageErrorCode = "TimeoutError" - UnknownError StorageErrorCode = "UnknownError" -) - -type StorageError struct { - code StorageErrorCode - msg string - cause error -} - -func (e *StorageError) Error() string { - return e.msg -} - -func (e *StorageError) Code() StorageErrorCode { - return e.code -} - -func (e *StorageError) Cause() error { - return e.cause -} - -func NewStorageError(code StorageErrorCode, msg string, cause error) *StorageError { - return &StorageError{ - code: code, - msg: msg, - cause: cause, - } -} - -type StorageSink func(io.Writer) error -type StorageSrc func(io.Reader) error - -type PutOptions struct { - Context context.Context - Key string - Sink StorageSink - ContentType string -} - -type GetOptions struct { - Context context.Context - Key string - Src StorageSrc -} - -type DeleteOptions struct { - Context context.Context - Key string -} - -type BlobStorage interface { - Put(PutOptions) *StorageError - Get(GetOptions) *StorageError - Delete(DeleteOptions) *StorageError -} diff --git a/storage/factory.go b/storage/factory.go deleted file mode 100644 index 289423f..0000000 --- a/storage/factory.go +++ /dev/null @@ -1,49 +0,0 @@ -package storage - -import ( - "fmt" - "net/url" - "strings" - "sync" -) - -var ( - factoriesMu sync.RWMutex - factories = make(map[string]BlobStorageFactory) -) - -type BlobStorageFactory func(url.URL) (BlobStorage, error) - -func NewBlobStorage(u url.URL) (BlobStorage, error) { - scheme := strings.ToLower(u.Scheme) - factoriesMu.RLock() - factory, ok := factories[scheme] - factoriesMu.RUnlock() - if !ok { - return nil, fmt.Errorf("stroage: unknown scheme %q (forgotten import?)", scheme) - } - return factory(u) -} - -func RegisterFactory(scheme string, factory BlobStorageFactory) { - scheme = strings.ToLower(scheme) - factoriesMu.Lock() - defer factoriesMu.Unlock() - if nil == factory { - panic("storage: RegisterFactory passed a nil factory") - } - if _, dup := factories[scheme]; dup { - panic("storage: RegisterFactory called twice for factory " + scheme) - } - factories[scheme] = factory -} - -func SupportedSchemes() []string { - factoriesMu.RLock() - defer factoriesMu.RUnlock() - var list []string - for scheme := range factories { - list = append(list, scheme) - } - return list -}