Move config file handling to the rest of the config stuff
This commit is contained in:
parent
2ac05f29d1
commit
be176fe419
2 changed files with 26 additions and 18 deletions
26
config.go
26
config.go
|
@ -1,6 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
URL string `yaml:"url"`
|
URL string `yaml:"url"`
|
||||||
|
@ -29,3 +35,21 @@ type configFormat struct {
|
||||||
Sites sites `yaml:"sites"`
|
Sites sites `yaml:"sites"`
|
||||||
Workstreams map[string]Workstreams `yaml:"workstreams"`
|
Workstreams map[string]Workstreams `yaml:"workstreams"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readConfig(configFile string) *configFormat {
|
||||||
|
file, err := os.Open(configFile)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Could not open '%s': %s", configFile, err))
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
cfg := new(configFormat)
|
||||||
|
|
||||||
|
configDecoder := yaml.NewDecoder(file)
|
||||||
|
err = configDecoder.Decode(&cfg)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Failed parsing '%s': %s", configFile, err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
18
gerritcp.go
18
gerritcp.go
|
@ -3,9 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -13,20 +10,7 @@ func main() {
|
||||||
configFile := flag.String("config", "config.yaml", "path to configuration")
|
configFile := flag.String("config", "config.yaml", "path to configuration")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
file, err := os.Open(*configFile)
|
cfg := readConfig(*configFile)
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("Could not open '%s': %s", *configFile, err))
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
cfg := new(configFormat)
|
|
||||||
|
|
||||||
configDecoder := yaml.NewDecoder(file)
|
|
||||||
err = configDecoder.Decode(&cfg)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("Failed parsing '%s': %s", *configFile, err))
|
|
||||||
}
|
|
||||||
|
|
||||||
repo := openRepo(dir, cfg)
|
repo := openRepo(dir, cfg)
|
||||||
|
|
||||||
fmt.Println(repo)
|
fmt.Println(repo)
|
||||||
|
|
Loading…
Add table
Reference in a new issue