sdk

package
v0.0.0-...-8a250b4 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

README

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.

import "github.com/mainflux/mainflux/sdk/go"

Then call SDK Go functions to interact with the system.

API Reference

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

func (sdk *MfxSDK) ConnectThing(thingID, chanID, token string) error
    ConnectThing - connect thing to a channel

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

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

func (sdk mfSDK) SendMessage(chanID, msg, token string) error
    SendMessage - send message on Mainflux channel

func (sdk mfSDK) SetContentType(ct ContentType) error
    SetContentType - set message content type. Available options are SenML
    JSON, custom JSON and custom binary (octet-stream).

func (sdk mfSDK) Thing(id, token string) (Thing, error)
    Thing - gets thing by ID

func (sdk mfSDK) Things(token string) ([]Thing, error)
    Things - gets all things

func (sdk mfSDK) UpdateChannel(channel Channel, token string) error
    UpdateChannel - update a channel

func (sdk mfSDK) UpdateThing(thing Thing, token string) error
    UpdateThing - updates thing by ID

func (sdk mfSDK) Version() (string, error)
    Version - server health check

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConflict indicates that create or update of entity failed because
	// entity with same name already exists.
	ErrConflict = errors.New("entity already exists")

	// ErrFailedCreation indicates that entity creation failed.
	ErrFailedCreation = errors.New("failed to create entity")

	// ErrFailedUpdate indicates that entity update failed.
	ErrFailedUpdate = errors.New("failed to update entity")

	// ErrFailedPublish indicates that publishing message failed.
	ErrFailedPublish = errors.New("failed to publish message")

	// ErrFailedRead indicates that read messages failed.
	ErrFailedRead = errors.New("failed to read messages")

	// ErrFailedRemoval indicates that entity removal failed.
	ErrFailedRemoval = errors.New("failed to remove entity")

	// ErrFailedConnection indicates that connecting thing to channel failed.
	ErrFailedConnection = errors.New("failed to connect thing to channel")

	// ErrFailedDisconnect indicates that disconnecting thing from a channel failed.
	ErrFailedDisconnect = errors.New("failed to disconnect thing from channel")

	// ErrInvalidArgs indicates that invalid argument was passed.
	ErrInvalidArgs = errors.New("invalid argument passed")

	// ErrFetchFailed indicates that fetching of entity data failed.
	ErrFetchFailed = errors.New("failed to fetch entity")

	// ErrUnauthorized indicates unauthorized access.
	ErrUnauthorized = errors.New("unauthorized access")

	// ErrNotFound indicates that entity doesn't exist.
	ErrNotFound = errors.New("entity not found")

	// ErrInvalidContentType indicates that nonexistent message content type
	// was passed.
	ErrInvalidContentType = errors.New("Unknown Content Type")
)

Functions

This section is empty.

Types

type Channel

type Channel struct {
	ID       string                 `json:"id,omitempty"`
	Name     string                 `json:"name"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Channel represents mainflux channel.

type ChannelsPage

type ChannelsPage struct {
	Channels []Channel `json:"channels"`
	Total    uint64    `json:"total"`
	Offset   uint64    `json:"offset"`
	Limit    uint64    `json:"limit"`
}

ChannelsPage contains list of channels in a page with proper metadata.

type Config

type Config struct {
	BaseURL           string
	ReaderURL         string
	ReaderPrefix      string
	UsersPrefix       string
	ThingsPrefix      string
	HTTPAdapterPrefix string
	MsgContentType    ContentType
	TLSVerification   bool
}

Config contains sdk configuration parameters.

type ContentType

type ContentType string

ContentType represents all possible content types.

const (
	// CTJSON represents JSON content type.
	CTJSON ContentType = "application/json"

	// CTJSONSenML represents JSON SenML content type.
	CTJSONSenML ContentType = "application/senml+json"

	// CTBinary represents binary content type.
	CTBinary ContentType = "application/octet-stream"
)

type SDK

type SDK interface {
	// CreateUser registers mainflux user.
	CreateUser(user User) error

	// CreateToken receives credentials and returns user token.
	CreateToken(user User) (string, error)

	// CreateThing registers new thing and returns its id.
	CreateThing(thing Thing, token string) (string, error)

	// Things returns page of things.
	Things(token string, offset, limit uint64) (ThingsPage, error)

	// ThingsByChannel returns page of things that are connected to specified
	// channel.
	ThingsByChannel(token, chanID string, offset, limit uint64) (ThingsPage, error)

	// Thing returns thing object by id.
	Thing(id, token string) (Thing, error)

	// UpdateThing updates existing thing.
	UpdateThing(thing Thing, token string) error

	// DeleteThing removes existing thing.
	DeleteThing(id, token string) error

	// ConnectThing connects thing to specified channel by id.
	ConnectThing(thingID, chanID, token string) error

	// DisconnectThing disconnect thing from specified channel by id.
	DisconnectThing(thingID, chanID, token string) error

	// CreateChannel creates new channel and returns its id.
	CreateChannel(channel Channel, token string) (string, error)

	// Channels returns page of channels.
	Channels(token string, offset, limit uint64) (ChannelsPage, error)

	// ChannelsByThing returns page of channels that are connected to specified
	// thing.
	ChannelsByThing(token, thingID string, offset, limit uint64) (ChannelsPage, error)

	// Channel returns channel data by id.
	Channel(id, token string) (Channel, error)

	// UpdateChannel updates existing channel.
	UpdateChannel(channel Channel, token string) error

	// DeleteChannel removes existing channel.
	DeleteChannel(id, token string) error

	// SendMessage send message to specified channel.
	SendMessage(chanID, msg, token string) error

	// ReadMessages read messages of specified channel.
	ReadMessages(chanID, token string) ([]mainflux.Message, error)

	// SetContentType sets message content type.
	SetContentType(ct ContentType) error

	// Version returns used mainflux version.
	Version() (string, error)
}

SDK contains Mainflux API.

func NewSDK

func NewSDK(conf Config) SDK

NewSDK returns new mainflux SDK instance.

type Thing

type Thing struct {
	ID       string                 `json:"id,omitempty"`
	Name     string                 `json:"name,omitempty"`
	Key      string                 `json:"key,omitempty"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Thing represents mainflux thing.

type ThingsPage

type ThingsPage struct {
	Things []Thing `json:"things"`
	Total  uint64  `json:"total"`
	Offset uint64  `json:"offset"`
	Limit  uint64  `json:"limit"`
}

ThingsPage contains list of things in a page with proper metadata.

type User

type User struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

User represents mainflux user its credentials.

Jump to

Keyboard shortcuts

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