Beispiel #1
0
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,
	}
}
Beispiel #2
0
func DemoPinyin() {
	println(pinyin.Convert("hello,世界!"))
}
Beispiel #3
0
func main() {
	println(pinyin.Convert("hello,世界!"))
}