Beispiel #1
0
func pageAdd(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html")

	pkgsStr := r.FormValue("pkg")
	pkgMessage := ""
	msgCls := "success"
	taValue := ""
	if pkgsStr != "" {
		pkgs := filterPackages(strings.Split(pkgsStr, "\n"))
		if len(pkgs) > 0 {
			log.Printf("%d packages added!", len(pkgs))
			pkgMessage = fmt.Sprintf("Totally %d package(s) added!", len(pkgs))
			gcse.AppendPackages(pkgs)
		} else {
			msgCls = "danger"
			pkgMessage = "No package added! Check the format you submitted, please."
			taValue = pkgsStr
		}
	}
	err := templates.ExecuteTemplate(w, "add.html", struct {
		UIUtils
		Message string
		MsgCls  string
		TAValue string
	}{
		Message: pkgMessage,
		MsgCls:  msgCls,
		TAValue: taValue,
	})
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
Beispiel #2
0
func pageAdd(w http.ResponseWriter, r *http.Request) {
	pkgsStr := r.FormValue("pkg")
	if pkgsStr != "" {
		pkgs := strings.Split(pkgsStr, "\n")
		log.Printf("%d packaged submitted!", len(pkgs))
		gcse.AppendPackages(pkgs)
	}

	err := templates.ExecuteTemplate(w, "add.html", nil)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}