2023-09-01 22:47:46 +01:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
2023-09-03 20:59:33 +01:00
|
|
|
"fmt"
|
2023-09-01 22:47:46 +01:00
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"git.fjla.uk/fred.boniface/barcodes/validation"
|
|
|
|
)
|
|
|
|
|
2023-09-02 22:05:46 +01:00
|
|
|
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-03 20:59:33 +01:00
|
|
|
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)
|
2023-09-01 22:47:46 +01:00
|
|
|
if err != nil {
|
2023-09-03 20:59:33 +01:00
|
|
|
fmt.Println("Error rendering templates: ", err)
|
|
|
|
http.Error(w, "Unable to render templates", 500)
|
2023-09-01 22:47:46 +01:00
|
|
|
}
|
|
|
|
}
|