Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add pre-commit hook for golangci-lint #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/codesee-arch-diagram.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,29 @@ 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.

- name: Configure Node.js 14
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.

Expand Down
27 changes: 26 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions .pre-commit-hooks.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 24 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# go-watch-middleware
<div align="center">
<h1>goWatch Middleware</h1>
<p>
Middleware for an HTTP server in GoLang to watch for unhandled exceptions
</p>
<a href="https://github.com/ojaswa1942/go-watch/network/members"><img src="https://img.shields.io/github/forks/iamrajiv/Rain-Simulation?style=flat-square" height="auto" width="auto" /></a>
<a href="https://github.com/ojaswa1942/go-watch/stargazers"><img src="https://img.shields.io/github/stars/iamrajiv/Rain-Simulation?style=flat-square" height="auto" width="auto" /></a>
<a href="https://github.com/ojaswa1942/go-watch/actions/workflows/golangci-lint.yml"><img src="https://github.com/ojaswa1942/go-watch/actions/workflows/golangci-lint.yml/badge.svg?style=flat-square" height="auto" width="auto" /></a>
</div>

## About

Middleware for an HTTP server in GoLang to watch for unhandled exceptions. The middleware provides the following features:

Expand All @@ -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