DEV Community

Ega Prasetya
Ega Prasetya

Posted on

10 3

Realtime Chat App - Golang

So in this chapter, we will to learn how to create chat app with Gorilla web socket, u should to download library with go get -u github.com/gorilla/websocket. So let`s do it.

BACKEND

Create file main.go, we will to create Socket Server first.

Alt Text

Next create 3 struct like this.

Alt Text

Next, create function main() its contents display template view index.html.

Alt Text

Next, create function handleIO()

Alt Text

Last, create function ejectConnection() & broadcastMessage().

Alt Text

FRONTEND

Create file index.html and follow this code

Alt Text

Next, we also to add style css.

Alt Text

Alt Text

And then last add also javascript.

Alt Text

Alt Text

TESTING

Alt Text

Full Source Code in here

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay