Skip to content

Commit

Permalink
Add README example
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Oct 27, 2021
1 parent 898fd47 commit dc53c34
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![reportcard-img]][reportcard-url]
[![coverage-img]][coverage-url]

Go HTTP middleware to filter clients by IP.
Go HTTP middleware to filter clients by IP address.

## Rationale

Expand All @@ -31,7 +31,25 @@ go get github.com/cristalhq/ipfilterware
## Example

```go
TODO
// your handler or mux/router
var myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// do something good
w.WriteHeader(http.StatusOK)
})

// some IPs to allow (see fetchers_test.go for DNS and proxy helpers)
ips := []string{"10.20.30.40", "100.100.99.1", "42.42.42.42"}

// create ipfilterware handler to pass allowed IPs to myHandler
handler, err := ipfilterware.New(myHandler, &ipfilterware.Config{
AllowedIPs: ips,
})
if err != nil {
panic(err)
}

// use handler as a router or middleware
http.ListenAndServe(":8080", handler)
```

## Documentation
Expand Down

0 comments on commit dc53c34

Please sign in to comment.