func mainHandler(w http.ResponseWriter, r *http.Request) { filter := strings.ToLower(r.FormValue("filter")) expert := r.FormValue("expert") == "on" tag := strings.ToLower(r.FormValue("tag")) l := ltxref.Ltxref{Version: latexref.Version} l.Commands = latexref.FilterCommands(filter, tag, expert) l.Packages = latexref.FilterPackages(filter, tag) l.Environments = latexref.FilterEnvironments(filter, tag, expert) l.DocumentClasses = latexref.FilterDocumentClasses(filter, tag, expert) switch strings.ToLower(r.FormValue("format")) { case "xml": str, err := l.ToXML() if err != nil { fmt.Println(err) } sendXML(w, str) return case "txt": l.ToString(w, true) return } data := struct { Filter string Tag string Edit string Expert bool L ltxref.Ltxref Tags []string XMLUrl string PlainTextUrl string }{ L: l, Filter: filter, Tag: tag, Edit: editToken(r), Expert: expert, Tags: latexref.Tags(), XMLUrl: addXMLFormatString(r.URL), PlainTextUrl: addTXTFormatString(r.URL), } err := tpl.ExecuteTemplate(w, "main.html", data) if err != nil { fmt.Println(err) } }
func documentclassDetailHandler(w http.ResponseWriter, r *http.Request) { requestedDocumentclass := mux.Vars(r)["documentclass"] filtervalue := strings.ToLower(r.FormValue("filter")) class := latexref.GetDocumentClass(requestedDocumentclass) if class == nil { // not found -> error // TODO return } switch strings.ToLower(r.FormValue("format")) { case "xml": l := ltxref.Ltxref{Version: latexref.Version} l.DocumentClasses = append(l.DocumentClasses, class) str, err := l.ToXML() if err != nil { fmt.Println(err) return } sendXML(w, str) return case "txt": class.ToString(w) return default: backlink := &url.URL{} backlink.Path = "/" addKeyValueToUrl(backlink, "edit", r.FormValue("edit")) addKeyValueToUrl(backlink, "filter", r.FormValue("filter")) data := struct { Backlink string Filter string Edit string DocumentClass ltxref.DocumentClass XMLUrl string PlainTextUrl string }{ Backlink: backlink.String(), Edit: editToken(r), Filter: filtervalue, DocumentClass: *class, XMLUrl: addXMLFormatString(r.URL), PlainTextUrl: addTXTFormatString(r.URL), } err := tpl.ExecuteTemplate(w, "classdetail", data) if err != nil { fmt.Println(err) } } return }