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 { // Here, we use nomino.Make function to generate the filename. // We use our global config, and add in a few extra Options specific to this. 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 { // Because we're using a different Generator, we chose to use the Make method on the Generator. // We add in additional Options with the `AddOptions` method on the `Config` newName, _ := nomino.Timestamp(nomino.TimestampUTC()). MakeWithConfig(NominoConfig().AddOptions( nomino.WithExtension("webm"), )) return newName } // This 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) }