Update web handling

This commit is contained in:
Fred Boniface
2023-09-03 21:41:25 +01:00
parent 00aa052a61
commit bfc14ce717
5 changed files with 19 additions and 3 deletions

14
web/page.route.go Normal file
View File

@@ -0,0 +1,14 @@
package web
import (
"fmt"
"net/http"
"strings"
)
func mainHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("Request URL: ", r.URL.Path)
requestFile := strings.TrimRight(r.URL.Path, "/")
requestFile = strings.TrimRight(requestFile, ".html")
fmt.Println("Template File: ", requestFile)
}

View File

@@ -6,9 +6,10 @@ import (
)
func StartServer() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Barcodes")
})
// What I want to do here is server from /static
// if the resource exists, else try to render from /templates
// if the template exists. Else return 404.
http.HandleFunc("/", mainHandler)
http.HandleFunc("/help", helpTemplate)