aboutsummaryrefslogtreecommitdiffsponsor
path: root/cmd/mirror/main.go
blob: e8a7f6cddd31c5c135353bfbfde81067e76927f9 (plain)
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
package main

import (
	"flag"
	"log"
	"os"

	"git.server.ky/slackcoder/mirror/internal/service"
)

type Flags struct {
	Config  string
	Mirrors string
}

func ParseFlags() *Flags {
	var flags Flags

	flag.StringVar(&flags.Config, "config", "/etc/mirror/config.json", "configuration file")

	flag.Parse()
	return &flags
}

func exitOnError(err error) {
	if err != nil {
		log.Printf("%s", err)
		os.Exit(-1)
	}
}

func main() {
	flags := ParseFlags()

	var cfg service.Config
	err := service.ApplyFileConfig(&cfg, flags.Config)
	exitOnError(err)

	srv, err := service.NewService(&cfg)
	exitOnError(err)

	err = srv.Run()
	exitOnError(err)
}