Skip to content

Commit

Permalink
Add listen address and version flag
Browse files Browse the repository at this point in the history
Add new command line flags:
-listen-address=":9103"
-version

Also fix container build date to be the actual build date.
  • Loading branch information
jayme-github committed Jun 6, 2022
1 parent b4bdbb5 commit 2664bd7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 4 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand All @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"os"
"runtime"
"sync"
"time"

Expand Down Expand Up @@ -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.")
Expand All @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 2664bd7

Please sign in to comment.