created better types

This commit is contained in:
Andreas Wachter
2021-06-01 20:04:38 +02:00
parent 0088e0a66c
commit bdfb34c120
2 changed files with 17 additions and 37 deletions
+6 -6
View File
@@ -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
+11 -31
View File
@@ -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
}