Skip to content

Commit

Permalink
Add Makefile to facilitate building and testing.
Browse files Browse the repository at this point in the history
Add --version, which will be taken from git tag or HEAD

Ran "go mod vendor" to fix some issues.
  • Loading branch information
middelink committed Nov 5, 2020
1 parent d51cbde commit 21c7556
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.PHONY: clean build test

MAIN_DIRECTORY := .
BIN_OUTPUT := $(if $(filter $(shell go env GOOS), windows), mikrotik-fwban.exe, mikrotik-fwban)

TAG_NAME := $(shell git tag -l --contains HEAD)
SHA := $(shell git rev-parse HEAD)
VERSION := $(if $(TAG_NAME),$(TAG_NAME),$(SHA))

default: clean test build

clean:
@echo BIN_OUTPUT: ${BIN_OUTPUT}
rm -rf ${BIN_OUTPUT} coverage.out

build: clean
@echo Version: $(VERSION)
go build -v -trimpath -ldflags '-X "main.version=${VERSION}"' -o ${BIN_OUTPUT} ${MAIN_DIRECTORY}

test: clean
go test -cover ./...
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/middelink/mikrotik-fwban

go 1.15

require (
github.com/google/gops v0.3.5
github.com/howeyc/fsnotify v0.9.0
Expand All @@ -9,4 +11,5 @@ require (
gopkg.in/routeros.v2 v2.0.0-20171228113335-2dc19c12445c
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.2.2
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net"
"os"
"os/signal"
"runtime"
"strings"
"syscall"
"time"
Expand All @@ -41,8 +42,10 @@ var (
debug = flag.Bool("debug", false, "Be absolutely staggering in our logging.")
verbose = flag.Bool("verbose", false, "Be more verbose in our logging.")
configchanged = flag.Bool("configchange", false, "Exit process when config file changes.")
hasVersion = flag.Bool("version", false, "output version information and exit")

cfg Config
version = "dev"
cfg Config
)

func setFlags(flags ...string) error {
Expand All @@ -61,6 +64,11 @@ func setFlags(flags ...string) error {

func main() {
setFlags()
if *hasVersion {
fmt.Fprintf(flag.CommandLine.Output(), "mikrotik-fwban version %s %s/%s\n", version, runtime.GOOS, runtime.GOARCH)
return
}

var err error
cfg, err = newConfigFile(*filename, uint16(*port), Duration(*blocktime), *autodelete, *verbose)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
# github.com/google/gops v0.3.5
## explicit
github.com/google/gops/agent
github.com/google/gops/internal
github.com/google/gops/signal
# github.com/howeyc/fsnotify v0.9.0
## explicit
github.com/howeyc/fsnotify
# github.com/jeromer/syslogparser v0.0.0-20180622150051-323c7ad120db
## explicit
github.com/jeromer/syslogparser
github.com/jeromer/syslogparser/rfc3164
github.com/jeromer/syslogparser/rfc5424
# github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1
## explicit
github.com/kardianos/osext
# gopkg.in/gcfg.v1 v1.2.3
## explicit
gopkg.in/gcfg.v1
gopkg.in/gcfg.v1/scanner
gopkg.in/gcfg.v1/token
gopkg.in/gcfg.v1/types
# gopkg.in/routeros.v2 v2.0.0-20171228113335-2dc19c12445c
## explicit
gopkg.in/routeros.v2
gopkg.in/routeros.v2/proto
# gopkg.in/warnings.v0 v0.1.2
## explicit
gopkg.in/warnings.v0
# gopkg.in/yaml.v2 v2.2.2
## explicit
gopkg.in/yaml.v2
# launchpad.net/gocheck v0.0.0-20140225173054-000000000087
## explicit

0 comments on commit 21c7556

Please sign in to comment.