Skip to content
/ golive Public
forked from brendonmatos/golive

💻 Reactive HTML Server Side Rendered by GoLang over WebSockets 🚀

License

Notifications You must be signed in to change notification settings

cxsx/golive

 
 

Repository files navigation

GoLive

Any suggestions are absolutely welcome

This project it's strongly inspired by Elixir Phoenix Live View. I'm writing this as a Side Project to solve some issues that I'm having in production in my full-time Job.

Component Example

package components 

import (
	"github.com/brendonferreira/golive"
	"time"
)
type Clock struct {
	golive.LiveComponentWrapper
	ActualTime string
}

func NewClock() *golive.LiveComponent {
	return golive.NewLiveComponent("Clock", &Clock{
		ActualTime: "91230192301390193",
	})
}

func (t *Clock) Mounted(_ *golive.LiveComponent) {
	go func() {
		for {
			t.ActualTime = time.Now().Format(time.RFC3339Nano)
			time.Sleep((time.Second * 1) / 60)
			t.Commit()
		}
	}()
}

func (t *Clock) TemplateHandler(_ *golive.LiveComponent) string {
	return `
		<div>
			<span>Time: {{ .ActualTime }}</span>
		</div>
	`
}

Server Example

  
package main

import (
	"github.com/brendonferreira/golive"
	"github.com/brendonferreira/golive/examples/components"
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/websocket/v2"
)

func main() {
	app := fiber.New()
	liveServer := golive.NewServer()

	app.Get("/", liveServer.CreateHTMLHandler(components.NewClock, golive.PageContent{
		Lang:  "us",
		Title: "Hello world",
	}))

	app.Get("/ws", websocket.New(liveServer.HandleWSRequest))

	_ = app.Listen(":3000")
}

That's it!

TODO

  • Components
    • Subcomponents
    • "turn off" unneeded components
    • Plan better component write - maybe follow go-kit policy?
    • Write Test
  • Decide what LiveWire will connect. It will continue to be the page, or the scope makes more sense?
  • Throttling events from view
  • Decide if will be necessary a method that receive all the events before send to front. Being able to block some updates
  • Examples
    • Agario clone

About

💻 Reactive HTML Server Side Rendered by GoLang over WebSockets 🚀

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%