Add version flag
And print version at startup.
This commit is contained in:
parent
7548567992
commit
78801c98e4
4 changed files with 18 additions and 2 deletions
|
@ -11,6 +11,7 @@ sources:
|
|||
tasks:
|
||||
- test: |
|
||||
cd ntfy-alertmanager
|
||||
go generate ./...
|
||||
go test -v ./...
|
||||
- lint: |
|
||||
cd ntfy-alertmanager
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
/ntfy-alertmanager
|
||||
version.txt
|
||||
|
|
|
@ -2,7 +2,8 @@ FROM golang:alpine as build
|
|||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
RUN go build -o /app/ntfy-alertmanager
|
||||
RUN apk add --no-cache git
|
||||
RUN go generate ./... && go build -o /app/ntfy-alertmanager
|
||||
|
||||
|
||||
FROM alpine:latest
|
||||
|
|
15
main.go
15
main.go
|
@ -4,11 +4,13 @@ package main
|
|||
import (
|
||||
"crypto/sha512"
|
||||
"crypto/subtle"
|
||||
_ "embed"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -17,6 +19,10 @@ import (
|
|||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
//go:generate sh -c "git describe --long > version.txt"
|
||||
//go:embed version.txt
|
||||
var version string
|
||||
|
||||
type receiver struct {
|
||||
cfg *config
|
||||
logger *log.Logger
|
||||
|
@ -205,8 +211,15 @@ func (rcv *receiver) basicAuthMiddleware(handler http.HandlerFunc) http.HandlerF
|
|||
func main() {
|
||||
var configPath string
|
||||
flag.StringVar(&configPath, "config", "/etc/ntfy-alertmanager/config", "config file path")
|
||||
var showVersion bool
|
||||
flag.BoolVar(&showVersion, "version", false, "Show version and exit")
|
||||
flag.Parse()
|
||||
|
||||
if showVersion {
|
||||
fmt.Println(version)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
logger := log.NewDefaultLogger()
|
||||
|
||||
cfg, err := readConfig(configPath)
|
||||
|
@ -220,7 +233,7 @@ func main() {
|
|||
|
||||
receiver := &receiver{cfg: cfg, logger: logger}
|
||||
|
||||
logger.Infof("Listening on %s", cfg.HTTPAddress)
|
||||
logger.Infof("Listening on %s, ntfy-alertmanager %s", cfg.HTTPAddress, version)
|
||||
|
||||
if cfg.User != "" && cfg.Password != "" {
|
||||
logger.Info("Enabling HTTP Basic Authentication")
|
||||
|
|
Loading…
Reference in a new issue