♻️ Replace HashType with Hasher
Compatible with crypto.Hash
This commit is contained in:
parent
1008a064d0
commit
2440f55563
5 changed files with 47 additions and 95 deletions
|
|
@ -1,66 +1,56 @@
|
|||
package nomino_test
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/hmac"
|
||||
"fmt"
|
||||
"hash"
|
||||
|
||||
"codeberg.org/danjones000/nomino"
|
||||
)
|
||||
|
||||
func ExampleSlug() {
|
||||
conf := nomino.NewConfig(
|
||||
nomino.WithOriginal("My name is Jimmy"),
|
||||
nomino.WithGenerator(nomino.Slug()),
|
||||
)
|
||||
str, _ := nomino.Make(conf)
|
||||
str, _ := nomino.Slug().Make(nomino.WithOriginal("My name is Jimmy"))
|
||||
fmt.Println(str)
|
||||
|
||||
// Output: my-name-is-jimmy.txt
|
||||
}
|
||||
|
||||
func ExampleSlug_withLang() {
|
||||
conf := nomino.NewConfig(
|
||||
nomino.WithOriginal("Diese & Dass"),
|
||||
nomino.WithGenerator(nomino.Slug("de")),
|
||||
)
|
||||
|
||||
str, _ := nomino.Make(conf)
|
||||
str, _ := nomino.Slug("de").
|
||||
Make(nomino.WithOriginal("Diese & Dass"))
|
||||
fmt.Println(str)
|
||||
|
||||
// Output: diese-und-dass.txt
|
||||
}
|
||||
|
||||
func ExampleHash_mD5() {
|
||||
conf := nomino.NewConfig(
|
||||
nomino.WithOriginal("foobar"),
|
||||
nomino.WithGenerator(
|
||||
nomino.Hash(nomino.HashMD5),
|
||||
),
|
||||
)
|
||||
str, _ := nomino.Make(conf)
|
||||
str, _ := nomino.Hash(crypto.MD5).
|
||||
Make(nomino.WithOriginal("foobar"))
|
||||
fmt.Println(str)
|
||||
// Output: 3858f62230ac3c915f300c664312c63f.txt
|
||||
}
|
||||
|
||||
func ExampleHash_sHA1() {
|
||||
conf := nomino.NewConfig(
|
||||
nomino.WithOriginal("foobar"),
|
||||
nomino.WithGenerator(
|
||||
nomino.Hash(nomino.HashSHA1),
|
||||
),
|
||||
)
|
||||
str, _ := nomino.Make(conf)
|
||||
str, _ := nomino.Hash(crypto.SHA1).
|
||||
Make(nomino.WithOriginal("foobar"))
|
||||
fmt.Println(str)
|
||||
// Output: 8843d7f92416211de9ebb963ff4ce28125932878.txt
|
||||
}
|
||||
|
||||
func ExampleHash_sHA256() {
|
||||
conf := nomino.NewConfig(
|
||||
nomino.WithOriginal("foobar"),
|
||||
nomino.WithGenerator(
|
||||
nomino.Hash(nomino.HashSHA256),
|
||||
),
|
||||
)
|
||||
str, _ := nomino.Make(conf)
|
||||
str, _ := nomino.Hash(crypto.SHA256).
|
||||
Make(nomino.WithOriginal("foobar"))
|
||||
fmt.Println(str)
|
||||
// Output: c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2.txt
|
||||
}
|
||||
|
||||
func ExampleHashingFunc_hMAC() {
|
||||
var hasher nomino.HashingFunc = func() hash.Hash {
|
||||
return hmac.New(crypto.SHA1.New, []byte("hello"))
|
||||
}
|
||||
g := nomino.Hash(hasher)
|
||||
str, _ := g.Make(nomino.WithOriginal("foobar"))
|
||||
fmt.Println(str)
|
||||
// Output: 85f767c284c80a3a59a9635194321d20dd90f31b.txt
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue