Categories
BLOG

glue go

Glue go

GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

GitHub is where the world builds software

Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Glue generates client code for your Go RPC server. It currently supports

go get github.com/segmentio/glue/cmd/glue

Then, glue should be available at $GOPATH/bin/glue (ideally, in your $PATH ).

glue -name=Service -service=Math [path] will traverse the provided path (or working directory if none is provided) and generate clients for RPC methods (pointed at Math.* ) declared on type Service .

Given the following is in a *.go file in your working directory,

go generate would output the following to clients/Service.go

If you use gorilla/rpc, you’re in luck! Just specify -gorilla .

Glue always outputs code with client package. By default, this is in ./client , but you can change the output directory via -out .

To output code to STDOUT instead of files, supply -print .

How do I use Glue with RPC implementation X?

Glue is modular. If you’d like support for another popular (or interesting, well-maintained) RPC implementation, open a PR to add a new Glue provider/ .

Unfortunately, Go doesn’t allow dynamic loading of packages so if you’d like Glue to support an internal or experimental RPC framework, fork Glue and supply another provider in cmd/glue/main.go.

About

Generate typed Golang RPC clients from server code

Generate typed Golang RPC clients from server code – segmentio/glue

Glue go

GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

GitHub is where the world builds software

Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Glue – Robust Go and Javascript Socket Library

Glue is a real-time bidirectional socket library. It is a clean, robust and efficient alternative to socket.io. This library is designed to connect webbrowsers with a go-backend in a simple way. It automatically detects supported socket layers and chooses the most suitable one. This library handles automatic reconnections on disconnections and handles caching to bridge those disconnections. The server implementation is thread-safe and stable. The API is fixed and there won’t be any breaking API changes.

Currently two socket layers are supported:

  • WebSockets – This is the primary option. They are used if the webbrowser supports WebSockets defined by RFC 6455.
  • AjaxSockets – This socket layer is used as a fallback mode.

Feel free to contribute to this project. Please check the TODO file for more information.

The client javascript Glue library is located in client/dist/glue.js.

You can use bower to install the client library:

bower install –save glue-socket

Get the source and start hacking.

go get github.com/desertbit/glue

Client – Javascript Library

A simple call to glue() without any options will establish a socket connection to the same host. A glue socket object is returned.

Optional Javascript options which can be passed to Glue:

The glue socket object has following public methods:

A channel object has following public methods:

Server – Go Library

Check the Documentation at GoDoc.org.

Use a custom HTTP multiplexer

If you choose to use a custom HTTP multiplexer, then it is possible to deactivate the automatic HTTP handler registration of glue.

The glue server implements the ServeHTTP method of the HTTP Handler interface of the http package. Use this to register the glue HTTP handler with a custom multiplexer. Be aware, that the URL of the custom HTTP handler has to match with the glue HTTPHandleURL options string.

Data has to be read from the socket and each channel. If you don’t require to read data from the socket or a channel, then discard received data with the DiscardRead() method. If received data is not discarded, then the read buffer will block as soon as it is full, which will also block the keep-alive mechanism of the socket. The result would be a closed socket.

Bind custom values to a socket

The socket.Value interface is a placeholder for custom data.

Channels are separate communication channels from the client to the server of a single socket connections. Multiple separate communication channels can be created:

With Glue it is easy to broadcast messages to multiple clients. The Glue Server keeps track of all active connected client sessions. You can make use of the server Sockets, GetSocket or OnNewSocket methods to implement broadcasting.

This socket library is very straightforward to use. Check the sample directory for more examples.

Read data from the socket with a read event function. Check the sample directory for other ways of reading data from the socket.

Glue – Robust Go and Javascript Socket Library (Alternative to Socket.io) – desertbit/glue