Getting started
Installation
To use gofh, you need Go 1.16 or later installed on your system. Install gofh using go get
:
go get github.com/teilomillet/gofh
Hello World Example
Let's create a simple "Hello World" application with gofh:
Create a new directory for your project:
mkdir hello-gofh
cd hello-gofh
Initialize a new Go module:
go mod init hello-gofh
Create a file named
main.go
with the following content:
package main
import (
"log"
"github.com/teilomillet/gofh"
)
func main() {
app := gofh.New()
app.Get("/").Handle(func(c *gofh.Context) gofh.Element {
return gofh.Div(
gofh.H1("Welcome to gofh"),
gofh.P("Hello, World!").
HxGet("/greet").
HxSwap("outerHTML"),
)
})
app.Get("/greet").Handle(func(c *gofh.Context) gofh.Element {
return gofh.P("Hello from gofh!")
})
log.Println("Server starting on http://localhost:8080")
log.Fatal(app.Serve())
}
Run your application:
go run main.go
Open your web browser and visit
http://localhost:8080
. You should see the "Hello, World!" message. Clicking on it will change the message to "Hello from gofh!" without a page reload, demonstrating the HTMX integration.
Last updated