github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/store/backend.go (about) 1 // Copyright (c) 2019 Intel Corporation 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package store 7 8 import ( 9 "context" 10 "fmt" 11 ) 12 13 type backendType string 14 15 const ( 16 filesystemBackend backendType = "filesystem" 17 ) 18 19 const ( 20 filesystemScheme string = "file" 21 ) 22 23 func schemeToBackendType(scheme string) (backendType, error) { 24 switch scheme { 25 case filesystemScheme: 26 return filesystemBackend, nil 27 } 28 29 return "", fmt.Errorf("Unsupported scheme %s", scheme) 30 } 31 32 func newBackend(scheme string) (backend, error) { 33 t, err := schemeToBackendType(scheme) 34 if err != nil { 35 return nil, err 36 } 37 38 switch t { 39 case filesystemBackend: 40 return &filesystem{}, nil 41 } 42 43 return nil, fmt.Errorf("Unsupported scheme %s", scheme) 44 } 45 46 type backend interface { 47 new(ctx context.Context, path string, host string) error 48 delete() error 49 load(item Item, data interface{}) error 50 store(item Item, data interface{}) error 51 // raw creates a raw Store item. A raw item is one that is 52 // not defined through the Item enum. 53 // The caller gets an item URL back and handles it directly, 54 // outside of the top level Store API. 55 raw(id string) (string, error) 56 lock(item Item, exclusive bool) (string, error) 57 unlock(item Item, token string) error 58 }