Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http/pprof"
"os"
"os/signal"
"runtime/debug"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -81,15 +82,26 @@ func main() {
flagConfig := flag.String("config", envString("GIT_MIRROR_CONFIG", "/etc/git-mirror/config.yaml"), "Absolute path to the config file")
flagWatchConfig := flag.Bool("watch-config", envBool("GIT_MIRROR_WATCH_CONFIG", true), "watch config for changes and reload when changes encountered")
flagHttpBind := flag.String("http-bind-address", envString("GIT_MIRROR_HTTP_BIND", ":9001"), "The address the web server binds to")
flagVersion := flag.Bool("version", false, "git-mirror version")

flag.Usage = usage
flag.Parse()

info, _ := debug.ReadBuildInfo()

if *flagVersion || (flag.NArg() == 1 && flag.Arg(0) == "version") {
fmt.Printf("version=%s go=%s\n", info.Main.Version, info.GoVersion)
return
}

// set log level according to argument
if v, ok := levelStrings[strings.ToLower(*flagLogLevel)]; ok {
loggerLevel.Set(v)
}

logger.Info("version", "app", info.Main.Version, "go", info.GoVersion)
logger.Info("config", "path", *flagConfig, "watch", *flagWatchConfig)

mirror.EnableMetrics("", prometheus.NewRegistry())
prometheus.MustRegister(configSuccess, configSuccessTime)

Expand Down Expand Up @@ -136,6 +148,7 @@ func main() {
go WatchConfig(ctx, *flagConfig, *flagWatchConfig, 10*time.Second, onConfigChange)

go func() {
logger.Info("starting web server", "add", *flagHttpBind)
if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Error("HTTP server terminated", "err", err)
}
Expand Down
Loading