Coder Social home page Coder Social logo

clivern / beaver Goto Github PK

View Code? Open in Web Editor NEW
1.5K 32.0 83.0 3.27 MB

๐Ÿ’จ A real time messaging system to build a scalable in-app notifications, multiplayer games, chat apps in web and mobile apps.

Home Page: https://clivern.github.io/Beaver/

License: MIT License

Makefile 4.44% Go 94.73% JavaScript 0.35% Shell 0.48%
pusher beaver websocket pubsub socket-io realtime messaging messaging-service socketjs hacktoberfest

beaver's People

Contributors

andrewvo148 avatar butuzov avatar clivern avatar dependabot[bot] avatar hongnguyenhuu96 avatar renovate[bot] avatar stack-file[bot] avatar todd-the-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beaver's Issues

I have some questions about this library

Hi @Clivern
First, I appreciate you for making this library.
But sorry to say if I still didn't understand your documentation.

Is there a 'good' documentation about it like some documentations in GoDoc or documentation provided with image for better illustrating?

Second, do you have sample or demo app?

Thankyou in advance ๐Ÿ™๐Ÿผ

Add Misc Endpoints

POST  /api/broadcast
POST  /api/unsubscribe
POST  /api/subscribe
POST  /api/publish

Add Config Endpoints

$ curl -X POST -H "Content-Type: application/json" -d '{"key":"app_name","value":"Beaver"}' "http://localhost:8080/api/config" 
$ curl -X GET -H "Content-Type: application/json" "http://localhost:8080/api/config/app_name"
$ curl -X PUT -H "Content-Type: application/json" -d '{"value":"Beaver1"}' "http://localhost:8080/api/config/app_name"
$ curl -X GET -H "Content-Type: application/json" "http://localhost:8080/api/config/app_name"
$ curl -X DELETE -H "Content-Type: application/json" "http://localhost:8080/api/config/app_name"

YAML Configs Support

https://github.com/micro/go-config
database:
  host: localhost
  port: 25
  username: root
  password: root
import(
	"github.com/micro/go-config"
	"github.com/micro/go-config/source/file"
)

config.Load(file.NewSource(
	file.WithPath("config.yaml"),
))

fmt.Println(config.Get("database", "host").String("localhost"))

Config File

You can now simplify config file loading with config.LoadFile(path).

HA Cluster!

Beaver nodes shall work as follow:

  • All beaver nodes connected to same Redis cluster.
  • Each Node join the cluster shares its info on Redis with other nodes.
  • Using shared info, All nodes should be able to load balance across multiple nodes.
  • All beaver nodes subscribe to a specific Redis Channel or RabbitMQ in order to get notified by all incoming messages, publish events and they will deliver these messages to their connected clients.
  • Clients are free to connect to any node without getting affected.
  • If node goes down, only connected clients are affected and connecting to a new node will fix the problem.

CORS headers middleware

Right now all requests forbidden do to cors restriction, when using the beaver from the browser. Is it possible to add cors middleware that will add required headers to the requests? All needed data can be described in the config file.

For example, the middleware may be something like that:

func Cors(allowedMethods, allowedHeaders []string, allowedOriginPattern string) gin.HandlerFunc {
	return func(c *gin.Context) {
		r := c.Request
		w := c.Writer

		w.Header().Set("Content-Type", "application/json; charset=utf-8")
		w.Header().Set("Access-Control-Allow-Methods", strings.Join(allowedMethods, ", "))
		w.Header().Set("Access-Control-Allow-Headers", strings.Join(allowedHeaders, ", "))

		reqOrigin := r.Header.Get("Origin")

		switch allowedOriginPattern {
		case "*", ".*", "/*":
			w.Header().Set("Access-Control-Allow-Origin", "*")
		default:
			if ok, _ := regexp.MatchString(allowedOriginPattern, reqOrigin); ok {
				w.Header().Set("Access-Control-Allow-Origin", reqOrigin)
			}
		}

		if r.Method == "OPTIONS" {
			c.AbortWithStatus(http.StatusOK)
		} else {
			c.Next()
		}
	}
}

Flutter support

Cloud u confirm that this could work with flutter, is there any docs for integration with flutter or just connect it as socket in flutter project

Suggestion to generate smaller images

I checked the Dockerfile and I'd like to do some suggestions to you(of course, I can do the changes and send a PR, if you are interested).

beaver-alpine -> I changed FROM golang:1.11.1 to FROM golang:1.11-alpine, it need to add git and CGO_ENABLED=0.
beaver-builder ->I used the Dockerfile to build the image, but I used alpine(it could be scratch) to run the project.
As you can see in the screenshot, we can create smaller images.
screen shot 2019-01-24 at 11 24 18

Please explain config API routes /api/config/*

Is your feature request related to a problem? Please describe.
It is not clear why there are the config REST API routes.

Describe the solution you'd like
Could you please explain in short?

Additional context

Add Base Skelton

Create Architecture for:

  • Public Channels.
  • Private Channels.
  • Presence Channels.
  • Clients Workflow.

It panic error occasionally

Describe the bug
I use beaver to build a socket server.But sometimes it panics with an error.
The error is : fatal error: concurrent map writes.

And the error's stacks info : github.com/clivern/beaver/internal/app/controller.(*Websocket).HandleConnections(0xc0001ca4d0, 0x7f033e218240, 0xc0004869a0, 0xc0000b1200, 0xc000233108, 0x24, 0xc00023312d, 0xbd, 0xc000029440, 0x24) /root/Beaver/internal/app/controller/socket.go:166 +0x505 fp=0xc000585688 sp=0xc0005854e8 pc=0xabd815.

The code in 166 line is:delete(e.Clients, ID)

I google for the reason and find it's unsafe that using map in goruntine. So I think Websocket.Clients should protected by mutex or use sync.Map directly?

Development or production environment

  • OS: [Ubuntu 16.04]
  • Go 1.12.17

Expose Beaver Metrics

There is two types:

  • Metrics that never change in case of node, so any node can provide these metrics.
  • Node metrics like connected clients & overall connected clients.

switch from micro/go-config to spf13/viper

For stability & reduce upgrade hurdles, i will switch to spf13/viper

$ go get -u

go: github.com/testcontainers/testcontainer-go@v0.0.2: parsing go.mod: unexpected module path "github.com/testcontainers/testcontainers-go"
go: finding github.com/gregjones/httpcache latest
go: finding github.com/dgryski/go-bitstream latest
go: finding github.com/k0kubun/colorstring latest
go get: error loading module requirements

Currently github.com/micro/go-config face a problem with one of the dependencies chain.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.