Go abstraction for hashing a string
$ go get github.com/garavan/hash-go
import (
hash "github.com/garavan/hash-go"
bcryptHash "github.com/garavan/hash-go/bcrypt"
)
type userService struct {
hash hash.Hash
}
func NewUserService(hash hash.Hash) User {
return &userService{hash}
}
func (u *userService) Create(data map[string]string) error {
passHashed, err := u.hash.Make(data["password"])
...
}
userSrv := NewUserService(bcryptHash.DefaultBcryptHash())
...
$ go test ./...