Getting Started
Get up and running with GoliveKit in under a minute.
Requirements
- Go 1.21+ - GoliveKit uses generics and modern Go features
- Modern browser - WebSocket support required (all modern browsers)
Installation
Install the GoliveKit CLI globally:
Terminal
go install github.com/gabrielmiguelok/golivekit/cmd/golive@latestOr add the library to an existing project:
Terminal
go get github.com/gabrielmiguelok/golivekitCreate Your First Project
Terminal
# Create a new project
golive new myapp
# Enter the project directory
cd myapp
# Start the development server
golive dev
# Open http://localhost:3000 in your browserProject Structure
Project Structure
myapp/
├── main.go # Entry point with router setup
├── components/ # LiveView components
│ └── counter.go # Example counter component
├── templates/ # HTML templates (optional)
├── static/ # Static assets (CSS, JS, images)
└── go.mod # Go module fileHello World Example
Here's a minimal GoliveKit application:
main.go
package main
import (
"context"
"fmt"
"io"
"net/http"
"github.com/gabrielmiguelok/golivekit/client"
"github.com/gabrielmiguelok/golivekit/pkg/core"
"github.com/gabrielmiguelok/golivekit/pkg/router"
)
type HelloWorld struct {
core.BaseComponent
Name string
}
func NewHelloWorld() core.Component {
return &HelloWorld{Name: "World"}
}
func (h *HelloWorld) Name() string { return "hello" }
func (h *HelloWorld) Mount(ctx context.Context, p core.Params, s core.Session) error {
return nil
}
func (h *HelloWorld) HandleEvent(ctx context.Context, event string, payload map[string]any) error {
if event == "greet" {
if name, ok := payload["name"].(string); ok {
h.Name = name
}
}
return nil
}
func (h *HelloWorld) Render(ctx context.Context) core.Renderer {
return core.RendererFunc(func(ctx context.Context, w io.Writer) error {
fmt.Fprintf(w, `<div data-live-view="hello">
<h1>Hello, %s!</h1>
<input type="text" lv-input="greet" lv-value-name placeholder="Enter name"/>
</div>`, h.Name)
return nil
})
}
func (h *HelloWorld) Terminate(ctx context.Context, r core.TerminateReason) error {
return nil
}
func main() {
r := router.New()
r.Handle("/_live/", http.StripPrefix("/_live/", client.Handler()))
r.Live("/", NewHelloWorld)
http.ListenAndServe(":3000", r)
}Next Steps
- Core Concepts - Understand the component lifecycle
- Events - Add interactivity to your components
- Routing - Set up routes and middleware
- Package Reference - Explore all 31 packages