Started playing with htmx and golang
This commit is contained in:
commit
7fc4ca26d5
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
*.test
|
||||
|
||||
*.out
|
||||
|
||||
vendor/
|
||||
|
||||
go.work
|
||||
|
31
server.go
Normal file
31
server.go
Normal 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
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
5
static/index.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user