This library allows to connect to a server using SignalR protocol.
go get
the package:
$ go get github.com/thebotguys/signalr
Then import it in your code:
import "github.com/thebotguys/signalr"
First of all create a client:
client := signalr.NewWebsocketClient()
Assign some functions:
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:
client.Connect("https", "destinationurl.com", []string{"hub1", "hub2"}) //and so forth
If you want to send messages to the server, use CallHub
function:
client.CallHub("hub1", "GET", "params", 1, 1.4, "every type is accepted")
When you are done, just close the client’s websocket:
client.Close()