signalr

package module
v0.0.0-...-787ebe6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2019 License: MIT Imports: 7 Imported by: 0

README

= SignalR Golang Wrapper
The Bot Guy <thebotguy@protonmail.com>
hweom

This library allows to connect to a server using SignalR protocol.

== Getting the package
`go get` the package:
[source, bash]
----
$ go get github.com/thebotguys/signalr
----
Then import it in your code:
[source, go]
----
import "github.com/thebotguys/signalr"
----

== Usage
First of all create a client:
[source, go]
----
client := signalr.NewWebsocketClient()
----
Assign some functions:
[source, go]
----
client.OnClientMethod = func(hub, method string, arguments []json.RawMessage) {
    fmt.Println("Message Received: ")
    fmt.Println("HUB: ", hub)
    fmt.Println("METHOD: ", method)
    fmt.Println("ARGUMENTS: ", arguments)
}
client.OnErrorMethod = func (err error) {
   fmt.Println("ERROR OCCURRED: ", err)
}
----
Then connect it:
[source, go]
----
client.Connect("https", "destinationurl.com", []string{"hub1", "hub2"}) //and so forth
----
If you want to send messages to the server, use `CallHub` function:
[source, go]
----
client.CallHub("hub1", "GET", "params", 1, 1.4, "every type is accepted")
----
When you are done, just close the client's websocket:
[source, go]
----
client.Close()
----

=== Known issues
Calling `CallHub` without connecting a client will result in an infinite wait.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	OnMessageError func(err error)
	OnClientMethod func(hub, method string, arguments []json.RawMessage)
	// When client disconnects, the causing error is sent to this channel. Valid only after Connect().
	DisconnectedChannel chan bool
	// contains filtered or unexported fields
}

func NewWebsocketClient

func NewWebsocketClient() *Client

func (*Client) CallHub

func (self *Client) CallHub(hub, method string, params ...interface{}) (json.RawMessage, error)

Call server hub method. Dispatch() function must be running, otherwise this method will never return.

func (*Client) Close

func (self *Client) Close()

func (*Client) Connect

func (self *Client) Connect(scheme, host string, hubs []string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL