Skip to content

Instantly share code, notes, and snippets.

@kyoh86
Last active May 16, 2016 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyoh86/66d3bebcc6c9316b251e to your computer and use it in GitHub Desktop.
Save kyoh86/66d3bebcc6c9316b251e to your computer and use it in GitHub Desktop.
package main
// Ellipsis a text
func Ellipsis(length int, text string) string {
r := []rune(text)
if len(r) > length {
return string(r[0:length]) + "..."
}
return text
}
package main
// Ellipsis a text
func Ellipsis(length int, text string) string {
r := []rune(text)
if len(r) > length {
return string(r[0:length]) + "..."
}
return text
}
package main
import (
"bytes"
"fmt"
"text/template"
)
func main() {
var buf bytes.Buffer
template.New("text").
Funcs(template.FuncMap{"ellipsis": Ellipse}).
Parse(`{{.value | ellipsis 5}}`).
Execute(buf, map[string]string{"value": "みんみんみらくる☆"})
fmt.Println(buf.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment