Build hotwire applications using Go
Examples are in examples directory
go get github.com/akmittal/turbo-go
github.com/akmittal/turbo-go/pkg/turbo
Send single template update
messageTemp, err := template.New("message").parse(`<div>{{.}}</div>`)
data := time.Now()
turbo := turbo.Turbo{
Action: turbo.APPEND, // Action can be UPDATE, APPEND, PREPEND, REPLACE, REMOVE
Template: messageTemp,
Target: "messages",
Data: data,
}
Send stream of templates
func main(){
// Create hub
hub := turbo.NewHub()
go hub.Run()
mux.Get("/socket", func(rw http.ResponseWriter, req *http.Request) {
getSocket(msgChan, hub, rw, req)
})
}
func getSocket(msgChan chan interface{}, hub *turbo.Hub, rw http.ResponseWriter, req *http.Request) {
temp, _ := template.ParseFiles("templates/messages.temp.html")
messageTemp := temp.Lookup("message")
appendMessage := turbo.Stream{
Action: turbo.APPEND,
Template: messageTemp,
Target: "messages",
Data: msgChan,
}
appendMessage.Stream(hub, rw, req)
}