1
0

Started playing with htmx and golang

This commit is contained in:
Nigel Barink 2024-04-03 21:17:02 +02:00
commit 7fc4ca26d5
Signed by: Nigel
GPG Key ID: C54278C495538619
5 changed files with 54 additions and 0 deletions

14
.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
vendor/
go.work

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module dev/barink/go-surf
go 1.22.2

31
server.go Normal file
View File

@ -0,0 +1,31 @@
package main
import(
"fmt"
"errors"
"io"
"net/http"
"os"
)
func getMouse(w http.ResponseWriter, r *http.Request){
io.WriteString(w, "Peep!\n")
}
func getHello(w http.ResponseWriter, r *http.Request){
fmt.Println("got /hello request")
io.WriteString(w, "Hello, HTTP!\n")
}
func main() {
http.Handle("/", http.FileServer(http.Dir("./static")))
http.HandleFunc("/hello", getHello)
http.HandleFunc("/mouse_entered", getMouse)
err := http.ListenAndServe(":8081", nil)
if errors.Is(err, http.ErrServerClosed){
fmt.Printf("server closed\n")
}else if err != nil {
fmt.Printf("error starting server: %s\n", err)
os.Exit(1)
}
}

1
static/htmx.min.js vendored Normal file

File diff suppressed because one or more lines are too long

5
static/index.html Normal file
View File

@ -0,0 +1,5 @@
<h1 hx-get="/hello" hx-trigger="load delay:4s"></h1>
<div hx-post="mouse_entered" hx-trigger="mouseenter">
[Here mouse, mouse!]
</div>
<script src="htmx.min.js" ></script>