Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lakinduakash/go-chat-api
Real time chat sever using websockets with go.
https://github.com/lakinduakash/go-chat-api
Last synced: 16 days ago
JSON representation
Real time chat sever using websockets with go.
- Host: GitHub
- URL: https://github.com/lakinduakash/go-chat-api
- Owner: lakinduakash
- Created: 2019-05-20T21:39:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-28T19:20:33.000Z (over 1 year ago)
- Last Synced: 2024-05-22T07:27:24.462Z (6 months ago)
- Language: Go
- Homepage:
- Size: 1.94 MB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-chat-api
[![GoDoc](https://godoc.org/github.com/lakinduakash/go-chat-api?status.svg)](https://godoc.org/github.com/lakinduakash/go-chat-api)
Required Go version >=1.11
To use module
`go get github.com/lakinduakash/go-chat-api`
You can start server on given port and path like below.
Then you can listen client registering,removing and message arriving event.
Starting sever is blocking operation. If you need to listen changes,
Use goroutine as below.```go
package mainimport (
"fmt"
chat_api "github.com/lakinduakash/go-chat-api"
)func main() {
go func() {
chat_api.StartSever(":28960", "/ws")
}()a := chat_api.ListenClientAddChanges()
b := chat_api.ListenClientRemoveChanges()
c := chat_api.ListenMessageChanges()for {
select {
case c := <-a:
fmt.Println("New user connected ", c.ID)case c := <-b:
fmt.Println("User removed ", c.ID)case c := <-c:
fmt.Println("New message ", c)
}}
}```
If you need to get list of clients registered currently, use `chat_api.GetClients()`.
It will return map of clients and keys which are UUIDs.To run example go server
```bash
git clone http://github.com/lakinduakash/go-chat-api
cd go-chat-api/example-chat/chat-sever
go run main.go
```
Start Angular client```bash
cd go-chat-api/example-chat/chat-ui
npm install
ng serve
```