Skip to content

fshiori/kuromi

Repository files navigation

kuromi

GoDoc

Minimalist websocket framework for Go. 世界クロミ化計画

Kuromi is websocket framework based on github.com/coder/websocket and rewrite of github.com/olahol/melody 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/http or 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/fshiori/kuromi

Chat

package main

import (
	"net/http"

	"github.com/fshiori/kuromi"
)

func main() {
	k := kuromi.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) {
		k.HandleRequest(w, r)
	})

	k.HandleMessage(func(s *kuromi.Session, msg []byte) {
		k.Broadcast(msg)
	})

	http.ListenAndServe(":5000", nil)
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages