Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
string keyer (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiko authored Aug 27, 2019
1 parent d4b0cf4 commit ff0e285
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type (
//KeyerFunc func(string) ([]string, error)
KeyFunc func() (Key, error)

// KeyerFunc transforms string to key
KeyerFunc func(string) (Key, error)

// Keyer interface for entity containing logic of its key creation
Keyer interface {
Key() (Key, error)
Expand Down Expand Up @@ -403,19 +406,19 @@ func KeyError(key *TransformedKey) error {
return errors.New(strings.Join(key.Origin, ` | `))
}

//type stringKeyer struct {
// str string
// keyer KeyerFunc
//}
//
//func (sk stringKeyer) Key() ([]string, error) {
// return sk.keyer(sk.str)
//}
//
//// StringKeyer constructor for struct implementing Keyer interface
//func StringKeyer(str string, keyer KeyerFunc) Keyer {
// return stringKeyer{str, keyer}
//}
type stringKeyer struct {
str string
keyer KeyerFunc
}

func (sk stringKeyer) Key() (Key, error) {
return sk.keyer(sk.str)
}

// StringKeyer constructor for struct implementing Keyer interface
func StringKeyer(str string, keyer KeyerFunc) Keyer {
return stringKeyer{str, keyer}
}

// Get data by key from private state, trying to convert to target interface
func (s *Impl) GetPrivate(collection string, entry interface{}, config ...interface{}) (interface{}, error) {
Expand Down

0 comments on commit ff0e285

Please sign in to comment.