Skip to content

A Go code only PWA as proof of concept for using (embedded) NATS as communication between front and back end.

License

Notifications You must be signed in to change notification settings

oderwat/go-nats-app

Repository files navigation

Go-Nats-App

This is a demo of a Go-App based PWA that uses NATS for the communication between frontend and backend.

How to run it?

Clone the repository, cd into it and run go run mage.go run (or mage run if you installed mage already).

Then open http://127.0.0.1:8500 once or multiple times in your browser and chat with yourself.

preview

Features of this demo

  • There is no java-script! Everything is Go code.
    • Frontend & Backend uses Go-App.
    • Build tooling made with Mage.
  • The frontend is a PWA and can be installed on your phone or desktop. It runs in the browser as WASM code with a service-worker.
  • We are using an embedded NATS-Server in the backend to offer three services:
    • Govatar image (JPEG / random / female).
    • Chat broker (3 lines of code + error handling = 10 lines).
    • (New) Each PWA has an echo "req" service under the subject "echo.". Like "echo.late-meadow" in our example picture. An example command-line is shown in the site.
  • We use the original nats.go client in the frontend.
  • Go-App code is smaller when building WASM and normal code separately.
  • We compress the WASM code on the fly.
  • You can run the embedded nats-server as leaf-node of a cluster (that is what we do in another proof of concept).

What does not work?

  • This will not work with TLS (wss://) with before the next release of Nats.go (after 1.20.0). If you need TLS for the web socket you can use go get https://github.com/nats-io/nats.go@main which should work for that. The code in the demo does contain everything needed though (implementation of SkipTLSHandshake() on the CustomDialer).
  • The IPs and ports are hard-coded and as everything binds to localhost it will not work behind reverse proxies or through tunnels like sish or ngrok.
  • A lot more. It is just a proof of concept / demo.
  • #second-tab

Disclaimer

  • We do not care what you do with the code as long as you do not bug us or destroy humanity with it :)
  • This uses the MIT License and is as it is what it is.
  • Parts of the code were quickly grabbed from other internal prototypes or written without much though. It is most likely full of bugs :)

Greetings

  • to the NATS Team
  • to the Go-App developer
  • all the contributors
  • and to everybody else :)

About

A Go code only PWA as proof of concept for using (embedded) NATS as communication between front and back end.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published