Add initial 'help' page
This commit is contained in:
38
web/help.go
Normal file
38
web/help.go
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ func StartServer() {
|
||||
fmt.Fprintf(w, "Barcodes")
|
||||
})
|
||||
|
||||
http.HandleFunc("/help", buildPage)
|
||||
|
||||
http.HandleFunc("/generate", generateBarcode)
|
||||
|
||||
port := ":8500"
|
||||
|
||||
Reference in New Issue
Block a user