-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: add bare-bones HTMX example (#15)
Closes #8 Obviously it's the simplest, silliest example possible, but we can build upon it as we go along.
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
|
||
"github.com/gamebox/gwirl/htmx-example/views/html" | ||
) | ||
|
||
type Server struct { | ||
count int | ||
} | ||
|
||
|
||
func (s *Server) renderIndex(rw http.ResponseWriter, req *http.Request) { | ||
rw.Write([]byte(html.Index(s.count))) | ||
rw.WriteHeader(200) | ||
} | ||
|
||
func (s *Server) renderCount(rw http.ResponseWriter, req *http.Request) { | ||
s.count += 1 | ||
rw.Write([]byte(html.Counter(s.count))) | ||
rw.WriteHeader(200) | ||
} | ||
|
||
func main() { | ||
log.Println("Starting up...") | ||
handler := http.NewServeMux() | ||
s := Server{0} | ||
handler.HandleFunc("/", s.renderIndex) | ||
handler.HandleFunc("/count", s.renderCount) | ||
log.Fatalf("%v", http.ListenAndServe(":3000", handler)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@(title string, content string) | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>@title</title> | ||
<script src="https://unpkg.com/htmx.org@@1.9.10"></script> | ||
</head> | ||
<body> | ||
@content | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@(count int) | ||
|
||
@import "fmt" | ||
|
||
<p id="counter" class="count">@fmt.Sprintf("%d", count)</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@(count int) | ||
|
||
@Base("Gwirl HTMX - Home") { | ||
<h1>Gwirl HTMX</h1> | ||
|
||
@Counter(count) | ||
|
||
<button hx-patch="/count" hx-target="#counter">Increment</button> | ||
} | ||
|