barcodes/web/help.route.go

37 lines
781 B
Go

package web
import (
"fmt"
"html/template"
"net/http"
"git.fjla.uk/fred.boniface/barcodes/validation"
)
func helpTemplate(w http.ResponseWriter, r *http.Request) {
i := 0
barcodeOptions := make([]string, len(validation.FormatRules))
for k := range validation.FormatRules {
barcodeOptions[i] = k
i++
}
type dataType struct {
BarcodeOptions []string
}
data := dataType{
BarcodeOptions: barcodeOptions,
}
tmpl, err := template.ParseFiles("./templates/base.html", "./templates/help.html")
if err != nil {
fmt.Println("Error parsing templates: ", err)
http.Error(w, "Unable to parse templates", 500)
}
err = tmpl.Execute(w, data)
if err != nil {
fmt.Println("Error rendering templates: ", err)
http.Error(w, "Unable to render templates", 500)
}
}