Skip to content

Commit

Permalink
demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Ola Holmström committed May 13, 2015
1 parent aedcbc9 commit 3f25380
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,45 @@
[![Build Status](https://travis-ci.org/olahol/melody.svg)](https://travis-ci.org/olahol/melody)

> :notes: Simple websocket framework for Go
## Install

```bash
go get github.com/olahol/melody
```

## Example

[Simple broadcasting chat server](https://github.com/olahol/melody/tree/master/examples/chat),
error handling left as en exercise for the developer.

```go
package main

import (
"github.com/olahol/melody"
"github.com/gin-gonic/gin"
"net/http"
)

func main() {
r := gin.Default()
m := melody.New()

r.GET("/", func(c *gin.Context) {
http.ServeFile(c.Writer, c.Request, "index.html")
})

r.GET("/ws", func(c *gin.Context) {
m.HandleRequest(c.Writer, c.Request)
})

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

r.Run(":5000")
}
```

[![Chat demo](https://cdn.rawgit.com/olahol/melody/master/examples/chat/demo.webm "Demo")](https://github.com/olahol/melody/tree/master/examples/chat)
Binary file added examples/chat/demo.webm
Binary file not shown.

0 comments on commit 3f25380

Please sign in to comment.