From aabd00dbba5e6059493c68cb8a0461773c560a85 Mon Sep 17 00:00:00 2001 From: Dennis Jekubczyk Date: Mon, 24 May 2021 16:52:05 +0200 Subject: [PATCH] refactoring --- internal/config/read.go | 30 +++++++++++++++--------------- internal/config/read_test.go | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/internal/config/read.go b/internal/config/read.go index 89f8e2d..bd2e0e8 100644 --- a/internal/config/read.go +++ b/internal/config/read.go @@ -11,16 +11,16 @@ const MirrorModePrivateAndPublic = "PRIVATE_AND_PUBLIC" type Config struct { MirrorMode string - Gitea GiteaConfig - Github GithubConfig + Gitea Gitea + Github Github } -type GiteaConfig struct { - GiteaUrl string - GiteaToken string +type Gitea struct { + Url string + Token string } -type GithubConfig struct { +type Github struct { Username string Token *string } @@ -48,29 +48,29 @@ func Read() (*Config, error) { }, nil } -func readGiteaConfig() (GiteaConfig, error) { +func readGiteaConfig() (Gitea, error) { url, a := os.LookupEnv("GITEA_URL") if !a { - return GiteaConfig{}, errors.New("missing mandatory parameter GITEA_URL, please specify your target gitea instance") + return Gitea{}, errors.New("missing mandatory parameter GITEA_URL, please specify your target gitea instance") } token, a := os.LookupEnv("GITEA_TOKEN") if !a { - return GiteaConfig{}, errors.New("missing mandatory parameter GITEA_TOKEN, please specify your gitea application token") + return Gitea{}, errors.New("missing mandatory parameter GITEA_TOKEN, please specify your gitea application token") } - return GiteaConfig{ - GiteaUrl: url, - GiteaToken: token, + return Gitea{ + Url: url, + Token: token, }, nil } -func readGithubConfig() (GithubConfig, error) { +func readGithubConfig() (Github, error) { username, present := os.LookupEnv("GITHUB_USERNAME") if !present { - return GithubConfig{}, errors.New("") + return Github{}, errors.New("") } var token *string = nil @@ -78,7 +78,7 @@ func readGithubConfig() (GithubConfig, error) { token = &val } - return GithubConfig{ + return Github{ Username: username, Token: token, }, nil diff --git a/internal/config/read_test.go b/internal/config/read_test.go index 6f2adfa..752c4dd 100644 --- a/internal/config/read_test.go +++ b/internal/config/read_test.go @@ -81,8 +81,8 @@ var _ = Describe("Read", func() { c, err := config.Read() Expect(err).NotTo(HaveOccurred()) - Expect(c.Gitea.GiteaUrl).To(Equal("https://gitea.url/api")) - Expect(c.Gitea.GiteaToken).To(Equal("a-gitea-token")) + Expect(c.Gitea.Url).To(Equal("https://gitea.url/api")) + Expect(c.Gitea.Token).To(Equal("a-gitea-token")) }) It("fails on missing gitea url", func() {