From 4e196b52123df8df5a3eae3bc1622e504cc797dc Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Mon, 10 Jul 2017 17:09:27 +1000 Subject: [PATCH 1/3] add goreleaser for packaging --- .goreleaser.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .goreleaser.yml diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..475b17f --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,6 @@ +builds: + - binary: csp-collector + goos: + - linux + goarch: + - amd64 From 00b0f016b009508c92114a74822708bbc92df478 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Mon, 10 Jul 2017 17:11:16 +1000 Subject: [PATCH 2/3] add darwin builds --- .goreleaser.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 475b17f..ab64292 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -2,5 +2,6 @@ builds: - binary: csp-collector goos: - linux + - darwin goarch: - amd64 From a46b3005db44cdc73cd8f466ae8f9f5c41996c72 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Fri, 14 Jul 2017 07:58:03 +1000 Subject: [PATCH 3/3] Add `-debug` flag Sometimes you want to know what is going on under the hood without breaking out a debugger. Other times you really don't care. To facilitate both of these needs, I've created a `debug` logger that will handle outputting it correctly and conditionally outputted it based on the flags at runtime. --- csp_collector.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/csp_collector.go b/csp_collector.go index 05fcba2..5d37447 100644 --- a/csp_collector.go +++ b/csp_collector.go @@ -2,9 +2,12 @@ package main import ( "encoding/json" + "flag" "fmt" + "io" "log" "net/http" + "os" "strings" "time" ) @@ -20,8 +23,27 @@ type CSPReport struct { } `json:"csp-report"` } +var ( + Debug *log.Logger + + // Flag for toggling verbose output. + debugFlag bool +) + +func setupDebugLogger(debugHandle io.Writer) { + Debug = log.New(debugHandle, "[DEBUG] ", log.Lmicroseconds) +} + func main() { - log.Println("Starting up...") + setupDebugLogger(os.Stdout) + + flag.BoolVar(&debugFlag, "debug", false, "Output additional logging for debugging") + flag.Parse() + + if debugFlag { + Debug.Println("Starting up...") + } + http.HandleFunc("/", handleViolationReport) log.Fatal(http.ListenAndServe(":8080", nil)) }