w3bstream-client-go

module
v0.0.0-...-4b345ff Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: Apache-2.0

README

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"),
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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