A simple Go package to convert strings into URL-friendly slugs.
go get github.com/iniadil/go-slugify@latestHere is a basic usage example:
import "github.com/iniadil/go-slugify/slugify"
slug, err := slugify.Slugify("Slugify - make !@#$%^&*()")
if err == nil {
fmt.Println(slug) // Output: slugify-make
}// Using a custom separator
newSlug, _ := slugify.Slugify("a title with separator", slugify.WithSeparator("/"))
fmt.Println(newSlug) // Output: slugify/makeSlugify(text string, opts ...Option) (string, error)- Converts the input string to a slug.
- Options:
WithSeparator(sep string): set a custom separator.WithLowerCase(bool): set lowercase (default true)
go-slugify has been benchmarked to demonstrate its performance.
On a macOS machine with an Intel i7 CPU, the results show:
- Short strings: ~300 ns/op
- Long strings: ~580 ns/op
- Custom separator: ~320 ns/op
- Without lowercase conversion: ~228 ns/op
These results indicate that:
- Fast: All operations complete in sub-microsecond time.
- Lightweight: Minimal overhead, suitable for high-performance applications.
- Consistent: Options like custom separators or disabling lowercase do not introduce significant cost.
This makes go-slugify a reliable choice for projects that require efficient slug generation, such as REST APIs, microservices, or CLI tools.
This project is open-source and licensed under the MIT License.
You are free to use, modify, and distribute it with attribution.
Contributions are welcome!
Feel free to open an issue or submit a pull request to improve this project.
Maintained by iniadil