From 37deedc9b1da92571548c920721984d545269eb4 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 13 May 2024 15:07:00 +0200 Subject: refactor: move Source/Repository types to config package --- internal/config/source.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 internal/config/source.go (limited to 'internal/config/source.go') diff --git a/internal/config/source.go b/internal/config/source.go new file mode 100644 index 0000000..2b1b440 --- /dev/null +++ b/internal/config/source.go @@ -0,0 +1,60 @@ +package config + +import ( + "fmt" + "time" + + "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 +} + +type Source struct { + Name string + Key string + Enable bool + Type Type + Channel string + URL string + Attribute string + ImportPath string `toml:"import-path"` + FetchTimeout time.Duration `toml:"fetch-timeout"` + ImportTimeout time.Duration `toml:"import-timeout"` + OutputPath string `toml:"output-path"` + Repo Repository +} -- cgit 1.4.1