Skip to content

Commit 2664bd7

Browse files
committed
Add listen address and version flag
Add new command line flags: -listen-address=":9103" -version Also fix container build date to be the actual build date.
1 parent b4bdbb5 commit 2664bd7

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

.goreleaser.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ before:
44
builds:
55
- env:
66
- CGO_ENABLED=0
7+
ldflags:
8+
- -s -w -X "main.Version=v{{ .Version }}" -X "main.GitCommit={{ .FullCommit }}"
79
goos:
810
- linux
911
- windows
@@ -30,7 +32,7 @@ dockers:
3032
- --label=org.opencontainers.image.url=https://github.com/jayme-github/{{ .ProjectName }}
3133
- --label=org.opencontainers.image.source=https://github.com/jayme-github/{{ .ProjectName }}
3234
- --label=org.opencontainers.image.version=v{{ .Version }}
33-
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
35+
- --label=org.opencontainers.image.created={{ .Date }}
3436
- --label=org.opencontainers.image.revision={{ .FullCommit }}
3537
- --label=org.opencontainers.image.licenses=GPLv3
3638
- image_templates: ["jaymedh/{{ .ProjectName }}:v{{ .Version }}-arm64v8"]
@@ -46,7 +48,7 @@ dockers:
4648
- --label=org.opencontainers.image.url=https://github.com/jayme-github/{{ .ProjectName }}
4749
- --label=org.opencontainers.image.source=https://github.com/jayme-github/{{ .ProjectName }}
4850
- --label=org.opencontainers.image.version=v{{ .Version }}
49-
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
51+
- --label=org.opencontainers.image.created={{ .Date }}
5052
- --label=org.opencontainers.image.revision={{ .FullCommit }}
5153
- --label=org.opencontainers.image.licenses=GPLv3
5254
docker_manifests:

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
6262
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
6363
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
6464
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
65-
github.com/jayme-github/fritzctl v1.4.23-0.20220206160018-2185c66d7f6f h1:0Hw74rytK5dUZJKHw5hiQX5V8NSl+uXZOTsIqO/joL8=
66-
github.com/jayme-github/fritzctl v1.4.23-0.20220206160018-2185c66d7f6f/go.mod h1:8bJv/qlxE0sdIAwjSLyuc+NeQ4kz77bMCdCCZOKJQjc=
6765
github.com/jayme-github/fritzctl v1.4.23-0.20220424111445-826538a7c038 h1:QhPu2bo814Kss65tEu6s30PBbkAueJb8wNCkwa/JD9M=
6866
github.com/jayme-github/fritzctl v1.4.23-0.20220424111445-826538a7c038/go.mod h1:8bJv/qlxE0sdIAwjSLyuc+NeQ4kz77bMCdCCZOKJQjc=
6967
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=

main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"net/url"
99
"os"
10+
"runtime"
1011
"sync"
1112
"time"
1213

@@ -44,6 +45,9 @@ func NewClient(options ...fritz.Option) *client {
4445
}
4546

4647
var (
48+
Version = "development"
49+
GitCommit = ""
50+
GoVersion = runtime.Version()
4751
fritzClient *client
4852
fbURL *url.URL
4953
username = flag.String("username", "", "FRITZ!Box username.")
@@ -52,11 +56,12 @@ var (
5256
noVerify = flag.Bool("noverify", false, "Omit TLS verification of the FRITZ!Box certificate.")
5357
certificatePath = flag.String("cert", "", "Path to the FRITZ!Box certificate.")
5458
loglevel = flag.String("loglevel", "warn", "Logging verbosity (debug, info, warn, error or none)")
59+
listenAddress = flag.String("listen-address", ":9103", "Address on which to expose metrics")
60+
version = flag.Bool("version", false, "Print version number and exit")
5561
)
5662

5763
func validateFlags() {
5864
var err error
59-
flag.Parse()
6065

6166
l := &fritzctllogger.Level{}
6267
if err := l.Set(*loglevel); err != nil {
@@ -95,6 +100,13 @@ func validateFlags() {
95100
}
96101

97102
func main() {
103+
flag.Parse()
104+
105+
if *version {
106+
fmt.Printf("Version: \"%s\", GitCommit: \"%s\", GoVersion: \"%s\"\n", Version, GitCommit, GoVersion)
107+
return
108+
}
109+
98110
validateFlags()
99111

100112
options := []fritz.Option{
@@ -135,7 +147,7 @@ func main() {
135147
prometheus.MustRegister(fc)
136148
http.Handle("/metrics", promhttp.Handler())
137149

138-
if err := http.ListenAndServe(":9103", nil); err != nil {
150+
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
139151
log.Fatalln(err)
140152
}
141153
}

0 commit comments

Comments
 (0)