internal/fetcher/main.go (view raw)
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 | package fetcher import ( "context" "log/slog" "searchix/internal/config" "github.com/pkg/errors" ) type FetchedFiles struct { Revision string Options string Packages string } type Fetcher interface { FetchIfNeeded(context.Context) (FetchedFiles, bool, error) } func New( source *config.Source, fetcherDataPath string, logger *slog.Logger, ) (fetcher Fetcher, err error) { switch source.Fetcher { case config.ChannelNixpkgs: fetcher, err = NewNixpkgsChannelFetcher(source, fetcherDataPath, logger) case config.Channel: fetcher, err = NewChannelFetcher(source, fetcherDataPath, logger) case config.Download: fetcher, err = NewDownloadFetcher(source, fetcherDataPath, logger) default: err = errors.Errorf("unsupported fetcher type %s", source.Fetcher.String()) } return } |