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 {
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

+ 2
- 2
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() {

Loading…
Cancel
Save