♻️ Make configuration structure more clean
This commit is contained in:
parent
8f63ef0401
commit
7a9dd706de
4 changed files with 22 additions and 8 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
7
internal/git/config.go
Normal file
7
internal/git/config.go
Normal 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)
|
||||
}
|
9
main.go
9
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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue