From bdfb34c1200dce0c9d0a866632e532c96cdadd79 Mon Sep 17 00:00:00 2001 From: Andreas Wachter Date: Tue, 1 Jun 2021 20:04:38 +0200 Subject: [PATCH] created better types --- main.go | 12 ++++++------ types.go | 42 +++++++++++------------------------------- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/main.go b/main.go index 1a3c5ee..c3379c1 100644 --- a/main.go +++ b/main.go @@ -145,7 +145,7 @@ func Locally(repo Repo, l Local) { } } -func BackupGitea(r Repo, d Gitea) { +func BackupGitea(r Repo, d GenRepo) { if d.Url == "" { d.Url = "https://gitea.com/" } @@ -168,7 +168,7 @@ func BackupGitea(r Repo, d Gitea) { } } -func BackupGogs(r Repo, d Gogs) { +func BackupGogs(r Repo, d GenRepo) { log.Info().Str("stage", "gogs").Str("url", d.Url).Msgf("mirroring %s to %s", blue(r.Name), d.Url) gogsclient := gogs.NewClient(d.Url, d.Token) @@ -185,7 +185,7 @@ func BackupGogs(r Repo, d Gogs) { } } -func BackupGitlab(r Repo, d Gitlab) { +func BackupGitlab(r Repo, d GenRepo) { gitlabclient := &gitlab.Client{} var err error if d.Url == "" { @@ -314,7 +314,7 @@ func getGitea(conf *Conf) []Repo { } for _, r := range gitearepos { - repos = append(repos, Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo.Github}) + repos = append(repos, Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo}) } } return repos @@ -331,7 +331,7 @@ func getGogs(conf *Conf) []Repo { } for _, r := range gogsrepos { - repos = append(repos, Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo.Github}) + repos = append(repos, Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo}) } } return repos @@ -374,7 +374,7 @@ func getGitlab(conf *Conf) []Repo { } } for _, r := range gitlabrepos { - repos = append(repos, Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo.Github}) + repos = append(repos, Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo}) } } return repos diff --git a/types.go b/types.go index 345f39a..065aeae 100644 --- a/types.go +++ b/types.go @@ -1,17 +1,12 @@ package main -// Gitea -type Gitea struct { - GenRepo -} - // Destination type Destination struct { - Gitlab []Gitlab `yaml:"gitlab"` - Local []Local `yaml:"local"` - Github []Github `yaml:"github"` - Gitea []Gitea `yaml:"gitea"` - Gogs []Gogs `yaml:"gogs"` + Gitlab []GenRepo `yaml:"gitlab"` + Local []Local `yaml:"local"` + Github []GenRepo `yaml:"github"` + Gitea []GenRepo `yaml:"gitea"` + Gogs []GenRepo `yaml:"gogs"` } // Local @@ -27,36 +22,21 @@ type Conf struct { // Source type Source struct { - Gogs []Gogs `yaml:"gogs"` - Gitlab []Gitlab `yaml:"gitlab"` - Github []Github `yaml:"github"` - Gitea []Gitea `yaml:"gitea"` + Gogs []GenRepo `yaml:"gogs"` + Gitlab []GenRepo `yaml:"gitlab"` + Github []GenRepo `yaml:"github"` + Gitea []GenRepo `yaml:"gitea"` } // Generell Repo type GenRepo struct { - Github - Url string `yaml:"url"` -} - -// Gogs -type Gogs struct { - GenRepo -} - -// Gitlab -type Gitlab struct { - GenRepo -} - -// Github -type Github struct { Token string `yaml:"token"` User string `yaml:"user"` SSH bool `yaml:"ssh"` SSHKey string `yaml:"sshkey"` Username string `yaml:"username"` Password string `yaml:"password"` + Url string `yaml:"url"` } // Repo @@ -66,5 +46,5 @@ type Repo struct { SshUrl string Token string Defaultbranch string - Origin Github + Origin GenRepo }