barcodes/web/help.go

39 lines
788 B
Go

package web
import (
"fmt"
"html/template"
"net/http"
"git.fjla.uk/fred.boniface/barcodes/validation"
)
func buildPage(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.New("help").ParseFiles("templates/help.html") // Match template name and file name
if err != nil {
fmt.Println("Error templating page: ", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = tmpl.Execute(w, data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}