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