Skip to content

Commit

Permalink
Adds connection stash middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
ksysoev committed Jan 18, 2024
1 parent 073f0f3 commit b25650c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
6 changes: 0 additions & 6 deletions middleware/http/clientip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import (
"strings"
)

type ContextKey uint

const (
ClientIP ContextKey = iota
)

type Provider uint8

const (
Expand Down
9 changes: 9 additions & 0 deletions middleware/http/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package http

type ContextKey uint

const (
NoKey ContextKey = iota
ClientIP
Stash
)
19 changes: 19 additions & 0 deletions middleware/http/stash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package http

import (
"context"
"net/http"
"sync"
)

func NewStashMiddleware() func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, Stash, &sync.Map{})
r = r.WithContext(ctx)

next.ServeHTTP(w, r)
})
}
}

0 comments on commit b25650c

Please sign in to comment.