Skip to content

Commit

Permalink
Made AddOptions more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
v3nom committed Jan 23, 2021
1 parent 7b8b260 commit d50cb09
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.14.x
- 1.15.x

git:
depth: 1
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# middleware [![Build Status](https://travis-ci.com/v3nom/middleware.svg?branch=master)](https://travis-ci.com/v3nom/middleware)
Useful middlewares for [Pipes](https://github.com/v3nom/pipes) library. Most middlewares are made specifically for the Google App Engine environment. Others are universally useful.
Useful middlewares for [Pipes](https://github.com/v3nom/pipes) library.

## What's in the box?

### Context middleware
Creates Google App Engine Context and passes it forward.
Creates request Context and passes it forward.

### Panic recovery middleware
Handles panic and allows to provide user friendly message or redirect to error page using http.ResponseWriter.
Expand Down
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Context(ctx context.Context, w http.ResponseWriter, r *http.Request, next p
}

// AddOptions adds context options
func AddOptions(options map[pipes.ContextKey]interface{}) pipes.Middleware {
func AddOptions(options map[interface{}]interface{}) pipes.Middleware {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, next pipes.Next) {
if options != nil {
for k, v := range options {
Expand Down
9 changes: 5 additions & 4 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ func TestContextMiddleware(t *testing.T) {
})
}

var aKey pipes.ContextKey = "akey"
var bKey pipes.ContextKey = "bkey"

func TestAddContextMiddleware(t *testing.T) {
options := map[pipes.ContextKey]interface{}{
aKey := pipes.ContextKey("akey")
type NewContextKey string
bKey := NewContextKey("bkey")

options := map[interface{}]interface{}{
aKey: "a",
bKey: "b",
}
Expand Down
2 changes: 1 addition & 1 deletion cookieauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type cookieDecoder = func(context.Context, *http.Cookie) map[string]string
type userFactory = func(map[string]string) interface{}

// User context key
const User pipes.ContextKey = "User"
const User = pipes.ContextKey("User")

// CookieAuth creates cookie auth middleware.
func CookieAuth(authCookieName string, cookieDec cookieDecoder, userFac userFactory) pipes.Middleware {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/v3nom/middleware

go 1.13
go 1.15

require github.com/v3nom/pipes v0.0.0-20190518131510-1defa98b0fbd
require github.com/v3nom/pipes v1.0.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/v3nom/pipes v0.0.0-20190518131510-1defa98b0fbd h1:wKDgNE+pFtlurcWwALtrPtIM9FcUqL4Hr4TMzGEji+U=
github.com/v3nom/pipes v0.0.0-20190518131510-1defa98b0fbd/go.mod h1:Zc+O1Nb8y/5iGnHoE9dsXt9Jxyd4xewp8gm6BXfOey0=
github.com/v3nom/pipes v1.0.0 h1:Q/RtQCcorYNOSRev6YD0Na9tdb4jiagh/VlKeCcN7m8=
github.com/v3nom/pipes v1.0.0/go.mod h1:/7Q4+L2R8UrmARMMF849Y8YrHwbYJxDFzqCVL6kVnSk=

0 comments on commit d50cb09

Please sign in to comment.