github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/model/v1beta1/storage_source.go (about)

     1  package v1beta1
     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  	StorageSourceInline
    23  	StorageSourceLocalDirectory
    24  	storageSourceDone // must be last
    25  )
    26  
    27  func ParseStorageSourceType(str string) (StorageSourceType, error) {
    28  	for typ := storageSourceUnknown + 1; typ < storageSourceDone; typ++ {
    29  		if equal(typ.String(), str) {
    30  			return typ, nil
    31  		}
    32  	}
    33  
    34  	return storageSourceUnknown, fmt.Errorf(
    35  		"executor: unknown source type '%s'", str)
    36  }
    37  
    38  func IsValidStorageSourceType(sourceType StorageSourceType) bool {
    39  	return sourceType > storageSourceUnknown && sourceType < storageSourceDone
    40  }
    41  
    42  func StorageSourceTypes() []StorageSourceType {
    43  	var res []StorageSourceType
    44  	for typ := storageSourceUnknown + 1; typ < storageSourceDone; typ++ {
    45  		res = append(res, typ)
    46  	}
    47  
    48  	return res
    49  }
    50  
    51  func StorageSourceNames() []string {
    52  	var names []string
    53  	for _, typ := range StorageSourceTypes() {
    54  		names = append(names, typ.String())
    55  	}
    56  	return names
    57  }
    58  func (ss StorageSourceType) MarshalText() ([]byte, error) {
    59  	return []byte(ss.String()), nil
    60  }
    61  
    62  func (ss *StorageSourceType) UnmarshalText(text []byte) (err error) {
    63  	name := string(text)
    64  	*ss, err = ParseStorageSourceType(name)
    65  	return
    66  }