diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 23689c4..05410a0 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -4,6 +4,8 @@ before: builds: - env: - CGO_ENABLED=0 + ldflags: + - -s -w -X "main.Version=v{{ .Version }}" -X "main.GitCommit={{ .FullCommit }}" goos: - linux - windows @@ -30,7 +32,7 @@ dockers: - --label=org.opencontainers.image.url=https://github.com/jayme-github/{{ .ProjectName }} - --label=org.opencontainers.image.source=https://github.com/jayme-github/{{ .ProjectName }} - --label=org.opencontainers.image.version=v{{ .Version }} - - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} + - --label=org.opencontainers.image.created={{ .Date }} - --label=org.opencontainers.image.revision={{ .FullCommit }} - --label=org.opencontainers.image.licenses=GPLv3 - image_templates: ["jaymedh/{{ .ProjectName }}:v{{ .Version }}-arm64v8"] @@ -46,7 +48,7 @@ dockers: - --label=org.opencontainers.image.url=https://github.com/jayme-github/{{ .ProjectName }} - --label=org.opencontainers.image.source=https://github.com/jayme-github/{{ .ProjectName }} - --label=org.opencontainers.image.version=v{{ .Version }} - - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} + - --label=org.opencontainers.image.created={{ .Date }} - --label=org.opencontainers.image.revision={{ .FullCommit }} - --label=org.opencontainers.image.licenses=GPLv3 docker_manifests: diff --git a/go.sum b/go.sum index a6f04ae..e14bb9d 100644 --- a/go.sum +++ b/go.sum @@ -62,8 +62,6 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/jayme-github/fritzctl v1.4.23-0.20220206160018-2185c66d7f6f h1:0Hw74rytK5dUZJKHw5hiQX5V8NSl+uXZOTsIqO/joL8= -github.com/jayme-github/fritzctl v1.4.23-0.20220206160018-2185c66d7f6f/go.mod h1:8bJv/qlxE0sdIAwjSLyuc+NeQ4kz77bMCdCCZOKJQjc= github.com/jayme-github/fritzctl v1.4.23-0.20220424111445-826538a7c038 h1:QhPu2bo814Kss65tEu6s30PBbkAueJb8wNCkwa/JD9M= github.com/jayme-github/fritzctl v1.4.23-0.20220424111445-826538a7c038/go.mod h1:8bJv/qlxE0sdIAwjSLyuc+NeQ4kz77bMCdCCZOKJQjc= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= diff --git a/main.go b/main.go index 07e6202..7b98dc6 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" "os" + "runtime" "sync" "time" @@ -44,6 +45,9 @@ func NewClient(options ...fritz.Option) *client { } var ( + Version = "development" + GitCommit = "" + GoVersion = runtime.Version() fritzClient *client fbURL *url.URL username = flag.String("username", "", "FRITZ!Box username.") @@ -52,11 +56,12 @@ var ( noVerify = flag.Bool("noverify", false, "Omit TLS verification of the FRITZ!Box certificate.") certificatePath = flag.String("cert", "", "Path to the FRITZ!Box certificate.") loglevel = flag.String("loglevel", "warn", "Logging verbosity (debug, info, warn, error or none)") + listenAddress = flag.String("listen-address", ":9103", "Address on which to expose metrics") + version = flag.Bool("version", false, "Print version number and exit") ) func validateFlags() { var err error - flag.Parse() l := &fritzctllogger.Level{} if err := l.Set(*loglevel); err != nil { @@ -95,6 +100,13 @@ func validateFlags() { } func main() { + flag.Parse() + + if *version { + fmt.Printf("Version: \"%s\", GitCommit: \"%s\", GoVersion: \"%s\"\n", Version, GitCommit, GoVersion) + return + } + validateFlags() options := []fritz.Option{ @@ -135,7 +147,7 @@ func main() { prometheus.MustRegister(fc) http.Handle("/metrics", promhttp.Handler()) - if err := http.ListenAndServe(":9103", nil); err != nil { + if err := http.ListenAndServe(*listenAddress, nil); err != nil { log.Fatalln(err) } }