diff options
author | Alan Pearce | 2024-05-09 16:47:41 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-09 19:27:55 +0200 |
commit | e062ca72b222b890e345548bd8422d5df98e9fef (patch) | |
tree | 89f52ebfdb1fb8069e6323d9dde42f5491dad5d1 /internal/importer/source-type.go | |
parent | 967f6fdf5c1693d3aa27079b3ae28768fb7356c6 (diff) | |
download | searchix-e062ca72b222b890e345548bd8422d5df98e9fef.tar.lz searchix-e062ca72b222b890e345548bd8422d5df98e9fef.tar.zst searchix-e062ca72b222b890e345548bd8422d5df98e9fef.zip |
feat: import sources from configuration in go code and index options
Diffstat (limited to 'internal/importer/source-type.go')
-rw-r--r-- | internal/importer/source-type.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/importer/source-type.go b/internal/importer/source-type.go new file mode 100644 index 0000000..5d84547 --- /dev/null +++ b/internal/importer/source-type.go @@ -0,0 +1,44 @@ +package importer + +import ( + "fmt" + + "github.com/stoewer/go-strcase" +) + +type Type int + +const ( + Unknown = iota + Channel + ChannelNixpkgs +) + +func (f Type) String() string { + switch f { + case Channel: + return "channel" + case ChannelNixpkgs: + return "channel-nixpkgs" + } + + return fmt.Sprintf("Fetcher(%d)", f) +} + +func parseType(name string) (Type, error) { + switch strcase.KebabCase(name) { + case "channel": + return Channel, nil + case "channel-nixpkgs": + return ChannelNixpkgs, nil + default: + return Unknown, fmt.Errorf("unsupported fetcher %s", name) + } +} + +func (f *Type) UnmarshalText(text []byte) error { + var err error + *f, err = parseType(string(text)) + + return err +} |