♻️ Make configuration structure more clean
Some checks failed
ci/woodpecker/push/test Pipeline failed
ci/woodpecker/push/lint Pipeline failed

This commit is contained in:
Ada 2024-04-04 18:02:04 +02:00
parent 8f63ef0401
commit 7a9dd706de
Signed by: ada
GPG key ID: 6A7F898157C6DE6E
4 changed files with 22 additions and 8 deletions

View file

@ -1,14 +1,12 @@
package config package config
import "git.gnous.eu/ada/git-mirror/internal/log" import (
"git.gnous.eu/ada/git-mirror/internal/git"
"git.gnous.eu/ada/git-mirror/internal/log"
)
type Config struct { type Config struct {
CloneDirectory string // Repository where gir-mirror keep repository CloneDirectory string // Repository where gir-mirror keep repository
Log log.Config Log log.Config
RepoList []repoConfig RepoList []git.RepoConfig
}
type repoConfig struct {
URL string // Source url
Name string // Name of clone (directory name)
} }

View file

@ -23,7 +23,7 @@ func LoadToml(file string) (Config, error) {
return config, nil return config, nil
} }
func VerifyConfig(config Config) error { func (config Config) Verify() error {
allowedValue := []string{"DEBUG", "INFO", "WARN", "ERROR", "FATAL"} allowedValue := []string{"DEBUG", "INFO", "WARN", "ERROR", "FATAL"}
found := false found := false
for _, v := range allowedValue { for _, v := range allowedValue {

7
internal/git/config.go Normal file
View file

@ -0,0 +1,7 @@
package git
type RepoConfig struct {
URL string // Source url
FullPath string // Full clone directory
Name string // Name of clone (directory name)
}

View file

@ -11,7 +11,16 @@ func main() {
logrus.Fatal(err) logrus.Fatal(err)
} }
err = initConfig.Verify()
if err != nil {
logrus.Fatal(err)
}
initConfig.Log.Init() initConfig.Log.Init()
logrus.Info("Config loaded") logrus.Info("Config loaded")
logrus.Debug("Config: ", initConfig) logrus.Debug("Config: ", initConfig)
cloneConfig := initConfig.RepoList[0]
cloneConfig.FullPath = initConfig.CloneDirectory + cloneConfig.Name
cloneConfig.FullClone()
} }