diff options
author | Alan Pearce | 2024-05-16 23:41:57 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-16 23:41:57 +0200 |
commit | a5e758d41c151c17ed03b39454470ba8dd0c3b99 (patch) | |
tree | 386333b5020477eabcf490773113b029e47a21ef /internal/config/fetcher.go | |
parent | d558039919b6198a246a6a3fd007276191cb4b2f (diff) | |
download | searchix-a5e758d41c151c17ed03b39454470ba8dd0c3b99.tar.lz searchix-a5e758d41c151c17ed03b39454470ba8dd0c3b99.tar.zst searchix-a5e758d41c151c17ed03b39454470ba8dd0c3b99.zip |
refactor: separate fetch and import logic
Diffstat (limited to 'internal/config/fetcher.go')
-rw-r--r-- | internal/config/fetcher.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/config/fetcher.go b/internal/config/fetcher.go new file mode 100644 index 0000000..5018b82 --- /dev/null +++ b/internal/config/fetcher.go @@ -0,0 +1,49 @@ +package config + +import ( + "fmt" + + "github.com/stoewer/go-strcase" +) + +type Fetcher int + +const ( + UnknownFetcher = iota + Channel + ChannelNixpkgs + Download +) + +func (f Fetcher) String() string { + switch f { + case Channel: + return "channel" + case ChannelNixpkgs: + return "channel-nixpkgs" + case Download: + return "download" + } + + return fmt.Sprintf("Fetcher(%d)", f) +} + +func parseFetcher(name string) (Fetcher, error) { + switch strcase.KebabCase(name) { + case "channel": + return Channel, nil + case "channel-nixpkgs": + return ChannelNixpkgs, nil + case "download": + return Download, nil + default: + return UnknownFetcher, fmt.Errorf("unsupported fetcher %s", name) + } +} + +func (f *Fetcher) UnmarshalText(text []byte) error { + var err error + *f, err = parseFetcher(string(text)) + + return err +} |