~xenrox/ntfy-alertmanager

78801c98e4e1c899b7d8b5ef5d8d81cfd6620174 — Thorben Günther 1 year, 3 months ago 7548567
Add version flag

And print version at startup.
4 files changed, 18 insertions(+), 2 deletions(-)

M .build.yml
M .gitignore
M docker/Dockerfile-dev
M main.go
M .build.yml => .build.yml +1 -0
@@ 11,6 11,7 @@ sources:
tasks:
    - test: |
          cd ntfy-alertmanager
          go generate ./...
          go test -v ./...
    - lint: |
          cd ntfy-alertmanager

M .gitignore => .gitignore +1 -0
@@ 1,1 1,2 @@
/ntfy-alertmanager
version.txt

M docker/Dockerfile-dev => docker/Dockerfile-dev +2 -1
@@ 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

M main.go => main.go +14 -1
@@ 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")