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/repository.go | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 internal/config/repository.go (limited to 'internal/config/repository.go') diff --git a/internal/config/repository.go b/internal/config/repository.go new file mode 100644 index 0000000..8c17a4f --- /dev/null +++ b/internal/config/repository.go @@ -0,0 +1,44 @@ +package config + +import ( + "fmt" + "strings" +) + +type RepoType int + +const ( + GitHub = iota + 1 +) + +type Repository struct { + Type string `default:"github"` + Owner string + Repo string + Revision string +} + +func (f RepoType) String() string { + switch f { + case GitHub: + return "github" + default: + return fmt.Sprintf("RepoType(%d)", f) + } +} + +func parseRepoType(name string) (RepoType, error) { + switch strings.ToLower(name) { + case "github": + return GitHub, nil + default: + return Unknown, fmt.Errorf("unsupported repo type %s", name) + } +} + +func (f *RepoType) UnmarshalText(text []byte) error { + var err error + *f, err = parseRepoType(string(text)) + + return err +} -- cgit 1.4.1