github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/model/v1alpha1/storage_source.go (about) 1 package v1alpha1 2 3 import ( 4 "fmt" 5 ) 6 7 // StorageSourceType is somewhere we can get data from 8 // e.g. ipfs / S3 are storage sources 9 // there can be multiple drivers for the same source 10 // e.g. ipfs fuse vs ipfs api copy 11 // 12 //go:generate stringer -type=StorageSourceType --trimprefix=StorageSource 13 type StorageSourceType int 14 15 const ( 16 storageSourceUnknown StorageSourceType = iota // must be first 17 StorageSourceIPFS 18 StorageSourceURLDownload 19 StorageSourceFilecoinUnsealed 20 StorageSourceFilecoin 21 StorageSourceEstuary 22 storageSourceDone // must be last 23 ) 24 25 func ParseStorageSourceType(str string) (StorageSourceType, error) { 26 for typ := storageSourceUnknown + 1; typ < storageSourceDone; typ++ { 27 if equal(typ.String(), str) { 28 return typ, nil 29 } 30 } 31 32 return storageSourceUnknown, fmt.Errorf( 33 "executor: unknown source type '%s'", str) 34 } 35 36 func IsValidStorageSourceType(sourceType StorageSourceType) bool { 37 return sourceType > storageSourceUnknown && sourceType < storageSourceDone 38 } 39 40 func StorageSourceTypes() []StorageSourceType { 41 var res []StorageSourceType 42 for typ := storageSourceUnknown + 1; typ < storageSourceDone; typ++ { 43 res = append(res, typ) 44 } 45 46 return res 47 } 48 49 func StorageSourceNames() []string { 50 var names []string 51 for _, typ := range StorageSourceTypes() { 52 names = append(names, typ.String()) 53 } 54 return names 55 } 56 func (ss StorageSourceType) MarshalText() ([]byte, error) { 57 return []byte(ss.String()), nil 58 } 59 60 func (ss *StorageSourceType) UnmarshalText(text []byte) (err error) { 61 name := string(text) 62 *ss, err = ParseStorageSourceType(name) 63 return 64 }