193 lines
3.3 KiB
Go
193 lines
3.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 ExampleIncremental() {
|
|
conf := NewConfig(WithPrefix("foo"), WithGenerator(Incremental()))
|
|
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// foo_0.txt
|
|
// foo_1.txt
|
|
// foo_2.txt
|
|
}
|
|
|
|
func ExampleIncrementalWithStart() {
|
|
conf := NewConfig(WithPrefix("foo"), WithGenerator(IncrementalWithStart(42)))
|
|
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// foo_42.txt
|
|
// foo_43.txt
|
|
// foo_44.txt
|
|
}
|
|
|
|
func ExampleIncrementalWithStep() {
|
|
conf := NewConfig(WithPrefix("foo"), WithGenerator(IncrementalWithStep(2)))
|
|
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// foo_0.txt
|
|
// foo_2.txt
|
|
// foo_4.txt
|
|
}
|
|
|
|
func ExampleIncrementalWithStartAndStep() {
|
|
conf := NewConfig(WithPrefix("foo"), WithGenerator(IncrementalWithStartAndStep(42, 2)))
|
|
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// foo_42.txt
|
|
// foo_44.txt
|
|
// foo_46.txt
|
|
}
|
|
|
|
func ExampleIncrementalFormat() {
|
|
conf := NewConfig(
|
|
WithPrefix("foo"),
|
|
WithGenerator(IncrementalFormat("%03d")),
|
|
)
|
|
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// foo_000.txt
|
|
// foo_001.txt
|
|
// foo_002.txt
|
|
}
|
|
|
|
func ExampleIncrementalFormatWithStart() {
|
|
conf := NewConfig(
|
|
WithPrefix("foo"),
|
|
WithGenerator(IncrementalFormatWithStart(9, "%02d")),
|
|
)
|
|
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// foo_09.txt
|
|
// foo_10.txt
|
|
}
|
|
|
|
func ExampleIncrementalFormatWithStep() {
|
|
conf := NewConfig(
|
|
WithPrefix("foo"),
|
|
WithGenerator(IncrementalFormatWithStep(10, "%02d")),
|
|
)
|
|
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// foo_00.txt
|
|
// foo_10.txt
|
|
}
|
|
|
|
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
|
|
}
|