Categories
BLOG

glue go

Glue go

Package glue – Robust Go and Javascript Socket Library. This library is thread-safe.

Index ¶

  • Constants
  • Variables
  • type Channel
    • func (c *Channel) DiscardRead()
    • func (c *Channel) OnRead(f OnReadFunc)
    • func (c *Channel) Read(timeout . time.Duration) (string, error)
    • func (c *Channel) Socket() *Socket
    • func (c *Channel) Write(data string)
  • type ClosedChan
  • type HTTPSocketType
  • type OnCloseFunc
  • type OnNewSocketFunc
  • type OnReadFunc
  • type Options
    • func (o *Options) SetDefaults()
  • type Server
    • func NewServer(o . Options) *Server
    • func (s *Server) Block(b bool)
    • func (s *Server) GetSocket(id string) *Socket
    • func (s *Server) IsBlocked() bool
    • func (s *Server) OnNewSocket(f OnNewSocketFunc)
    • func (s *Server) Release()
    • func (s *Server) Run() error
    • func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
    • func (s *Server) Sockets() []*Socket
  • type Socket
    • func (s *Socket) Channel(name string) *Channel
    • func (s *Socket) Close()
    • func (s *Socket) ClosedChan() ClosedChan
    • func (s *Socket) DiscardRead()
    • func (s *Socket) ID() string
    • func (s *Socket) IsClosed() bool
    • func (s *Socket) IsInitialized() bool
    • func (s *Socket) OnClose(f OnCloseFunc)
    • func (s *Socket) OnRead(f OnReadFunc)
    • func (s *Socket) Read(timeout . time.Duration) (string, error)
    • func (s *Socket) RemoteAddr() string
    • func (s *Socket) UserAgent() string
    • func (s *Socket) Write(data string)
Package Files ¶

Constants ¶

Variables ¶

type Channel ¶ Uses

A Channel is a separate communication channel.

func (*Channel) DiscardRead ¶ Uses

DiscardRead ignores and discars the data received from this channel. Call this method during initialization, if you don’t read any data from this channel. 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.

func (*Channel) OnRead ¶ Uses

OnRead sets the function which is triggered if new data is received on the channel. If this event function based method of reading data from the socket is used, then don’t use the socket Read method. Either use the OnRead or the Read approach.

func (*Channel) Read ¶ Uses

Read the next message from the channel. This method is blocking. One variadic argument sets a timeout duration. If no timeout is specified, this method will block forever. ErrSocketClosed is returned, if the socket connection is closed. ErrReadTimeout is returned, if the timeout is reached.

func (*Channel) Socket ¶ Uses

Socket returns the channel’s socket.

func (*Channel) Write ¶ Uses

Write data to the channel.

type ClosedChan ¶ Uses

ClosedChan is a channel which doesn’t block as soon as the socket is closed.

type HTTPSocketType ¶ Uses

A HTTPSocketType defines which socket type to use for the HTTP glue server.

type OnCloseFunc ¶ Uses

OnCloseFunc is an event function.

type OnNewSocketFunc ¶ Uses

OnNewSocketFunc is an event function.

type OnReadFunc ¶ Uses

OnReadFunc is an event function.

type Options ¶ Uses

Options holds the glue server options.

func (*Options) SetDefaults ¶ Uses

SetDefaults sets unset option values to its default value.

type Server ¶ Uses

A Server represents a glue server which handles incoming socket connections.

func NewServer ¶ Uses

NewServer creates a new glue server instance. One variadic arguments specifies the server options.

func (*Server) Block ¶ Uses

Block new incomming connections.

func (*Server) GetSocket ¶ Uses

GetSocket obtains a socket by its ID. Returns nil if not found.

func (*Server) IsBlocked ¶ Uses

IsBlocked returns a boolean whenever new incoming connections should be blocked.

func (*Server) OnNewSocket ¶ Uses

OnNewSocket sets the event function which is triggered if a new socket connection was made. The event function must not block! As soon as the event function returns, the socket is added to the active sockets map.

func (*Server) Release ¶ Uses

Release this package. This will block all new incomming socket connections and close all current connected sockets.

func (*Server) Run ¶ Uses

Run starts the server and listens for incoming socket connections. This is a blocking method.

func (*Server) ServeHTTP ¶ Uses

ServeHTTP implements the HTTP Handler interface of the http package.

func (*Server) Sockets ¶ Uses

Sockets returns a list of all current connected sockets. Hint: Sockets are added to the active sockets list before the OnNewSocket event function is called. Use the IsInitialized flag to determind if a socket is not ready yet.

type Socket ¶ Uses

A Socket represents a single socket connections to a client.

func (*Socket) Channel ¶ Uses

Channel returns the corresponding channel value specified by the name. If no channel value exists for the given name, a new channel is created. Multiple calls to Channel with the same name, will always return the same channel value pointer.

func (*Socket) Close ¶ Uses

Close the socket connection.

func (*Socket) ClosedChan ¶ Uses

ClosedChan returns a channel which is non-blocking (closed) as soon as the socket is closed.

func (*Socket) DiscardRead ¶ Uses

DiscardRead ignores and discars the data received from the client. Call this method during initialization, if you don’t read any data from the socket. 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.

func (*Socket) ID ¶ Uses

ID returns the socket’s unique ID. This is a cryptographically secure pseudorandom number.

func (*Socket) IsClosed ¶ Uses

IsClosed returns a boolean whenever the connection is closed.

func (*Socket) IsInitialized ¶ Uses

IsInitialized returns a boolean indicating if a socket is initialized and ready to be used. This flag is set to true after the OnNewSocket function has returned for this socket.

func (*Socket) OnClose ¶ Uses

OnClose sets the functions which is triggered if the socket connection is closed. This method can be called multiple times to bind multiple functions.

func (*Socket) OnRead ¶ Uses

OnRead sets the function which is triggered if new data is received. If this event function based method of reading data from the socket is used, then don’t use the socket Read method. Either use the OnRead or the Read approach.

func (*Socket) Read ¶ Uses

Read the next message from the socket. This method is blocking. One variadic argument sets a timeout duration. If no timeout is specified, this method will block forever. ErrSocketClosed is returned, if the socket connection is closed. ErrReadTimeout is returned, if the timeout is reached.

func (*Socket) RemoteAddr ¶ Uses

RemoteAddr returns the remote address of the client.

func (*Socket) UserAgent ¶ Uses

UserAgent returns the user agent of the client.

func (*Socket) Write ¶ Uses

Write data to the client.

Directories ¶

Path Synopsis
backend

Package backend provides the server backend with various socket implementations.
backend/closer

Emit a close function only once, also if called multiple times.
backend/global

Package global provides global types and constants for the backend packages.
backend/sockets/ajaxsocket

Package ajaxsocket provides the ajax socket implementation.
backend/sockets/websocket
log

Package log holds the log backend used by the socket library.
sample/Channels
sample/OnlyWrite
sample/ReadEventWrite
sample/ReadWrite
utils

Package utils provides utilities for the glue socket implementation.

Package glue imports 15 packages (graph) and is imported by 9 packages. Updated 2019-06-21 . Refresh now. Tools for package owners.

Package glue – Robust Go and Javascript Socket Library.

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