barcodes/web/help.route.go

33 lines
627 B
Go
Raw Normal View History

2023-09-01 22:47:46 +01:00
package web
import (
"html/template"
"net/http"
"git.fjla.uk/fred.boniface/barcodes/validation"
)
func helpTemplate(w http.ResponseWriter, r *http.Request) {
2023-09-01 22:47:46 +01:00
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,
}
2023-09-01 23:01:08 +01:00
tmpl := template.Must(template.New("help.html").ParseFiles("templates/help.html"))
2023-09-01 22:47:46 +01:00
2023-09-01 23:01:08 +01:00
err := tmpl.Execute(w, data)
2023-09-01 22:47:46 +01:00
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}