From d50cb09cc985ea3e4cffc702836db394bce1e8d3 Mon Sep 17 00:00:00 2001 From: Tomas Date: Sat, 23 Jan 2021 13:14:57 +0100 Subject: [PATCH] Made AddOptions more generic --- .travis.yml | 2 +- README.md | 4 ++-- context.go | 2 +- context_test.go | 9 +++++---- cookieauth.go | 2 +- go.mod | 4 ++-- go.sum | 2 ++ 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2a14e66..8c10fdf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - 1.14.x + - 1.15.x git: depth: 1 diff --git a/README.md b/README.md index 91acc36..939b5e9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/context.go b/context.go index 1819fe3..8b39ffd 100644 --- a/context.go +++ b/context.go @@ -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 { diff --git a/context_test.go b/context_test.go index b6d769a..75e3874 100644 --- a/context_test.go +++ b/context_test.go @@ -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", } diff --git a/cookieauth.go b/cookieauth.go index 624aa99..95af9f3 100644 --- a/cookieauth.go +++ b/cookieauth.go @@ -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 { diff --git a/go.mod b/go.mod index 0e92fe2..40f0a2d 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 6e7e6fd..52ea086 100644 --- a/go.sum +++ b/go.sum @@ -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=