new order popup
This commit is contained in:
parent
fbed113a55
commit
cdd60a01f7
5 changed files with 81 additions and 0 deletions
3
go.mod
Normal file
3
go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module github.com/Bronku/iroon
|
||||||
|
|
||||||
|
go 1.23.5
|
||||||
53
main.go
Normal file
53
main.go
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"io/fs"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
//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)
|
||||||
|
}
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
func getNewOrder(w http.ResponseWriter, r *http.Request) {
|
||||||
|
tmpl, err := template.ParseFS(templates, "templates/*.gohtml")
|
||||||
|
if err != nil {
|
||||||
|
_, _ = fmt.Fprint(w, err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
err := http.ListenAndServe(":8080", server)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Can't start the server: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
1
public/htmx-2.04.js
Normal file
1
public/htmx-2.04.js
Normal file
File diff suppressed because one or more lines are too long
17
public/index.html
Normal file
17
public/index.html
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>IROON</title>
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
|
<script src="htmx-2.04.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>I ran out of names</h1>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
<button hx-get="/order/new" hx-swap="afterend">New Order</button>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
7
templates/new_order.gohtml
Normal file
7
templates/new_order.gohtml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<form>
|
||||||
|
<label>
|
||||||
|
ok
|
||||||
|
<input>
|
||||||
|
</label>
|
||||||
|
<button hx-post="/order/new" hx-swap="delete" hx-target="closest form">Submit</button>
|
||||||
|
</form>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue