Mon, 23 Mar 2015 3:46 pm
func safehtml di List dan TagView di sederhanakan jadi satu fungsi tersendiri #webkoe #go
      func safehtml(text string) template.HTML { 

          text = text + " "
          text = strings.Replace(text, "<", "<", -1)   
          text = strings.Replace(text, ">", ">", -1) 
            
          text = strings.Replace(text, "
", "
", -1) 
          text = strings.Replace(text, "
", "
", -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, "" + tagAscii + "", 1) } return template.HTML(text) }
dan ini yang memanggil
      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)
          }
      }
#script #webkoe #go #enlightenment #nice
189
Additional Info: