xmpp-webhook

webhook to xmpp gateway (clone of https://github.com/opthomas-prime/xmpp-webhook/ with my own mods)
git clone https://git.e1e0.net/xmpp-webhook.git
Log | Files | Refs | README | LICENSE

commit 8e3df4ccb7fa8f93b5021fcc934ae8f59a938eba
parent c66e481512572b555192154440f8242ca818b4a0
Author: Paco Esteban <paco@onna.be>
Date:   Mon, 15 Jul 2019 13:13:54 +0200

add this:

version flag
port can be set on env variable (and has a default)
makefile

Diffstat:
AMakefile | 22++++++++++++++++++++++
Mmain.go | 24+++++++++++++++++++++++-
2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -0,0 +1,22 @@ +BINARY=xmpp-webhook + +VERSION=0.1 +BUILD_DATE=`date '+%Y%m%d%H%M'` +BUILD=`git rev-parse HEAD` +OS=`uname | tr "[:upper:]" "[:lower:]"` +ARCH="amd64" + +LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -X main.BuildDate=${BUILD_DATE} -w" + +.DEFAULT: ${BINARY} + +${BINARY}: main.go handler.go + @echo "Build for ${OS}(${ARCH}) static" + GOOS=${OS} GOARCH=${ARCH} CGO_ENABLED=0 \ + go build ${LDFLAGS} -tags netgo -o ${BINARY} + +.PHONY: clean +clean: + rm -rf ${BINARY} + +# vim:ft=make diff --git a/main.go b/main.go @@ -1,6 +1,8 @@ package main import ( + "flag" + "fmt" "log" "net/http" "os" @@ -9,6 +11,12 @@ import ( "github.com/emgee/go-xmpp/src/xmpp" ) +var ( + Version string + Build string + BuildDate string +) + // starts xmpp session and returns the xmpp client func xmppLogin(id string, pass string) (*xmpp.XMPP, error) { // parse jid structure @@ -39,16 +47,30 @@ func xmppLogin(id string, pass string) (*xmpp.XMPP, error) { } func main() { + verF := flag.Bool("version", false, "Prints version and exit") + flag.Parse() + + if *verF { + fmt.Printf("xmpp-webhook v%s, built on: %s\n", Version, BuildDate) + fmt.Printf("Git rev: %s\n", Build) + os.Exit(0) + } + // get xmpp credentials and message receivers from env xi := os.Getenv("XMPP_ID") xp := os.Getenv("XMPP_PASS") xr := os.Getenv("XMPP_RECEIVERS") + port := os.Getenv("XMPP_HOOK_PORT") // check if xmpp credentials and receiver list are supplied if len(xi) < 1 || len(xp) < 1 || len(xr) < 1 { log.Fatal("XMPP_ID, XMPP_PASS or XMPP_RECEIVERS not set") } + if len(port) < 1 { + port = "4321" + } + // connect to xmpp server xc, err := xmppLogin(xi, xp) if err != nil { @@ -106,5 +128,5 @@ func main() { http.Handle("/custom", newMessageHandler(messages, customParserFunc)) // listen for requests - http.ListenAndServe(":4321", nil) + http.ListenAndServe(":" + port, nil) }