https://github.com/patrickcurl/gowired
https://github.com/patrickcurl/gowired
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/patrickcurl/gowired
- Owner: patrickcurl
- License: other
- Created: 2021-07-05T22:11:30.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-06T01:01:54.000Z (over 4 years ago)
- Last Synced: 2025-01-25T14:12:02.725Z (11 months ago)
- Language: Go
- Homepage:
- Size: 1.28 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# GoWired
## 💻 Reactive HTML Server Side Rendered by GoLang over WebSockets 🚀
Use Go and ***Zero JavaScript*** to program reactive front-ends!

## How?
1. Render Server Side HTML
2. Connect to same server using Websocket
3. Send user events
4. Change state of [component](component.go) in server
5. Render Component and get [diff](diff.go)
6. Update instructions are sent to the browser
## Getting Started
- [Extended Version Todo Example](https://github.com/SamHennessy/gowired-example)
- [Project Examples](https://github.com/patrickcurl/gowired/tree/master/examples)
- [GoBook - Interactive Go REPL in browser](https://github.com/brendonmatos/gobook)
**Any suggestions are absolutely welcome**
This project it's strongly inspired by Elixir Phoenix LiveView.
## Component Example
```go
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 `
Time: {{ .ActualTime }}
`
}
```
### Server Example
```go
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")
}
```
### That's it

## More Examples
### Slider

### Simple todo

### All at once using components

### GoBook

[Go to repo](https://github.com/brendonmatos/gobook)