fixed order popup
This commit is contained in:
parent
cdd60a01f7
commit
ec24dace6a
7 changed files with 55 additions and 30 deletions
29
main.go
29
main.go
|
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
)
|
||||
|
|
@ -11,9 +10,6 @@ import (
|
|||
//go:embed public
|
||||
var public embed.FS
|
||||
|
||||
//go:embed templates
|
||||
var templates embed.FS
|
||||
|
||||
func unwrap[T any](output T, err error) T {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -21,30 +17,21 @@ func unwrap[T any](output T, err error) T {
|
|||
return output
|
||||
}
|
||||
|
||||
func getNewOrder(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl, err := template.ParseFS(templates, "templates/*.gohtml")
|
||||
func handlePost(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("received Post request: ", r)
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprint(w, err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
fmt.Println(err)
|
||||
}
|
||||
err = tmpl.ExecuteTemplate(w, "new_order.gohtml", nil)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprint(w, err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func postNewOrder(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
fmt.Println(r.Form)
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
|
||||
func main() {
|
||||
server := http.NewServeMux()
|
||||
|
||||
server.Handle("/", http.FileServerFS(unwrap(fs.Sub(public, "public"))))
|
||||
server.HandleFunc("GET /order/new", getNewOrder)
|
||||
server.HandleFunc("POST /order/new", postNewOrder)
|
||||
server.Handle("GET /", http.FileServerFS(unwrap(fs.Sub(public, "public"))))
|
||||
server.HandleFunc("POST /", handlePost)
|
||||
|
||||
err := http.ListenAndServe(":8080", server)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue