Comments (4)
I'm glad to include an example if someone wants to work on it. It's not something I have time to do right now, but if that changes, I'll consider putting something together.
from pagoda.
I use NATS.Go to do all that.
nats.Go can work in a web client when compiled to wasm. For non web clients it just works of course.
I have done it this way with go-app projects as well as GIO projects.
Using nats gives you security, kv, workers and other stuff. It also means you can stop using REST or GRPC because it does all that too.
for pagoda you can easily do hook up htmx stuff to use it from the server. In the web client it’s very easy to use. When you get sent something from the server ( will be html in this case ) you can just call Js from the golang wasm to update the DOM. It’s pretty cool way to do things I have found.
hope I have explained myself reasonably
from pagoda.
But I don’t know it’s done now. It’s SSE based ?
from pagoda.
I was going to contribute an example but was unable to invoke the websocket handler function from the echo route group. I must be doing something wrong there. Not sure, but I think it's re-rendering the outer page, since it's set to render that page on GET of the outer route before it reaches the websocket route?
router.go
wsocket := wsocket{Controller: ctr}
g.GET("/wsocket", wsocket.Get, middleware.RequireAuthentication()).Name = "wsocket"
g.GET("/terminal", wsocket.Terminal).Name = "terminal"
websocket.go
package routes
import (
"fmt"
"github.com/mikestefanello/pagoda/pkg/controller"
"github.com/labstack/echo/v4"
"golang.org/x/net/websocket"
)
type (
wsocket struct {
controller.Controller
}
)
func (c *wsocket) Get(ctx echo.Context) error {
page := controller.NewPage(ctx)
page.Layout = "main"
page.Name = "wsocket"
page.Title = "Websocket Shell"
return c.RenderPage(ctx, page)
}
func (c *wsocket) Terminal(ctx echo.Context) error {
websocket.Handler(func(ws *websocket.Conn) {
defer ws.Close()
for {
// Write
err := websocket.Message.Send(ws, "Hello, Client!")
if err != nil {
ctx.Logger().Error(err)
}
// Read
msg := ""
err = websocket.Message.Receive(ws, &msg)
if err != nil {
ctx.Logger().Error(err)
}
fmt.Printf("%s\n", msg)
}
}).ServeHTTP(ctx.Response(), ctx.Request())
return nil
}
websocket.gohtml
{{define "content"}}
<div hx-ext="ws" ws-connect="/wsocket/terminal">
<div hx-boost="true" id="chat_room" hx-swap-oob="morphdom">
hello
</div>
{{template "form" .}}
</div>
{{end}}
{{define "form"}}
<form id="form" ws-send >
<input name="chat_message">
</form>
{{end}}
from pagoda.
Related Issues (20)
- Image storage and handling HOT 3
- CueLang HOT 2
- Wasm service worker and htmx idea HOT 4
- Alias "docker compose" in makefile so it works on macs also HOT 4
- kataras/blocks instead of bespoke template solution? HOT 1
- This template is really awesome, thanks! HOT 1
- Serverless can? HOT 2
- Dependency migrated HOT 1
- Gorilla no longer maintained HOT 3
- Rebuilding after file edits HOT 1
- How to use pongo2 as default template engine. HOT 11
- Files HOT 5
- Rendering data returned by ent query HOT 1
- sqlc instead of ent HOT 1
- API support HOT 7
- Workflow on making migrations with Ent and Atlas? HOT 3
- Syntax Highlighting for gohtml files HOT 1
- Error initializing ORM HOT 3
- Flash messages when using HTMX HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pagoda.