Package filenamer
Package "Filenamer" provides a set of methods for filename manipulation.
It's a very simple API for adding custom prefixes
and suffixes to your base filename such as timestamps,
random strings etc. Very useful when working with file
uploads and you need to genereate unique filenames for your uploads.
Installation
go get -u github.com/artdarek/filenamer
Examples
package main
import (
"github.com/artdarek/filenamer"
"fmt"
)
func main() {
fn := filenamer.New("test file.jpg")
fn.CleanIt()
name := fn.Get()
fmt.Println(name)
}
package main
import (
"github.com/artdarek/filenamer"
"fmt"
)
func main() {
fn := filenamer.New("test fil e.jpg")
fn.CleanIt()
fn.WithReplacement("test", "example")
fn.WithRandomPrefix(10)
fn.WithRandomSuffix(10)
fn.SeparateWith("-")
fn.WithTimestamp()
fn.WithCustomPrefix("image")
fn.WithCustomSuffix("renamed")
fn.WithExtension("png")
fn.WithExtensionRemoved()
fn.HashIt()
name := fn.Get()
fmt.Println(name)
}
See some more examples in cmd/examples/main.go
. You can test them in action by running following command:
go run cmd/examples/main.go
Contributing
Pull requests, bug fixes and issue reports are welcome.
Before proposing a change, please discuss your change by raising an issue.