github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/model/v1beta1/publisher.go (about) 1 package v1beta1 2 3 import ( 4 "fmt" 5 ) 6 7 //go:generate stringer -type=Publisher --trimprefix=Publisher 8 type Publisher int 9 10 const ( 11 publisherUnknown Publisher = iota // must be first 12 PublisherNoop 13 PublisherIpfs 14 PublisherFilecoin 15 PublisherEstuary 16 publisherDone // must be last 17 ) 18 19 func ParsePublisher(str string) (Publisher, error) { 20 for typ := publisherUnknown + 1; typ < publisherDone; typ++ { 21 if equal(typ.String(), str) { 22 return typ, nil 23 } 24 } 25 26 return publisherUnknown, fmt.Errorf("verifier: unknown type '%s'", str) 27 } 28 29 func IsValidPublisher(publisherType Publisher) bool { 30 return publisherType > publisherUnknown && publisherType < publisherDone 31 } 32 33 func PublisherTypes() []Publisher { 34 var res []Publisher 35 for typ := publisherUnknown + 1; typ < publisherDone; typ++ { 36 res = append(res, typ) 37 } 38 39 return res 40 } 41 42 func PublisherNames() []string { 43 var names []string 44 for _, typ := range PublisherTypes() { 45 names = append(names, typ.String()) 46 } 47 return names 48 } 49 50 func (p Publisher) MarshalText() ([]byte, error) { 51 return []byte(p.String()), nil 52 } 53 54 func (p *Publisher) UnmarshalText(text []byte) (err error) { 55 name := string(text) 56 *p, err = ParsePublisher(name) 57 return 58 }