Skip to content

Commit e9f31e6

Browse files
authored
add version info and logs (#41)
1 parent ec68885 commit e9f31e6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

main.go

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http/pprof"
1111
"os"
1212
"os/signal"
13+
"runtime/debug"
1314
"strconv"
1415
"strings"
1516
"syscall"
@@ -81,15 +82,26 @@ func main() {
8182
flagConfig := flag.String("config", envString("GIT_MIRROR_CONFIG", "/etc/git-mirror/config.yaml"), "Absolute path to the config file")
8283
flagWatchConfig := flag.Bool("watch-config", envBool("GIT_MIRROR_WATCH_CONFIG", true), "watch config for changes and reload when changes encountered")
8384
flagHttpBind := flag.String("http-bind-address", envString("GIT_MIRROR_HTTP_BIND", ":9001"), "The address the web server binds to")
85+
flagVersion := flag.Bool("version", false, "git-mirror version")
8486

8587
flag.Usage = usage
8688
flag.Parse()
8789

90+
info, _ := debug.ReadBuildInfo()
91+
92+
if *flagVersion || (flag.NArg() == 1 && flag.Arg(0) == "version") {
93+
fmt.Printf("version=%s go=%s\n", info.Main.Version, info.GoVersion)
94+
return
95+
}
96+
8897
// set log level according to argument
8998
if v, ok := levelStrings[strings.ToLower(*flagLogLevel)]; ok {
9099
loggerLevel.Set(v)
91100
}
92101

102+
logger.Info("version", "app", info.Main.Version, "go", info.GoVersion)
103+
logger.Info("config", "path", *flagConfig, "watch", *flagWatchConfig)
104+
93105
mirror.EnableMetrics("", prometheus.NewRegistry())
94106
prometheus.MustRegister(configSuccess, configSuccessTime)
95107

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

138150
go func() {
151+
logger.Info("starting web server", "add", *flagHttpBind)
139152
if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
140153
logger.Error("HTTP server terminated", "err", err)
141154
}

0 commit comments

Comments
 (0)