repositorypackage
0.0.2
Repository: https://github.com/patrickcurl/gowired.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
# README
GoWired
💻 Reactive HTML Server Side Rendered by GoLang over WebSockets 🚀
Use Go and Zero JavaScript to program reactive front-ends!
How?
- Render Server Side HTML
- Connect to same server using Websocket
- Send user events
- Change state of component in server
- Render Component and get diff
- Update instructions are sent to the browser
Getting Started
Any suggestions are absolutely welcome
This project it's strongly inspired by Elixir Phoenix LiveView.
Component Example
package components
import (
"github.com/patrickcurl/gowired"
"time"
)
type Clock struct {
gowired.WiredComponentWrapper
ActualTime string
}
func NewClock() *gowired.WiredComponent {
return gowired.NewWiredComponent("Clock", &Clock{})
}
func (t *Clock) Mounted(_ *gowired.WiredComponent) {
go func() {
for {
t.ActualTime = time.Now().Format(time.RFC3339Nano)
time.Sleep((time.Second * 1) / 60)
t.Commit()
}
}()
}
func (t *Clock) TemplateHandler(_ *gowired.WiredComponent) string {
return `
<div>
<span>Time: {{ .ActualTime }}</span>
</div>
`
}
Server Example
package main
import (
"github.com/patrickcurl/gowired"
"github.com/patrickcurl/gowired/examples/components"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/websocket/v2"
)
func main() {
app := fiber.New()
wiredServer := gowired.NewServer()
app.Get("/", wiredServer.CreateHTMLHandler(components.NewClock, gowired.PageContent{
Lang: "us",
Title: "Hello world",
}))
app.Get("/ws", websocket.New(wiredServer.HandleWSRequest))
_ = app.Listen(":3000")
}