From 7a9dd706de6e09510d61cfae57a592a96767a837 Mon Sep 17 00:00:00 2001 From: Ada Date: Thu, 4 Apr 2024 18:02:04 +0200 Subject: [PATCH] :recycle: Make configuration structure more clean --- internal/config/config.go | 12 +++++------- internal/config/toml.go | 2 +- internal/git/config.go | 7 +++++++ main.go | 9 +++++++++ 4 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 internal/git/config.go diff --git a/internal/config/config.go b/internal/config/config.go index 911b5a8..9b6f44c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,14 +1,12 @@ 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 { CloneDirectory string // Repository where gir-mirror keep repository Log log.Config - RepoList []repoConfig -} - -type repoConfig struct { - URL string // Source url - Name string // Name of clone (directory name) + RepoList []git.RepoConfig } diff --git a/internal/config/toml.go b/internal/config/toml.go index 4c69493..162c853 100644 --- a/internal/config/toml.go +++ b/internal/config/toml.go @@ -23,7 +23,7 @@ func LoadToml(file string) (Config, error) { return config, nil } -func VerifyConfig(config Config) error { +func (config Config) Verify() error { allowedValue := []string{"DEBUG", "INFO", "WARN", "ERROR", "FATAL"} found := false for _, v := range allowedValue { diff --git a/internal/git/config.go b/internal/git/config.go new file mode 100644 index 0000000..23bf1b5 --- /dev/null +++ b/internal/git/config.go @@ -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) +} diff --git a/main.go b/main.go index 19dba9d..3d8d81e 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,16 @@ func main() { logrus.Fatal(err) } + err = initConfig.Verify() + if err != nil { + logrus.Fatal(err) + } + initConfig.Log.Init() logrus.Info("Config loaded") logrus.Debug("Config: ", initConfig) + + cloneConfig := initConfig.RepoList[0] + cloneConfig.FullPath = initConfig.CloneDirectory + cloneConfig.Name + cloneConfig.FullClone() }