<commit_before># gatekeeper
[![GoDoc](https://godoc.org/github.com/otraore/gatekeeper?status.svg)](https://godoc.org/github.com/otraore/gatekeeper)
[![Go Report Card](https://goreportcard.com/badge/github.com/otraore/gatekeeper)](https://goreportcard.com/report/github.com/otraore/gatekeeper)
![License](https://img.shields.io/badge/License-MIT-blue.svg)

Hydra middleware for golang web frameworks. Inspired by [gin-hydra](https://github.com/janekolszak/gin-hydra), it current has support for [gin](https://github.com/gin-gonic/gin), [echo](https://github.com/labstack/echo), and [goa](https://github.com/goadesign/goa). More framework support is planned.

## Install
``` bash
go get -u github.com/otraore/gatekeeper
```

## Gin
``` go
import (
    "github.com/gin-gonic/gin"
    "github.com/ory-am/hydra/firewall"
    hydra "github.com/ory-am/hydra/sdk"
    "github.com/otraore/gatekeeper"
)

func handler(c *gin.Context) {
	ctx := c.Get("hydra").(*firewall.Context)
	// Now you can access ctx.Subject etc.
}

func main(){
	// Initialize Hydra
	hc, err := hydra.Connect(
		hydra.ClientID("..."),
		hydra.ClientSecret("..."),
		hydra.ClusterURL("..."),
	)

	if err != nil {
		panic(err)
	}
	
	// Create a gatekeeper instance for Gin
	gk := gatekeeper.NewGin(hc)

 	r := gin.Default()
	r.GET("/protected", gk.ScopesRequired("scope1", "scope2"), handler)
	r.Run()
}
```
## Echo
``` go
import (
    "github.com/labstack/echo"
    "github.com/labstack/echo/engine/standard"
    "github.com/ory-am/hydra/firewall"
    hydra "github.com/ory-am/hydra/sdk"
    "github.com/otraore/gatekeeper"
)

func handler(c *gin.Context) {
	ctx := c.Get("hydra").(*firewall.Context)
	// Now you can access ctx.Subject etc.
}

func main(){
	// Initialize Hydra
	hc, err := hydra.Connect(
		hydra.ClientID("..."),
		hydra.ClientSecret("..."),
		hydra.ClusterURL("..."),
	)

	if err != nil {
		panic(err)
	}
	
	// Create a gatekeeper instance for Echo
	gk := gatekeeper.NewGin(hc)

 	e := echo.Default()
	e.GET("/protected", handler, gk.ScopesRequired("scope1", "scope2"),)<commit_msg>Fix echo example in the README<commit_after># gatekeeper
[![GoDoc](https://godoc.org/github.com/otraore/gatekeeper?status.svg)](https://godoc.org/github.com/otraore/gatekeeper)
[![Go Report Card](https://goreportcard.com/badge/github.com/otraore/gatekeeper)](https://goreportcard.com/report/github.com/otraore/gatekeeper)
![License](https://img.shields.io/badge/License-MIT-blue.svg)

Hydra middleware for golang web frameworks. Inspired by [gin-hydra](https://github.com/janekolszak/gin-hydra), it current has support for [gin](https://github.com/gin-gonic/gin), [echo](https://github.com/labstack/echo), and [goa](https://github.com/goadesign/goa). More framework support is planned.

## Install
``` bash
go get -u github.com/otraore/gatekeeper
```

## Gin
``` go
import (
    "github.com/gin-gonic/gin"
    "github.com/ory-am/hydra/firewall"
    hydra "github.com/ory-am/hydra/sdk"
    "github.com/otraore/gatekeeper"
)

func handler(c *gin.Context) {
	ctx := c.Get("hydra").(*firewall.Context)
	// Now you can access ctx.Subject etc.
}

func main(){
	// Initialize Hydra
	hc, err := hydra.Connect(
		hydra.ClientID("..."),
		hydra.ClientSecret("..."),
		hydra.ClusterURL("..."),
	)

	if err != nil {
		panic(err)
	}
	
	// Create a gatekeeper instance for Gin
	gk := gatekeeper.NewGin(hc)

 	r := gin.Default()
	r.GET("/protected", gk.ScopesRequired("scope1", "scope2"), handler)
	r.Run()
}
```
## Echo
``` go
import (
    "github.com/labstack/echo"
    "github.com/labstack/echo/engine/standard"
    "github.com/ory-am/hydra/firewall"
    hydra "github.com/ory-am/hydra/sdk"
    "github.com/otraore/gatekeeper"
)

func handler(c echo.Context) {
	ctx := c.Get("hydra").(*firewall.Context)
	// Now you can access ctx.Subject etc.
}

func main(){
	// Initialize Hydra
	hc, err := hydra.Connect(
		hydra.ClientID("..."),
		hydra.ClientSecret("..."),
		hydra.ClusterURL("..."),
	)

	if err != nil {
		panic(err)
	}
	
	// Create a gatekeeper instance for Echo
	gk := gatekeeper.NewGin(hc)

 	e := echo.Default()
	e.GET("/protected", handler, gk.ScopesRequired("scope1", "scope2"),)
{'fraction_non_alphanumeric': 0.19294856314899783, 'fraction_numerical': 0.001931900507123883, 'mean_word_length': 3.771889400921659, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2030106', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1546, 'n_words': 268}