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