storage/hash/hash.go
Vasiliy Tolstov 83f9fa19ad initial import
Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
2018-03-22 13:38:56 +03:00

35 lines
578 B
Go

package hash
import (
"fmt"
"hash"
"strings"
)
var hashTypes map[string]hash.Hash
func init() {
hashTypes = make(map[string]hash.Hash)
}
func RegisterHash(engine string, hash hash.Hash) {
hashTypes[engine] = hash
}
func New(htype string) (hash.Hash, error) {
hash, ok := hashTypes[htype]
if !ok {
return nil, fmt.Errorf("unknown hash type %s. only %s supported", htype, strings.Join(HashTypes(), ","))
}
return hash, nil
}
func HashTypes() []string {
var htypes []string
for htype, _ := range hashTypes {
htypes = append(htypes, htype)
}
return htypes
}