Go client for dSock.
go get github.com/Cretezy/dSock-go
import "github.com/Cretezy/dSock-go"
dSockClient := dsock.NewClient(dSockUrl, dSockToken)
Create a claim for user authentication.
claim, err := dSockClient.CreateClaim(dsock.CreateClaimOptions{
User: "user",
// optional
Session: "session",
Id: "id",
Channels: []string{"channel"},
// either or
Duration: 30, // in seconds
Expiration: 1600000000, // in seconds since epoch
})
Send a message to a target (one or many clients).
err := dSockClient.SendMessage(dsock.SendMessageOptions{
Type: "text", // or `binary`
Message: []byte("hello world"),
// target (choose one or many)
Target: dsock.Target{
User: "user",
Session: "session",
Id: "id",
Channel: "channel",
},
})
Disconnect a target (one or many clients).
err := dSockClient.Disconnect(dsock.DisconnectOptions{
// target (choose one or many)
Target: dsock.Target{
User: "user",
Session: "session",
Id: "id",
Channel: "channel",
},
})
Get claim and connection info from a target (one or many clients).
info, err := dSockClient.GetInfo(dsock.GetInfoOptions{
// target (choose one or many)
Target: dsock.Target{
User: "user",
Session: "session",
Id: "id",
Channel: "channel",
},
})
Subscribe/unsubscribe a target to a channel (one or many clients).
err := dSockClient.SubscribeChannel(dsock.ChannelOptions{
Channel: "new_channel",
// Should claims also be subscribed?
IgnoreClaims: true,
// target (choose one or many)
Target: dsock.Target{
User: "user",
Session: "session",
Id: "id",
Channel: "channel",
},
})
err := dSockClient.UnsubscribeChannel(dsock.ChannelOptions{
Channel: "remove_channel",
// Should claims also be unsubscribed?
IgnoreClaims: true,
// target (choose one or many)
Target: dsock.Target{
User: "user",
Session: "session",
Id: "id",
Channel: "channel",
},
})