2018-10-14 16:44:21 +02:00
|
|
|
# Mainflux Go SDK
|
|
|
|
|
|
|
|
Go SDK, a Go driver for Mainflux HTTP API.
|
|
|
|
|
|
|
|
Does both system administration (provisioning) and messaging.
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
Import `"github.com/mainflux/mainflux/sdk/go"` in your Go package.
|
|
|
|
|
|
|
|
```
|
2020-06-03 15:16:19 +02:00
|
|
|
import "github.com/mainflux/mainflux/pkg/sdk/go"```
|
2018-10-14 16:44:21 +02:00
|
|
|
|
|
|
|
Then call SDK Go functions to interact with the system.
|
|
|
|
|
|
|
|
## API Reference
|
|
|
|
|
|
|
|
```go
|
|
|
|
FUNCTIONS
|
|
|
|
|
|
|
|
func NewMfxSDK(host, port string, tls bool) *MfxSDK
|
|
|
|
|
|
|
|
func (sdk *MfxSDK) Channel(id, token string) (things.Channel, error)
|
|
|
|
Channel - gets channel by ID
|
|
|
|
|
|
|
|
func (sdk *MfxSDK) Channels(token string) ([]things.Channel, error)
|
|
|
|
Channels - gets all channels
|
|
|
|
|
2020-03-03 10:58:30 +01:00
|
|
|
func (sdk *MfxSDK) Connect(struct{[]string, []string}, token string) error
|
|
|
|
Connect - connect things to channels
|
2018-10-14 16:44:21 +02:00
|
|
|
|
|
|
|
func (sdk *MfxSDK) CreateChannel(data, token string) (string, error)
|
|
|
|
CreateChannel - creates new channel and generates UUID
|
|
|
|
|
|
|
|
func (sdk *MfxSDK) CreateThing(data, token string) (string, error)
|
|
|
|
CreateThing - creates new thing and generates thing UUID
|
|
|
|
|
|
|
|
func (sdk *MfxSDK) CreateToken(user, pwd string) (string, error)
|
|
|
|
CreateToken - create user token
|
|
|
|
|
|
|
|
func (sdk *MfxSDK) CreateUser(user, pwd string) error
|
|
|
|
CreateUser - create user
|
|
|
|
|
2020-03-04 18:37:41 +01:00
|
|
|
func (sdk *MfxSDK) User(pwd string) (user, error)
|
|
|
|
User - gets user
|
|
|
|
|
|
|
|
func (sdk *MfxSDK) UpdateUser(user, pwd string) error
|
|
|
|
UpdateUser - update user
|
|
|
|
|
|
|
|
func (sdk *MfxSDK) UpdatePassword(user, pwd string) error
|
|
|
|
UpdatePassword - update user password
|
|
|
|
|
2018-10-14 16:44:21 +02:00
|
|
|
func (sdk *MfxSDK) DeleteChannel(id, token string) error
|
|
|
|
DeleteChannel - removes channel
|
|
|
|
|
|
|
|
func (sdk *MfxSDK) DeleteThing(id, token string) error
|
|
|
|
DeleteThing - removes thing
|
|
|
|
|
|
|
|
func (sdk *MfxSDK) DisconnectThing(thingID, chanID, token string) error
|
|
|
|
DisconnectThing - connect thing to a channel
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
func (sdk mfSDK) SendMessage(chanID, msg, token string) error
|
2018-10-14 16:44:21 +02:00
|
|
|
SendMessage - send message on Mainflux channel
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
func (sdk mfSDK) SetContentType(ct ContentType) error
|
2018-10-14 16:44:21 +02:00
|
|
|
SetContentType - set message content type. Available options are SenML
|
|
|
|
JSON, custom JSON and custom binary (octet-stream).
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
func (sdk mfSDK) Thing(id, token string) (Thing, error)
|
2018-10-14 16:44:21 +02:00
|
|
|
Thing - gets thing by ID
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
func (sdk mfSDK) Things(token string) ([]Thing, error)
|
2018-10-14 16:44:21 +02:00
|
|
|
Things - gets all things
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
func (sdk mfSDK) UpdateChannel(channel Channel, token string) error
|
2018-10-14 16:44:21 +02:00
|
|
|
UpdateChannel - update a channel
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
func (sdk mfSDK) UpdateThing(thing Thing, token string) error
|
2018-10-14 16:44:21 +02:00
|
|
|
UpdateThing - updates thing by ID
|
|
|
|
|
2022-01-24 21:18:53 +01:00
|
|
|
func (sdk mfSDK) Health() (mainflux.Health, error)
|
|
|
|
Health - things service health check
|
2018-10-14 16:44:21 +02:00
|
|
|
```
|