{"id":29089810,"url":"https://github.com/benzinga/go-webrpc","last_synced_at":"2025-06-28T04:05:07.925Z","repository":{"id":57498491,"uuid":"43695683","full_name":"Benzinga/go-webrpc","owner":"Benzinga","description":"Simple, lightweight RPC server for Golang.","archived":false,"fork":false,"pushed_at":"2018-03-07T15:50:40.000Z","size":54,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-05-17T13:03:23.079Z","etag":null,"topics":["golang","rpc","travis-ci","websocket"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Benzinga.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-05T15:48:54.000Z","updated_at":"2024-06-16T04:08:47.000Z","dependencies_parsed_at":"2022-09-06T17:10:31.632Z","dependency_job_id":null,"html_url":"https://github.com/Benzinga/go-webrpc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Benzinga/go-webrpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Benzinga%2Fgo-webrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Benzinga%2Fgo-webrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Benzinga%2Fgo-webrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Benzinga%2Fgo-webrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Benzinga","download_url":"https://codeload.github.com/Benzinga/go-webrpc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Benzinga%2Fgo-webrpc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262371672,"owners_count":23300596,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","rpc","travis-ci","websocket"],"created_at":"2025-06-28T04:05:07.050Z","updated_at":"2025-06-28T04:05:07.911Z","avatar_url":"https://github.com/Benzinga.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![godoc.org](http://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square)](https://godoc.org/github.com/Benzinga/go-webrpc) [![Build Status](https://travis-ci.org/Benzinga/go-webrpc.svg)](https://travis-ci.org/Benzinga/go-webrpc) [![codecov.io](http://codecov.io/github/Benzinga/go-webrpc/coverage.svg?branch=master)](http://codecov.io/github/Benzinga/go-webrpc?branch=master)\n\n# Go-WebRPC\nGo-WebRPC is an RPC-style communication library providing a thin abstraction over WebSockets.\n\n# Getting Started\nWebRPC is a library. To make use of it, you need to write software that imports it.\n\nTo make it easier to get started, a full demo is included that can be used with Docker Compose.\n\n## Prerequisites\nGo-WebRPC is built in the Go programming language. If you are new to Go, you will need to [install Go](https://golang.org/dl/).\n\nYou may want Docker in order to easily test the demo app, though it is not required to use `go-webrpc` or the demo app.\n\n## Acquiring\nNext, you'll want to `go get` go-webrpc, like so:\n\n```sh\ngo get github.com/Benzinga/go-webrpc\n```\n\nIf your `$GOPATH` is configured, and git is setup to know your credentials, in a few moments the command should complete with no output. The repository will exist under `$GOPATH/src/github.com/Benzinga/go-webrpc`. It cannot be moved from this location.\n\nHint: If you've never used Go before, your `$GOPATH` will be under the `go` folder of your user directory.\n\n## Demo\nIn order to run the demo app, you'll need to change into the `example/chat` directory. Then, run `docker-compose up`.\n\n```sh\ncd example/chat\ndocker-compose up\n```\n\nThen, in a browser, visit http://localhost:1234. You should be able to chat with yourself.\n\n### Server: Code Explanation\nThe server code is fairly simple, weighing around 40 lines of code.\n\nFirst, the server is instantiated.\n```go\n    server := webrpc.NewServer()\n```\n\nNext, the `OnConnect` handler is set. This handler handles when a WebRPC client connects, and is similar to ServeHTTP.\n```go\n    server.OnConnect(func(c *webrpc.Conn) {\n        ...\n    })\n```\n\nIn the OnConnect handler, we use the user's address as a sort of username.\n```go\n    server.OnConnect(func(c *webrpc.Conn) {\n        user := c.Addr().String()\n\n        ...\n    })\n```\n\nWe define a few helper functions. These deal with sending messages to the client.\n```go\n    server.OnConnect(func(c *webrpc.Conn) {\n        ...\n\n        join := func(ch string) {\n            c.Join(ch)\n            server.Broadcast(ch, \"join\", time.Now(), user, ch)\n        }\n\n        part := func(ch string) {\n            server.Broadcast(ch, \"part\", time.Now(), user, ch)\n            c.Leave(ch)\n        }\n\n        msg := func(ch string, msg string) {\n            server.Broadcast(ch, \"msg\", time.Now(), user, msg)\n        }\n\n        ...\n    })\n```\n\nTo conclude our `OnConnect` handler, we do some things upon connecting as well as register a simple disconnect handler.\n```go\n    server.OnConnect(func(c *webrpc.Conn) {\n        ...\n\n        c.On(\"msg\", msg)\n        join(\"#welcome\")\n        c.OnClose(func() {\n            part(\"#welcome\")\n        })\n    })\n```\n\nFinally, we start an HTTP server with our WebRPC setup.\n```go\n    http.ListenAndServe(\":4321\", server)\n```\n\n### Client\nThe client is written in JavaScript and uses webrpc.js. This is out of scope for this README, but the code is in the `example/chat/client` folder of the repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenzinga%2Fgo-webrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenzinga%2Fgo-webrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenzinga%2Fgo-webrpc/lists"}