Categorygithub.com/patrickcurl/gowired
modulepackage
0.0.2
Repository: https://github.com/patrickcurl/gowired.git
Documentation: pkg.go.dev

# 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 in server
  5. Render Component and get diff
  6. 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")
}

That's it

More Examples

Slider

Simple todo

All at once using components

GoBook

Go to repo

# Packages

No description provided by the author

# Functions

AttrMapFromNode todo.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewWiredComponent ...
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
Code automatically generated.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
.
WiredComponentWrapper is a struct.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
.

# Type aliases

No description provided by the author
No description provided by the author
HTTPHandlerCtx HTTP Handler with a page level context.
HTTPMiddleware Middleware to run on HTTP requests.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author