feat: initial template (Go + Templ + HTMX + CDN Tailwind)
This commit is contained in:
17
internal/web/handler.go
Normal file
17
internal/web/handler.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func NewHandler() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
_ = Index().Render(context.Background(), w)
|
||||
})
|
||||
mux.HandleFunc("/api/hello", func(w http.ResponseWriter, r *http.Request) {
|
||||
_ = Hello("world").Render(context.Background(), w)
|
||||
})
|
||||
return mux
|
||||
}
|
||||
16
internal/web/index.templ
Normal file
16
internal/web/index.templ
Normal file
@@ -0,0 +1,16 @@
|
||||
package web
|
||||
|
||||
templ Index() {
|
||||
@Layout("__PROJECT_NAME__") {
|
||||
<h1 class="text-3xl font-semibold mb-6">__PROJECT_NAME__</h1>
|
||||
<button hx-get="/api/hello" hx-target="#out"
|
||||
class="px-4 py-2 bg-slate-900 text-white rounded-md hover:bg-slate-700">
|
||||
Say hello
|
||||
</button>
|
||||
<div id="out" class="mt-6 text-slate-700"></div>
|
||||
}
|
||||
}
|
||||
|
||||
templ Hello(name string) {
|
||||
<p>Hello, { name }!</p>
|
||||
}
|
||||
19
internal/web/layout.templ
Normal file
19
internal/web/layout.templ
Normal file
@@ -0,0 +1,19 @@
|
||||
package web
|
||||
|
||||
templ Layout(title string) {
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1"/>
|
||||
<title>{ title }</title>
|
||||
<script src="https://unpkg.com/htmx.org@2.0.0"></script>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
</head>
|
||||
<body class="min-h-screen bg-slate-50 text-slate-900 antialiased">
|
||||
<main class="max-w-3xl mx-auto px-6 py-12">
|
||||
{ children... }
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
Reference in New Issue
Block a user