Files
docker-updater/main.go
2026-02-08 22:52:26 +01:00

60 lines
1.3 KiB
Go

//go:build !debug
package main
import (
"context"
"docker-updater/constant"
"log/slog"
"os"
"runtime"
"runtime/debug"
"strings"
)
func main() {
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
slog.SetDefault(logger)
defer func() {
if r := recover(); r != nil {
if info, ok := debug.ReadBuildInfo(); ok {
var settings []string
for _, setting := range info.Settings {
settings = append(settings, setting.Key+":"+setting.Value)
}
slog.Error("a panic occured",
"err", r,
"os", runtime.GOOS,
"arch", runtime.GOARCH,
"num_cpu", runtime.NumCPU(),
"num_cgo_call", runtime.NumCgoCall(),
"num_goroutine", runtime.NumGoroutine(),
"go_version", info.GoVersion,
"build_settings", strings.Join(settings, ", "),
)
} else {
slog.Error("a panic occured, no build info available",
"err", r,
"os", runtime.GOOS,
"arch", runtime.GOARCH,
"num_cpu", runtime.NumCPU(),
"num_cgo_call", runtime.NumCgoCall(),
"num_goroutine", runtime.NumGoroutine(),
)
}
}
}()
debug.SetTraceback("none")
slog.Info("docker-updater", "version", constant.ProgramVersion(), "os", runtime.GOOS, "arch", runtime.GOARCH)
os.Exit(run(ctx, false))
}