Skip to content

Commit

Permalink
fix: option interface honor interface{} instead of startegy for more …
Browse files Browse the repository at this point in the history
…flexibility
  • Loading branch information
shaj13 committed Aug 14, 2020
1 parent c31102b commit 091444e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions auth/strategies/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func NewWithOptions(f AuthenticateFunc, cache store.Cache, opts ...auth.Option)

// SetHash set the hashing algorithm to hash the user password.
func SetHash(h crypto.Hash) auth.Option {
return auth.OptionFunc(func(s auth.Strategy) {
if v, ok := s.(*cachedBasic); ok {
return auth.OptionFunc(func(v interface{}) {
if v, ok := v.(*cachedBasic); ok {
v.hash = h
}
})
Expand Down
8 changes: 4 additions & 4 deletions auth/strategies/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const (
// SetType sets the authentication token type or scheme,
// used for HTTP WWW-Authenticate header.
func SetType(t Type) auth.Option {
return auth.OptionFunc(func(s auth.Strategy) {
switch v := s.(type) {
return auth.OptionFunc(func(v interface{}) {
switch v := v.(type) {
case *Static:
v.Type = t
case *cachedToken:
Expand All @@ -41,8 +41,8 @@ func SetType(t Type) auth.Option {

// SetParser sets the strategy token parser.
func SetParser(p Parser) auth.Option {
return auth.OptionFunc(func(s auth.Strategy) {
switch v := s.(type) {
return auth.OptionFunc(func(v interface{}) {
switch v := v.(type) {
case *Static:
v.Parser = p
case *cachedToken:
Expand Down
8 changes: 4 additions & 4 deletions auth/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ type Strategy interface {
// see https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html and
// https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis.
type Option interface {
Apply(s Strategy)
Apply(v interface{})
}

// OptionFunc implements Option interface.
type OptionFunc func(s Strategy)
type OptionFunc func(v interface{})

// Apply the configuration to the provided strategy.
func (fn OptionFunc) Apply(s Strategy) {
fn(s)
func (fn OptionFunc) Apply(v interface{}) {
fn(v)
}

// Append new Info to a strategy store.
Expand Down

0 comments on commit 091444e

Please sign in to comment.