https://github.com/machinefi/w3bstream-client-go
https://github.com/machinefi/w3bstream-client-go
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/machinefi/w3bstream-client-go
- Owner: machinefi
- License: apache-2.0
- Created: 2023-08-03T17:02:57.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-07T22:05:55.000Z (almost 3 years ago)
- Last Synced: 2023-12-17T09:46:51.948Z (over 2 years ago)
- Language: Go
- Size: 4.55 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# w3bstream-client-go
The Go Client for W3bstream integration on server
## Getting started
Install `w3bstream-client-go`
``` shell
go get "github.com/machinefi/w3bstream-client-go"
```
## Example Code
### Publish Event Synchronously
``` go
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
``` go
import (
"github.com/machinefi/w3bstream-client-go/client"
)
err := cli.PublishEvent(
&Header{
DeviceID: "id",
},
[]byte("payload"),
)
```
### Publish Event Asynchronously with Response Error Handler
``` go
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"),
)
```