github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/store/blob.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); 2 // you may not use this file except in compliance with the License. 3 // You may obtain a copy of the License at 4 // 5 // https://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, 9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 // See the License for the specific language governing permissions and 11 // limitations under the License. 12 // 13 // Original source: github.com/micro/go-micro/v3/store/blob.go 14 15 package store 16 17 import ( 18 "errors" 19 "io" 20 ) 21 22 var ( 23 // ErrMissingKey is returned when no key is passed to blob store Read / Write 24 ErrMissingKey = errors.New("missing key") 25 ) 26 27 // BlobStore is an interface for reading / writing blobs 28 type BlobStore interface { 29 Read(key string, opts ...BlobOption) (io.Reader, error) 30 Write(key string, blob io.Reader, opts ...BlobOption) error 31 Delete(key string, opts ...BlobOption) error 32 // List returns any keys that match, or an empty list with no error if none matched. 33 List(opts ...BlobListOption) ([]string, error) 34 } 35 36 // BlobOptions contains options to use when interacting with the store 37 type BlobOptions struct { 38 // Namespace to from 39 Namespace string 40 Public bool 41 ContentType string 42 } 43 44 // BlobOption sets one or more BlobOptions 45 type BlobOption func(o *BlobOptions) 46 47 // BlobNamespace sets the Namespace option 48 func BlobNamespace(ns string) BlobOption { 49 return func(o *BlobOptions) { 50 o.Namespace = ns 51 } 52 } 53 54 // BlobNamespace sets the Public option 55 func BlobPublic(p bool) BlobOption { 56 return func(o *BlobOptions) { 57 o.Public = p 58 } 59 } 60 61 // BlobNamespace sets the Public option 62 func BlobContentType(contentType string) BlobOption { 63 return func(o *BlobOptions) { 64 o.ContentType = contentType 65 } 66 } 67 68 type BlobListOptions struct { 69 Namespace string 70 Prefix string 71 } 72 73 type BlobListOption func(o *BlobListOptions) 74 75 func BlobListNamespace(namespace string) BlobListOption { 76 return func(o *BlobListOptions) { 77 o.Namespace = namespace 78 } 79 } 80 81 func BlobListPrefix(prefix string) BlobListOption { 82 return func(o *BlobListOptions) { 83 o.Prefix = prefix 84 } 85 }