♻️ 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
|
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)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
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)
|
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()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue