github.com/uber/kraken@v0.1.4/lib/backend/client.go (about) 1 // Copyright (c) 2016-2019 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package backend 15 16 import ( 17 "fmt" 18 "io" 19 20 "github.com/uber/kraken/core" 21 ) 22 23 var _factories = make(map[string]ClientFactory) 24 25 // ClientFactory creates backend client given name. 26 type ClientFactory interface { 27 Create(config interface{}, authConfig interface{}) (Client, error) 28 } 29 30 // Register registers new Factory with corresponding backend client name. 31 func Register(name string, factory ClientFactory) { 32 _factories[name] = factory 33 } 34 35 // getFactory returns backend client factory given client name. 36 func getFactory(name string) (ClientFactory, error) { 37 factory, ok := _factories[name] 38 if !ok { 39 return nil, fmt.Errorf("no backend client defined with name %s", name) 40 } 41 return factory, nil 42 } 43 44 // Client defines an interface for accessing blobs on a remote storage backend. 45 // 46 // Implementations of Client must be thread-safe, since they are cached and 47 // used concurrently by Manager. 48 type Client interface { 49 // Stat returns blob info for name. All implementations should return 50 // backenderrors.ErrBlobNotFound when the blob was not found. 51 // 52 // Stat is useful when we need to quickly know if a blob exists (and maybe 53 // some basic information about it), without downloading the entire blob, 54 // which may be very large. 55 Stat(namespace, name string) (*core.BlobInfo, error) 56 57 // Upload uploads src into name. 58 Upload(namespace, name string, src io.Reader) error 59 60 // Download downloads name into dst. All implementations should return 61 // backenderrors.ErrBlobNotFound when the blob was not found. 62 Download(namespace, name string, dst io.Writer) error 63 64 // List lists entries whose names start with prefix. 65 List(prefix string, opts ...ListOption) (*ListResult, error) 66 }