w3bstream-client-go
The Go Client for W3bstream integration on server
Getting started
Install w3bstream-client-go
go get "github.com/machinefi/w3bstream-client-go"
Example Code
Publish Event Synchronously
import (
"github.com/machinefi/w3bstream-client-go/client"
)
// the http_route, project and api_key are obtained on W3bstream-Studio
cli := NewClient("http_route", "api_key")
// defer cli.Close()
// device_id is the identity for the device
// payload can be an empty string if served as a heartbeat
resp, err := cli.PublishEventSync(
&Header{
DeviceID: "device_id",
},
[]byte("payload"),
)
Publish Event Asynchronously
import (
"github.com/machinefi/w3bstream-client-go/client"
)
err := cli.PublishEvent(
&Header{
DeviceID: "id",
},
[]byte("payload"),
)
Publish Event Asynchronously with Response Error Handler
import (
"github.com/machinefi/w3bstream-client-go/client"
)
cli := NewClient("http_route", "api_key", WithErrHandler(func(err error) {
fmt.Println(err)
}))
err := cli.PublishEvent(
&Header{
DeviceID: "id",
},
[]byte("payload"),
)