func newPost(title string, body string, user int64) Post { // Convert Chinese charaters into Pinyin pinyinTitle := pinyin.Convert(title) //let's make pretty urls from title reg, err := regexp.Compile("[^A-Za-z0-9]+") if err != nil { log.Fatal(err) } prettyurl := reg.ReplaceAllString(pinyinTitle, "-") prettyurl = strings.ToLower(strings.Trim(prettyurl, "-")) return Post{ Created: time.Now().Unix(), Title: title, Body: body, UserId: user, Url: prettyurl, } }
func DemoPinyin() { println(pinyin.Convert("hello,世界!")) }
func main() { println(pinyin.Convert("hello,世界!")) }