Skip to content

Commit

Permalink
Updates to WithNewWookie (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkajla12 authored Sep 29, 2023
1 parent f052204 commit 4ac4e2d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/wookie/wookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (
const HeaderName = "Warrant-Token"
const Latest = "latest"

type WarrantTokenCtxKey struct{}
type WookieCtxKey struct{}
type warrantTokenCtxKey struct{}
type wookieCtxKey struct{}

func WarrantTokenMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
headerVal := r.Header.Get(HeaderName)
if headerVal != "" {
warrantTokenCtx := context.WithValue(r.Context(), WarrantTokenCtxKey{}, headerVal)
warrantTokenCtx := context.WithValue(r.Context(), warrantTokenCtxKey{}, headerVal)
next.ServeHTTP(w, r.WithContext(warrantTokenCtx))
return
}
Expand All @@ -41,7 +41,7 @@ func WarrantTokenMiddleware(next http.Handler) http.Handler {

// Returns true if ctx contains wookie set to 'latest', false otherwise.
func ContainsLatest(ctx context.Context) bool {
if val, ok := ctx.Value(WarrantTokenCtxKey{}).(string); ok {
if val, ok := ctx.Value(warrantTokenCtxKey{}).(string); ok {
if val == Latest {
return true
}
Expand All @@ -50,7 +50,7 @@ func ContainsLatest(ctx context.Context) bool {
}

func GetWookieFromRequestContext(ctx context.Context) (*Token, error) {
wookieCtxVal := ctx.Value(WookieCtxKey{})
wookieCtxVal := ctx.Value(wookieCtxKey{})
if wookieCtxVal == nil {
//nolint:nilnil
return nil, nil
Expand All @@ -66,12 +66,12 @@ func GetWookieFromRequestContext(ctx context.Context) (*Token, error) {

// Return a context with Warrant-Token set to 'latest'.
func WithLatest(parent context.Context) context.Context {
return context.WithValue(parent, WarrantTokenCtxKey{}, Latest)
return context.WithValue(parent, warrantTokenCtxKey{}, Latest)
}

// Return context with wookie set to specified Token.
func WithWookie(parent context.Context, wookie *Token) context.Context {
return context.WithValue(parent, WookieCtxKey{}, *wookie)
return context.WithValue(parent, wookieCtxKey{}, *wookie)
}

func AddAsResponseHeader(w http.ResponseWriter, token *Token) {
Expand Down

0 comments on commit 4ac4e2d

Please sign in to comment.