66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package nomino
|
|
|
|
import "fmt"
|
|
|
|
func ExampleWithGenerator_custom_generator() {
|
|
gen := func(*Config) (string, error) {
|
|
return "hello", nil
|
|
}
|
|
option := WithGenerator(gen)
|
|
|
|
str, _ := Make(NewConfig(option))
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(NewConfig(option, WithoutExtension()))
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// hello.txt
|
|
// hello
|
|
}
|
|
|
|
func ExampleSlug() {
|
|
conf := NewConfig(WithGenerator(Slug()), WithOriginal("My name is Jimmy"))
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output: my-name-is-jimmy.txt
|
|
}
|
|
|
|
func ExampleSlugWithLang() {
|
|
conf := NewConfig(WithGenerator(SlugWithLang("de")), WithOriginal("Diese & Dass"))
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output: diese-und-dass.txt
|
|
}
|
|
|
|
func ExampleHash_mD5() {
|
|
conf := NewConfig(
|
|
WithOriginal("foobar"),
|
|
WithGenerator(Hash(MD5)),
|
|
)
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
// Output: 3858f62230ac3c915f300c664312c63f.txt
|
|
}
|
|
|
|
func ExampleHash_sHA1() {
|
|
conf := NewConfig(
|
|
WithOriginal("foobar"),
|
|
WithGenerator(Hash(SHA1)),
|
|
)
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
// Output: 8843d7f92416211de9ebb963ff4ce28125932878.txt
|
|
}
|
|
|
|
func ExampleHash_sHA256() {
|
|
conf := NewConfig(
|
|
WithOriginal("foobar"),
|
|
WithGenerator(Hash(SHA256)),
|
|
)
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
// Output: c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2.txt
|
|
}
|