📝 Add package level example
This commit is contained in:
parent
8f02956ecd
commit
797c616447
1 changed files with 56 additions and 0 deletions
56
examples_test.go
Normal file
56
examples_test.go
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
package nomino_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"codeberg.org/danjones000/nomino"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Define a global Config.
|
||||||
|
func NominoConfig() nomino.Config {
|
||||||
|
return nomino.NewConfig(
|
||||||
|
nomino.WithSeparator("-"),
|
||||||
|
nomino.WithPrefix("upload"),
|
||||||
|
nomino.WithGenerator(nomino.UUID(
|
||||||
|
nomino.UUIDv7,
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// / HandleImgUploads generates new filenames for images with a png extension.
|
||||||
|
func HandleImgUploads(orig string) string {
|
||||||
|
newName, _ := nomino.Make(
|
||||||
|
NominoConfig(),
|
||||||
|
nomino.WithExtension("png"),
|
||||||
|
nomino.WithOriginalSlug(orig),
|
||||||
|
)
|
||||||
|
|
||||||
|
return newName
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleVidUploads generates a new filename for videos.
|
||||||
|
// We ignore the original filename and use a timestamp for the generated part
|
||||||
|
// with a webm extension.
|
||||||
|
func HandleVidUploads() string {
|
||||||
|
newName, _ := nomino.Timestamp(nomino.TimestampUTC()).
|
||||||
|
MakeWithConfig(NominoConfig().AddOptions(
|
||||||
|
nomino.WithExtension("webm"),
|
||||||
|
))
|
||||||
|
return newName
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example shows how to use nomino.
|
||||||
|
func Example() {
|
||||||
|
// Pretend we have an image upload
|
||||||
|
filename := "George"
|
||||||
|
uploadImgName := HandleImgUploads(filename)
|
||||||
|
|
||||||
|
// Upload to storage
|
||||||
|
fmt.Println(uploadImgName)
|
||||||
|
|
||||||
|
// New Video Upload
|
||||||
|
uploadVidName := HandleVidUploads()
|
||||||
|
|
||||||
|
// Upload to storage
|
||||||
|
fmt.Println(uploadVidName)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue