package cv import ( "html/template" "log" "net/url" "strings" ) func (g *generator) setupTemplate() error { tpl := template.New("cv.gohtml") tpl.Funcs(template.FuncMap{ "prettyUrl": prettyUrl, "notEmpty": notEmpty, }) tpl, err := tpl.ParseFiles("templates/cv.gohtml") if err != nil { return err } g.tpl = tpl return nil } func notEmpty(v interface{}) bool { switch t := v.(type) { case string: return len(t) > 0 case []string: return len(t) > 0 } return true } func prettyUrl(u string) string { v, err := url.Parse(u) if err != nil { log.Println("Error:", err) return u } if strings.HasPrefix(v.Host, "www.") { v.Host = strings.TrimPrefix(v.Host, "www.") } v.Path = strings.TrimRight(v.Path, "/") return v.Host + v.Path }