Home
Crypto
Create
func safehtml di List dan TagView di sederhanakan jadi satu fungsi tersendiri #webkoe #go <pre> func safehtml(text string) template.HTML { text = text + " " text = strings.Replace(text, "<", "<", -1) text = strings.Replace(text, ">", ">", -1) text = strings.Replace(text, "<pre>", "<pre>", -1) text = strings.Replace(text, "</pre>", "</pre>", -1) regexPagar, _ := regexp.Compile(tagPattern) tags := regexPagar.FindAllString(text, -1) for _ , value := range tags { tagAscii := strings.Replace(value, "#", "#", 1) tagOnly := strings.Replace(value, "#", "", 1) text = strings.Replace(text, value, "<a href='/tag/" + tagOnly + "'>" + tagAscii + "</a>", 1) } return template.HTML(text) } </pre> dan ini yang memanggil <pre> func WkListHandler(w http.ResponseWriter, r *http.Request) { funcMap := template.FuncMap{ "safehtml": safehtml , } templates := template.Must(template.New("").Funcs(funcMap).ParseFiles(templatePath + "webkoe-base.html", templatePath + "webkoe-list.html")) var results []Blog err = MCol.Find(bson.M{}).Sort("-date").Limit(1000000000000).All(&results) if err != nil { panic(err) } // var finalResult []tagView // fmt.Println(reflect.TypeOf(results)) err := templates.ExecuteTemplate(w, "base", results) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } } </pre> #script #webkoe #go #enlightenment #nice