Compare commits
No commits in common. "master" and "v0.0.9" have entirely different histories.
101
build.sh
101
build.sh
@ -1,101 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
APP=mqttListener
|
||||
|
||||
# expand PATH for go tools
|
||||
export PATH=$PATH:~/go/bin
|
||||
|
||||
|
||||
RED='\e[0;31m'
|
||||
GREEN='\e[0;32m'
|
||||
LIGHT_YELLOW='\e[93m'
|
||||
NC='\e[0m' # No Color
|
||||
BOLD='\e[1m'
|
||||
NORMAL='\e[21m'
|
||||
|
||||
#######################################################################################
|
||||
# defaults
|
||||
GO_BUILD_OPTIONS=-v
|
||||
#GO_BUILD_OPTIONS="-a -v"
|
||||
DEFAULT_TARGET=amd64
|
||||
|
||||
#######################################################################################
|
||||
# functions
|
||||
|
||||
die() { echo -e "\n${RED}$@${NC}" 1>&2 ; exit 1; }
|
||||
|
||||
usage() {
|
||||
echo "usage: `basename $0` [<TARGET>] [all]"
|
||||
}
|
||||
|
||||
|
||||
#######################################################################################
|
||||
# build functions
|
||||
|
||||
build_linux_amd64() {
|
||||
echo -e "\nBuilding for Linux amd64:"
|
||||
|
||||
env GOOS=linux GOARCH=amd64 go build ${GO_BUILD_OPTIONS} -ldflags "$(govvv -flags)" -o ${APP}-linux-amd64
|
||||
echo -e "\t\t${GREEN}... done${NC}"
|
||||
}
|
||||
|
||||
build_linux_arm() {
|
||||
echo -e "\nBuilding for arm:"
|
||||
|
||||
# setup environment
|
||||
export CGO_ENABLED=1
|
||||
export PATH=$PATH:/opt/devel/ptu4/buildrootBuild/host/usr/bin
|
||||
export CC=arm-linux-gcc
|
||||
export PKG_CONFIG_PATH=/opt/devel/ptu4/buildrootBuild/host/usr/lib/pkgconfig
|
||||
|
||||
env GOOS=linux GOARCH=arm go build ${GO_BUILD_OPTIONS} -ldflags "$(govvv -flags)" -o ${APP}-linux-arm
|
||||
echo -e "\t\t${GREEN}... done${NC}"
|
||||
|
||||
echo -e "\nstipping arm binary:"
|
||||
strip -o ${TARGET}-linux-arm-stripped ${APP}-linux-arm
|
||||
echo -e "\t\t${GREEN}... done${NC}"
|
||||
}
|
||||
|
||||
#######################################################################################
|
||||
# checks
|
||||
|
||||
echo -e "${NC}\n "
|
||||
|
||||
|
||||
if [ ! command -v govvv &> /dev/null ] ; then
|
||||
die "govvv is not installed"
|
||||
fi
|
||||
|
||||
|
||||
if [ $# -eq 0 ] ; then
|
||||
echo -e "\nbuilding for default TARGET ${DEFAULT_TARGET}..."
|
||||
TARGET=${DEFAULT_TARGET}
|
||||
else
|
||||
TARGET=$1
|
||||
fi
|
||||
|
||||
#######################################################################################
|
||||
# build
|
||||
|
||||
#cd /src
|
||||
|
||||
|
||||
if [ "$2" == "all" ] ; then
|
||||
echo -e "\nforce rebuilding of all packages..."
|
||||
GO_BUILD_OPTIONS="-a -v"
|
||||
fi
|
||||
|
||||
|
||||
case "${TARGET}" in
|
||||
"arm"|"ARM")
|
||||
build_linux_arm
|
||||
;;
|
||||
"amd64"|"AMD64")
|
||||
build_linux_amd64
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
die "Target ${TARGET} is not defined"
|
||||
;;
|
||||
esac
|
||||
|
1
go.mod
1
go.mod
@ -3,7 +3,6 @@ module mqttListener
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/ahmetb/govvv v0.3.0 // indirect
|
||||
github.com/eclipse/paho.mqtt.golang v1.2.0
|
||||
github.com/mattn/go-sqlite3 v1.14.2
|
||||
github.com/mmcdole/gofeed v1.0.0
|
||||
|
48
main.go
48
main.go
@ -6,64 +6,18 @@ import (
|
||||
"mqttListener/models"
|
||||
"mqttListener/mqtt"
|
||||
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Following variables will be statically linked at the time of compiling
|
||||
|
||||
// GitCommit holds short commit hash of source tree
|
||||
var GitCommit string
|
||||
|
||||
// GitBranch holds current branch name the code is built off
|
||||
var GitBranch string
|
||||
|
||||
// GitState shows whether there are uncommitted changes
|
||||
var GitState string
|
||||
|
||||
// GitSummary holds output of git describe --tags --dirty --always
|
||||
var GitSummary string
|
||||
|
||||
// BuildDate holds RFC3339 formatted UTC date (build time)
|
||||
var BuildDate string
|
||||
|
||||
// Version holds contents of ./VERSION file, if exists, or the value passed via the -version option
|
||||
var Version string
|
||||
|
||||
// PrintVersion prints version information
|
||||
func PrintVersion() {
|
||||
var versionString string = GitSummary
|
||||
fmt.Println("\n--------------------------------------------------------")
|
||||
fmt.Println(filepath.Base(os.Args[0]), " Version Information: ")
|
||||
fmt.Println("\tVersion:\t", versionString)
|
||||
fmt.Println("\tBranch:\t\t", GitBranch)
|
||||
fmt.Println("\tCommit-ID:\t", GitCommit)
|
||||
fmt.Println("\tBuilt:\t\t", BuildDate)
|
||||
fmt.Println("\n--------------------------------------------------------")
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
func main() {
|
||||
|
||||
versionFlagPtr := flag.Bool("v", false, "print version")
|
||||
flag.Parse()
|
||||
if *versionFlagPtr {
|
||||
PrintVersion()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
PrintVersion()
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
@ -80,7 +34,7 @@ func main() {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
env := &env.Env{DB: db, Config: config}
|
||||
env := &env.Env{db, config}
|
||||
|
||||
mqtt.Setup(env)
|
||||
mqtt.Connect()
|
||||
|
Loading…
Reference in New Issue
Block a user