github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/app/subscription/documentfetcher/fetcher.go (about) 1 package documentfetcher 2 3 import ( 4 "context" 5 6 "github.com/v2fly/v2ray-core/v5/app/subscription" 7 ) 8 9 //go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen 10 11 type FetcherOptions interface{} 12 13 type Fetcher interface { 14 DownloadDocument(ctx context.Context, source *subscription.ImportSource, opts ...FetcherOptions) ([]byte, error) 15 } 16 17 var knownFetcher = make(map[string]Fetcher) 18 19 func RegisterFetcher(name string, fetcher Fetcher) error { 20 if _, found := knownFetcher[name]; found { 21 return newError("fetcher ", name, " already registered") 22 } 23 knownFetcher[name] = fetcher 24 return nil 25 } 26 27 func GetFetcher(name string) (Fetcher, error) { 28 if fetcher, found := knownFetcher[name]; found { 29 return fetcher, nil 30 } 31 return nil, newError("fetcher ", name, " not found") 32 }