INNER CODE UNIT · Go

handleRenderTemplate

machinebox/remoto · console/api/main.go:86

func handleRenderTemplate() http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		if r.Method != http.MethodPost {
			http.NotFound(w, r)
			return
		}
		templatePath := r.URL.Path[len("/api/"):] + ".plush"
		tplBytes, err := ioutil.ReadFile(templatePath)
		if err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		def, err := generator.Parse(strings.NewReader(r.FormValue("definition")))
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		filename := filepath.Base(templatePath)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…