gosimple/slug 生成url 友好的slug
gosimple/slug 是一个golang 包,可以用开生成支持多语言的url 友好的slug
参考使用
package main
import (
"fmt"
"github.com/gosimple/slug"
)
func main() {
text := slug.Make("Hellö Wörld хелло ворлд")
fmt.Println(text) // Will print: "hello-world-khello-vorld"
someText := slug.Make("影師")
fmt.Println(someText) // Will print: "ying-shi"
enText := slug.MakeLang("This & that", "en")
fmt.Println(enText) // Will print: "this-and-that"
deText := slug.MakeLang("Diese & Dass", "de")
fmt.Println(deText) // Will print: "diese-und-dass"
slug.Lowercase = false // Keep uppercase characters
deUppercaseText := slug.MakeLang("Diese & Dass", "de")
fmt.Println(deUppercaseText) // Will print: "Diese-und-Dass"
slug.CustomSub = map[string]string{
"water": "sand",
}
textSub := slug.Make("water is hot")
fmt.Println(textSub) // Will print: "sand-is-hot"
}
说明
好多项目都依赖了gosimple/slug ,而且如果我们是做cms 使用此包生成url 也是一个不错的