Skip to content

Commit

Permalink
fix: rename NewCachedToken to New
Browse files Browse the repository at this point in the history
  • Loading branch information
shaj13 committed May 22, 2020
1 parent 6b0fcbb commit a69cb5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions auth/strategies/bearer/cached.go
Expand Up @@ -19,10 +19,10 @@ const CachedStrategyKey = auth.StrategyKey("Bearer.Cached.Strategy")
// Use NoOpAuthenticate instead to refresh/mangae token directly using cache or Append function.
type Authenticate func(ctx context.Context, r *http.Request, token string) (auth.Info, error)

// NewCachedToken return new auth.Strategy.
// New return new auth.Strategy.
// The returned strategy caches the invocation result of authenticate function, See Authenticate.
// Use NoOpAuthenticate to refresh/mangae token directly using cache or Append function, See NoOpAuthenticate.
func NewCachedToken(auth Authenticate, c store.Cache) auth.Strategy {
func New(auth Authenticate, c store.Cache) auth.Strategy {
if auth == nil {
panic("Authenticate Function required and can't be nil")
}
Expand Down
4 changes: 2 additions & 2 deletions auth/strategies/bearer/cached_test.go
Expand Up @@ -85,12 +85,12 @@ func TestNewCahced(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
if tt.panic {
assert.Panics(t, func() {
NewCachedToken(tt.authFunc, tt.cache)
New(tt.authFunc, tt.cache)
})
return
}

strategy := NewCachedToken(tt.authFunc, tt.cache)
strategy := New(tt.authFunc, tt.cache)
r, _ := http.NewRequest("GET", "/", nil)
r.Header.Set("Authorization", "Bearer "+tt.token)
_ = tt.cache.Store(tt.token, tt.info, r)
Expand Down
6 changes: 3 additions & 3 deletions auth/strategies/bearer/example_test.go
Expand Up @@ -47,7 +47,7 @@ func ExampleNewStatic() {
// <nil> 1
}

func ExampleNewCachedToken() {
func ExampleNew() {
authFunc := Authenticate(func(ctx context.Context, r *http.Request, token string) (auth.Info, error) {
fmt.Print("authFunc called ")
if token == "90d64460d14870c08c81352a05dedd3465940a7" {
Expand All @@ -57,7 +57,7 @@ func ExampleNewCachedToken() {
})

cache := store.NewFIFO(time.Minute * 5)
strategy := NewCachedToken(authFunc, cache)
strategy := New(authFunc, cache)

r, _ := http.NewRequest("GET", "/", nil)
r.Header.Set("Authorization", "Bearer 90d64460d14870c08c81352a05dedd3465940a7")
Expand All @@ -76,7 +76,7 @@ func ExampleNewCachedToken() {

func ExampleNoOpAuthenticate() {
cache := store.NewFIFO(time.Microsecond * 500)
strategy := NewCachedToken(NoOpAuthenticate, cache)
strategy := New(NoOpAuthenticate, cache)

// demonstrate a user attempt to login
r, _ := http.NewRequest("GET", "/login", nil)
Expand Down

0 comments on commit a69cb5e

Please sign in to comment.