olahol/melody
olahol/melody has 4,080 GitHub stars and 370 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-08 15:37 UTC. Last push 2025-10-28.
:notes: Minimalist websocket framework for Go
Measured star growth
- in 24h
- 0
- in 7 days
- Update delayed
- in 15 days
- Update delayed
- in 1 month
- Update delayed
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Originalmelody
:notes: Minimalist websocket framework for Go.
Melody is websocket framework based on github.com/gorilla/websocket that abstracts away the tedious parts of handling websockets. It gets out of your way so you can write real-time apps. Features include:
- Clear and easy interface similar to
net/httpor Gin. - A simple way to broadcast to all or selected connected sessions.
- Message buffers making concurrent writing safe.
- Automatic handling of sending ping/pong heartbeats that timeout broken sessions.
- Store data on sessions.
Install
go get github.com/olahol/melody
Example: chat
package main
import (
"net/http"
"github.com/olahol/melody"
)
func main() {
m := melody.New()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "index.html")
})
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
m.HandleRequest(w, r)
})
m.HandleMessage(func(s *melody.Session, msg []byte) {
m.Broadcast(msg)
})
http.ListenAndServe(":5000", nil)
}
Example: gophers
package main
import (
"fmt"
"net/http"
"sync/atomic"
"github.com/olahol/melody"
)
var idCounter atomic.Int64
func main() {
m := melody.New()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "index.html")
})
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
m.HandleRequest(w, r)
})
m.HandleConnect(func(s *melody.Session) {
id := idCounter.Add(1)
s.Set("id", id)
s.Write([]byte(fmt.Sprintf("iam %d", id)))
})
m.HandleDisconnect(func(s *melody.Session) {
if id, ok := s.Get("id"); ok {
m.BroadcastOthers([]byte(fmt.Sprintf("dis %d", id)), s)
}
})
m.HandleMessage(func(s *melody.Session, msg []byte) {
if id, ok := s.Get("id"); ok {
m.BroadcastOthers([]byte(fmt.Sprintf("set %d %s", id, msg)), s)
}
})
http.ListenAndServe(":5000", nil)
}
More examples
Documentation
Contributors
FAQ
If you are getting a 403 when trying to connect to your websocket you can change allow all origin hosts:
m := melody.New()
m.Upgrader.CheckOrigin = func(r *http.Request) bool { return true }
Explore related projects
n8n-io/n8n
Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.
209,865 starslanggenius/dify
Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
160,680 starsmicrosoft/PowerToys
Microsoft PowerToys is a collection of utilities that supercharge productivity and customization on Windows
140,710 starsstablyai/orca
Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.
119,447 stars
