1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package main
import (
"flag"
"fmt"
"log"
"os"
"git.server.ky/slackcoder/mirror/internal/service"
)
// Program version
var Version string
type Flags struct {
Config string
ConfigDir string
Version bool
}
func ParseFlags() *Flags {
var flags Flags
flag.StringVar(&flags.Config, "config", "/etc/mirror/mirror.toml", "configuration file which takes precedence")
flag.StringVar(&flags.ConfigDir, "config-dir", "/etc/mirror/conf.d", "configuration directory")
flag.BoolVar(&flags.Version, "version", false, "print version")
flag.Parse()
return &flags
}
func exitOnError(err error) {
if err != nil {
log.Printf("%s", err)
os.Exit(-1)
}
}
func main() {
flags := ParseFlags()
if flags.Version {
fmt.Println(Version)
os.Exit(0)
}
var cfg service.Config
c, err := service.ReadConfigDir(flags.ConfigDir)
exitOnError(err)
cfg.Append(c)
c, err = service.ReadConfig(flags.Config)
exitOnError(err)
cfg.Append(c)
srv, err := service.NewService(&cfg)
exitOnError(err)
err = srv.Run()
exitOnError(err)
}
|