Browse Source

refactoring

migrate-to-golang
Dennis Jekubczyk 3 years ago
parent
commit
aabd00dbba
2 changed files with 17 additions and 17 deletions
  1. +15
    -15
      internal/config/read.go
  2. +2
    -2
      internal/config/read_test.go

+ 15
- 15
internal/config/read.go

@ -11,16 +11,16 @@ const MirrorModePrivateAndPublic = "PRIVATE_AND_PUBLIC"
type Config struct { type Config struct {
MirrorMode string 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 Username string
Token *string Token *string
} }
@ -48,29 +48,29 @@ func Read() (*Config, error) {
}, nil }, nil
} }
func readGiteaConfig() (GiteaConfig, error) {
func readGiteaConfig() (Gitea, error) {
url, a := os.LookupEnv("GITEA_URL") url, a := os.LookupEnv("GITEA_URL")
if !a { 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") token, a := os.LookupEnv("GITEA_TOKEN")
if !a { 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 }, nil
} }
func readGithubConfig() (GithubConfig, error) {
func readGithubConfig() (Github, error) {
username, present := os.LookupEnv("GITHUB_USERNAME") username, present := os.LookupEnv("GITHUB_USERNAME")
if !present { if !present {
return GithubConfig{}, errors.New("")
return Github{}, errors.New("")
} }
var token *string = nil var token *string = nil
@ -78,7 +78,7 @@ func readGithubConfig() (GithubConfig, error) {
token = &val token = &val
} }
return GithubConfig{
return Github{
Username: username, Username: username,
Token: token, Token: token,
}, nil }, nil

+ 2
- 2
internal/config/read_test.go

@ -81,8 +81,8 @@ var _ = Describe("Read", func() {
c, err := config.Read() c, err := config.Read()
Expect(err).NotTo(HaveOccurred()) 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() { It("fails on missing gitea url", func() {

Loading…
Cancel
Save