From a955f01b9337770056d7e91583489ab26a0e5aca Mon Sep 17 00:00:00 2001 From: Rajiv Ranjan Singh Date: Fri, 1 Oct 2021 23:11:50 +0530 Subject: [PATCH 1/3] refactor readme Signed-off-by: Rajiv Ranjan Singh --- .github/workflows/codesee-arch-diagram.yml | 12 ++++---- README.md | 35 +++++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/.github/workflows/codesee-arch-diagram.yml b/.github/workflows/codesee-arch-diagram.yml index c30d2dc..422ef5a 100644 --- a/.github/workflows/codesee-arch-diagram.yml +++ b/.github/workflows/codesee-arch-diagram.yml @@ -29,8 +29,8 @@ jobs: uses: actions/setup-java@v2 if: ${{ fromJSON(steps.detect-languages.outputs.languages).java }} with: - java-version: '16' - distribution: 'zulu' + java-version: "16" + distribution: "zulu" # CodeSee Maps Go support uses a static binary so there's no setup step required. @@ -38,20 +38,20 @@ jobs: uses: actions/setup-node@v2 if: ${{ fromJSON(steps.detect-languages.outputs.languages).javascript }} with: - node-version: '14' + node-version: "14" - name: Configure Python 3.x uses: actions/setup-python@v2 if: ${{ fromJSON(steps.detect-languages.outputs.languages).python }} with: - python-version: '3.x' - architecture: 'x64' + python-version: "3.x" + architecture: "x64" - name: Configure Ruby '3.x' uses: ruby/setup-ruby@v1 if: ${{ fromJSON(steps.detect-languages.outputs.languages).ruby }} with: - ruby-version: '3.0' + ruby-version: "3.0" # CodeSee Maps Rust support uses a static binary so there's no setup step required. diff --git a/README.md b/README.md index badd8c6..22ebbf8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,14 @@ -# go-watch-middleware +
+

goWatch Middleware

+

+Middleware for an HTTP server in GoLang to watch for unhandled exceptions +

+ + + +
+ +## About Middleware for an HTTP server in GoLang to watch for unhandled exceptions. The middleware provides the following features: @@ -7,30 +17,33 @@ Middleware for an HTTP server in GoLang to watch for unhandled exceptions. The m - Slack alerts in production - Discord alerts in production - Log & display stack trace in development -- Code browser +- Code browser ## Quick Start -A simple wrapper to your HTTP request multiplexer [ServeMux](https://golang.org/pkg/net/http/#ServeMux) to begin development. + +A simple wrapper to your HTTP requests multiplexer [ServeMux](https://golang.org/pkg/net/http/#ServeMux) to begin development. + ```go http.ListenAndServe(":3000", watch.WatchMw(mux)) ``` ## Options + [watch](#go-watch-middleware) uses functional options for various configurations: -Option | Default | Description ----- | :----: | -------- -`WithDevelopment(bool)` | `true` | Set environment as development (true) or production (false). -`WithDebugPath(string)` | `"/watch/debug"` | Path used by `watch` to show in-browser files for debugging (code browser) in development. This option will be silently ignored during production. -`WithEmail(watch.EmailDetails)` | - | Issue email alerts on Failure in Production. This option will be silently ignored during development. -`WithSlack(watch.SlackDetails)` | - | Issue slack alerts on Failure in Production. This option will be silently ignored during development. -`WithDiscord(watch.DiscordDetails)` | - | Issue discord alerts on Failure in Production. This option will be silently ignored during development. +| Option | Default | Description | +| ----------------------------------- | :--------------: | -------------------------------------------------------------------------------------------------------------------------------------------------- | +| `WithDevelopment(bool)` | `true` | Set environment as development (true) or production (false). | +| `WithDebugPath(string)` | `"/watch/debug"` | Path used by `watch` to show in-browser files for debugging (code browser) in development. This option will be silently ignored during production. | +| `WithEmail(watch.EmailDetails)` | - | Issue email alerts on Failure in Production. This option will be silently ignored during development. | +| `WithSlack(watch.SlackDetails)` | - | Issue slack alerts on Failure in Production. This option will be silently ignored during development. | +| `WithDiscord(watch.DiscordDetails)` | - | Issue discord alerts on Failure in Production. This option will be silently ignored during development. | You can find sample usage for these arguments [here](example/main.go). Kindly note that the usage example is a non-compulsive sample representation and may not directly represent your use case. ## Environment? + You can toggle between dev and production using `WithDevelopment` [option](#options). The following are things enabled per environment. - **Production**: Email alerts, Slack alerts, Discord alerts, Log - **Development**: Stack Trace, Code browser (See `WithDebugPath` option), Log - From e28c80f4b1fdc46e6d8d01875596b5db2274e360 Mon Sep 17 00:00:00 2001 From: Rajiv Ranjan Singh Date: Fri, 1 Oct 2021 23:13:03 +0530 Subject: [PATCH 2/3] add gitignore Signed-off-by: Rajiv Ranjan Singh --- .gitignore | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 49438f4..a20f5d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,26 @@ -**out + +# Created by https://www.toptal.com/developers/gitignore/api/go +# Edit at https://www.toptal.com/developers/gitignore?templates=go + +### Go ### +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +### Go Patch ### +/vendor/ +/Godeps/ + +# End of https://www.toptal.com/developers/gitignore/api/go From 533cc6520e44de7e4ee81de0b6593ab8e0d737c7 Mon Sep 17 00:00:00 2001 From: Rajiv Ranjan Singh Date: Fri, 1 Oct 2021 23:13:47 +0530 Subject: [PATCH 3/3] add pre-commit hook Signed-off-by: Rajiv Ranjan Singh --- .pre-commit-hooks.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .pre-commit-hooks.yml diff --git a/.pre-commit-hooks.yml b/.pre-commit-hooks.yml new file mode 100644 index 0000000..92a01f4 --- /dev/null +++ b/.pre-commit-hooks.yml @@ -0,0 +1,7 @@ +- id: golangci-lint + name: golangci-lint + description: Fast linters runner for Go. + entry: golangci-lint run --fix + types: [go] + language: golang + pass_filenames: false