sdk

package
v0.41.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 17 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/MainfluxLabs/mainflux/sdk/go" in your Go package.

import "github.com/MainfluxLabs/mainflux/pkg/sdk/go"```

Then call SDK Go functions to interact with the system.

## API Reference

```go
FUNCTIONS

func NewSDK(conf Config) mfSDK

func (sdk mfSDK) CreateUser(token string, user User) (string, error)
    CreateUser - create user

func (sdk mfSDK) User(token, id string) (User, error)
    User - gets user

func (sdk mfSDK) Users(token string, pm PageMetadata) (UsersPage, error)
    Users - gets list of users.
    
func (sdk mfSDK) CreateToken(user User) (string, error)
    CreateToken - create user token

func (sdk mfSDK) RegisterUser(user User) (string, error)
    RegisterUser - registers mainflux user
    
func (sdk mfSDK) UpdateUser(user User, token string) error
    UpdateUser - update user

func (sdk mfSDK) UpdatePassword(oldPass, newPass, token string) error
    UpdatePassword - update user password

func (sdk mfSDK) CreateThing(thing Thing, groupID, token string) (string, error)
    CreateThing - creates new thing and generates thing UUID

func (sdk mfSDK) CreateThings(things []Thing, groupID, token string) ([]Thing, error)
    CreateThings - registers new things 
	
func (sdk mfSDK) Things(token string, pm PageMetadata) (ThingsPage, error)
     Things - gets all things
	
func (sdk mfSDK) ThingsByProfile(token, profileID string, offset, limit uint64) (ThingsPage, error)
    ThingsByProfile - gets things by profile
	
func (sdk mfSDK) Thing(id, token string) (Thing, error)
    Thing - gets thing by id.
    
func (sdk mfSDK) MetadataByKey(thingKey string) (Metadata, error)
    MetadataByKey - gets thing metadata by key.

func (sdk mfSDK) UpdateThing(thing Thing, token string) error
    UpdateThing - updates existing thing
    
func (sdk mfSDK) DeleteThing(id, token string) error
    DeleteThing - removes thing

func (sdk mfSDK) DeleteThings(ids []string, token string) error
    DeleteThings - removes existing things
	
func (sdk mfSDK) IdentifyThing(key string) (string, error)
     IdentifyThing - validates thing's key and returns its ID
	
func (sdk mfSDK) CreateGroup(group Group, orgID, token string) (string, error)
    CreateGroup - creates new group
	
func (sdk mfSDK) DeleteGroup(id, token string) error
    DeleteGroup - deletes users group

func (sdk mfSDK) DeleteGroups(ids []string, token string) error
	DeleteGroups - delete users groups
	
func (sdk mfSDK) Groups(meta PageMetadata, token string) (GroupsPage, error)
    Groups - returns page of groups
	
func (sdk mfSDK) Group(id, token string) (Group, error)
    Group - returns users group by id
	 
func (sdk mfSDK) ListThingsByGroup(groupID, token string, offset, limit uint64) (ThingsPage, error)
    ListThingsByGroup - lists things by group

func (sdk mfSDK) ViewGroupByThing(thingID, token string) (Group, error)
    ViewGroupByThing - retrieves a group by thing
    
func (sdk mfSDK) UpdateGroup(group Group, token string) error
    UpdateGroup - updates existing group
    
func (sdk mfSDK) CreateProfile(profile Profile, groupID, token string) (string, error)
    CreateProfile - creates new profile and generates UUID

func (sdk mfSDK) CreateProfiles(profiles []Profile, groupID, token string) ([]Profile, error)
    CreateProfiles - registers new profiles
    
func (sdk mfSDK) Profiles(token string) ([]things.Profile, error)
    Profiles - gets all profiles

func (sdk mfSDK) ViewProfileByThing(token, thingID string) (Profile, error)
    ViewProfileByThing - returns profile by thing
    
func (sdk mfSDK) Profile(id, token string) (things.Profile, error)
    Profile - gets profile by ID

func (sdk mfSDK) UpdateProfile(profile Profile, token string) error
    UpdateProfile - updates existing profile
    
func (sdk mfSDK) DeleteProfile(id, token string) error
    DeleteProfile - removes profile

func (sdk mfSDK) DeleteProfiles(ids []string, token string) error
    DeleteProfiles - removes existing profiles
    
func (sdk mfSDK) ListProfilesByGroup(groupID, token string, offset, limit uint64) (ProfilesPage, error)
    ListProfilesByGroup - lists profiles by group
    
func (sdk mfSDK) ViewGroupByProfile(profileID, token string) (Group, error)
    ViewGroupByProfile retrieves a group by profile
    
func (sdk mfSDK) CreateGroupMemberships(gms []GroupMembership, groupID, token string) error
    CreateGroupMemberships - creates memberships to the specified group
    
func (sdk mfSDK) UpdateGroupMemberships(gms []GroupMembership, groupID, token string) error
    UpdateGroupMemberships - updates existing memberships
	
func (sdk mfSDK) RemoveGroupMemberships(ids []string, groupID, token string) error
    RemoveGroupMemberships - removes memberships from the specified group
	
func (sdk mfSDK) ListGroupMemberships(groupID string, pm PageMetadata, token string) (GroupMembershipsPage, error)
    ListGroupMemberships - lists memberships created for a specified group
 
func (sdk mfSDK) CreateOrg(org Org, token string) error
    CreateOrg - registers new org
	
func (sdk mfSDK) Org(id, token string) (Org, error)
    Org - returns org data by id
	
func (sdk mfSDK) UpdateOrg(o Org, token string) error
    UpdateOrg - updates existing org

func (sdk mfSDK) DeleteOrg(id, token string) error
    DeleteOrg - removes existing org

func (sdk mfSDK) Orgs(meta PageMetadata, token string) (OrgsPage, error)
    Orgs - returns page of orgs

func (sdk mfSDK) GetOrgMembership(memberID, orgID, token string) (OrgMembership, error)
    GetOrgMembership - retrieves a membership for the specified org and member
	
func (sdk mfSDK) CreateOrgMemberships(oms []OrgMembership, orgID, token string) error
    CreateOrgMemberships - creates memberships to the specified org
	
func (sdk mfSDK) RemoveOrgMemberships(token, orgID string, memberIDs ...string) error
    RemoveOrgMemberships - removes memberships from the specified org
    
func (sdk mfSDK) UpdateOrgMemberships(oms []OrgMembership, orgID, token string) error
    UpdateOrgMemberships - updates existing memberships

func (sdk mfSDK) ListOrgMemberships(orgID string, meta PageMetadata, token string) (OrgMembershipsPage, error)
    ListOrgMemberships - lists memberships created for a specified org
	
func (sdk mfSDK) CreateWebhooks(whs []Webhook, groupID, token string) ([]Webhook, error)
    CreateWebhooks - creates new webhooks
	
func (sdk mfSDK) ListWebhooksByGroup(groupID, token string) (Webhooks, error)
    ListWebhooksByGroup - lists webhooks by group
	
func (sdk mfSDK) Webhook(webhookID, token string) (Webhook, error)
    Webhook - returns webhook by id
	
func (sdk mfSDK) UpdateWebhook(wh Webhook, token string) error
    UpdateWebhook - updates existing webhook
	
func (sdk mfSDK) DeleteWebhooks(ids []string, groupID, token string) error
    DeleteWebhooks - removes existing webhooks
    
func (sdk mfSDK) SendMessage(profileID, msg, token string) error
    SendMessage - send message on Mainflux Profile

func (sdk mfSDK) ReadMessages(profileID, token string) (MessagesPage, error)
    ReadMessages - read messages of specified profile

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

func (sdk mfSDK) Health() (mainflux.HealthInfo, error)
    Health - things service health check

func (sdk mfSDK) IssueCert(thingID string, keyBits int, keyType, valid, token string) (Cert, error)
    IssueCert - issues a certificate for a thing required for mtls

func (sdk mfSDK) RemoveCert(id, token string) error
    RemoveCert - removes a certificate

func (sdk mfSDK) RevokeCert(thingID, certID, token string) error
    RevokeCert - revokes certificate with certID for thing with thingID

func (sdk mfSDK) Issue(token string, duration time.Duration) (KeyRes, error)
    Issue - issues a new key, returning its token value alongside
	
func (sdk mfSDK) Revoke(token, id string) error
    Revoke - removes the key with the provided ID 
    
func (sdk mfSDK) RetrieveKey(token, id string) (retrieveKeyRes, error)
	RetrieveKey - retrieves data for the key identified by the provided ID

Documentation

Index

Constants

View Source
const (
	UserTypeInviter = "inviter"
	UserTypeInvitee = "invitee"
)
View Source
const (
	// LoginKey is temporary User key received on successfull login.
	LoginKey uint32 = iota
	// RecoveryKey represents a key for resseting password.
	RecoveryKey
	// APIKey enables the one to act on behalf of the user.
	APIKey
)

Variables

View Source
var (
	// 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")

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

	// ErrFailedRemoval indicates that entity removal failed.
	ErrFailedRemoval = errors.New("failed to remove 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")

	// ErrInvalidContentType indicates that non-existent message content type
	// was passed.
	ErrInvalidContentType = errors.New("unknown content-type")

	// ErrFetchHealth indicates that fetching of health check failed.
	ErrFetchHealth = errors.New("failed to fetch health check")

	// ErrCerts indicates error fetching certificates.
	ErrCerts = errors.New("failed to fetch certs data")

	// ErrCertsRemove indicates failure while cleaning up from the Certs service.
	ErrCertsRemove = errors.New("failed to remove certificate")
)

Functions

This section is empty.

Types

type Cert

type Cert struct {
	ThingID        string    `json:"thing_id,omitempty"`
	Certificate    string    `json:"certificate,omitempty"`
	PrivateKey     string    `json:"private_key,omitempty"`
	IssuingCA      string    `json:"issuing_ca,omitempty"`
	CAChain        []string  `json:"ca_chain,omitempty"`
	PrivateKeyType string    `json:"private_key_type,omitempty"`
	Serial         string    `json:"serial,omitempty"`
	ExpiresAt      time.Time `json:"expires_at,omitempty"`
}

Cert represents certs data.

type CertSerial added in v0.38.0

type CertSerial struct {
	ThingID    string    `json:"thing_id"`
	CertSerial string    `json:"cert_serial"`
	ExpiresAt  time.Time `json:"expires_at"`
}

CertSerial represents a certificate serial entry in a listing.

type CertsPage added in v0.38.0

type CertsPage struct {
	Total  uint64       `json:"total"`
	Offset uint64       `json:"offset"`
	Limit  uint64       `json:"limit"`
	Certs  []CertSerial `json:"certs"`
}

CertsPage contains a page of certificate serials.

type Config

type Config struct {
	AuthURL        string
	CertsURL       string
	HTTPAdapterURL string
	ReaderURL      string
	ThingsURL      string
	UsersURL       string
	WebhooksURL    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 Group

type Group struct {
	ID          string         `json:"id,omitempty"`
	Name        string         `json:"name,omitempty"`
	OwnerID     string         `json:"owner_id,omitempty"`
	OrgID       string         `json:"org_id,omitempty"`
	Description string         `json:"description,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
	CreatedAt   time.Time      `json:"created_at,omitempty"`
	UpdatedAt   time.Time      `json:"updated_at,omitempty"`
}

Group represents mainflux users group.

type GroupMembership added in v0.29.0

type GroupMembership struct {
	MemberID string `json:"member_id,omitempty"`
	Role     string `json:"role,omitempty"`
	Email    string `json:"email,omitempty"`
}

GroupMembership represents mainflux Group Membership.

type GroupMembershipsPage added in v0.29.0

type GroupMembershipsPage struct {
	GroupMemberships []GroupMembership `json:"group_memberships"`
	// contains filtered or unexported fields
}

GroupMembershipsPage contains a list of memberships for a certain group with proper metadata.

type GroupsPage

type GroupsPage struct {
	Groups []Group `json:"groups"`
	// contains filtered or unexported fields
}

GroupsPage contains list of groups in a page with proper metadata.

type Invite added in v0.30.0

type Invite struct {
	ID           string    `json:"id"`
	InviteeID    string    `json:"invitee_id"`
	InviteeEmail string    `json:"invitee_email"`
	InviterID    string    `json:"inviter_id"`
	OrgID        string    `json:"org_id"`
	InviteeRole  string    `json:"invitee_role"`
	CreatedAt    time.Time `json:"created_at"`
	ExpiresAt    time.Time `json:"expires_at"`
}

type InvitesPage added in v0.30.0

type InvitesPage struct {
	Invites []Invite `json:"invites,omitempty"`
	// contains filtered or unexported fields
}

type JSONPageMetadata added in v0.38.0

type JSONPageMetadata struct {
	Offset      uint64   `json:"offset"`
	Limit       uint64   `json:"limit"`
	Subtopic    string   `json:"subtopic,omitempty"`
	Publisher   string   `json:"publisher,omitempty"`
	Protocol    string   `json:"protocol,omitempty"`
	From        int64    `json:"from,omitempty"`
	To          int64    `json:"to,omitempty"`
	Filter      string   `json:"filter,omitempty"`
	AggInterval string   `json:"agg_interval,omitempty"`
	AggValue    uint64   `json:"agg_value,omitempty"`
	AggType     string   `json:"agg_type,omitempty"`
	AggFields   []string `json:"agg_fields,omitempty"`
	Dir         string   `json:"dir,omitempty"`
}

JSONPageMetadata represents query parameters for JSON message endpoints.

type Key

type Key struct {
	ID        string
	Type      uint32
	IssuerID  string
	Subject   string
	IssuedAt  time.Time
	ExpiresAt time.Time
}

type KeyRes

type KeyRes struct {
	ID        string     `json:"id,omitempty"`
	Value     string     `json:"value,omitempty"`
	IssuedAt  time.Time  `json:"issued_at,omitempty"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
}

func (KeyRes) Code

func (res KeyRes) Code() int

func (KeyRes) Empty

func (res KeyRes) Empty() bool

func (KeyRes) Headers

func (res KeyRes) Headers() map[string]string

type MessagesPage

type MessagesPage struct {
	Messages []senml.Message `json:"messages,omitempty"`
	// contains filtered or unexported fields
}

MessagesPage contains list of messages in a page with proper metadata.

type Metadata added in v0.25.0

type Metadata map[string]any

type Org

type Org struct {
	ID          string         `json:"id,omitempty"`
	OwnerID     string         `json:"owner_id,omitempty"`
	Name        string         `json:"name,omitempty"`
	Description string         `json:"description,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
	CreatedAt   time.Time      `json:"created_at,omitempty"`
	UpdatedAt   time.Time      `json:"updated_at,omitempty"`
}

Org represents mainflux org.

type OrgMembership added in v0.29.0

type OrgMembership struct {
	MemberID  string    `json:"member_id,omitempty"`
	OrgID     string    `json:"org_id,omitempty"`
	Role      string    `json:"role,omitempty"`
	CreatedAt time.Time `json:"created_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	Email     string    `json:"email,omitempty"`
}

OrgMembership represents mainflux Org Membership.

type OrgMembershipsPage added in v0.29.0

type OrgMembershipsPage struct {
	OrgMemberships []OrgMembership `json:"org_memberships"`
	// contains filtered or unexported fields
}

OrgMembershipsPage contains org memberships in a page with proper metadata.

type OrgsPage

type OrgsPage struct {
	Orgs []Org `json:"orgs"`
	// contains filtered or unexported fields
}

OrgsPage contains list of orgs in a page with proper metadata.

type PageMetadata

type PageMetadata struct {
	Total    uint64         `json:"total"`
	Offset   uint64         `json:"offset"`
	Limit    uint64         `json:"limit"`
	Order    string         `json:"order"`
	Dir      string         `json:"dir"`
	Subtopic string         `json:"subtopic,omitempty"`
	Format   string         `json:"format,omitempty"`
	Email    string         `json:"email,omitempty"`
	Name     string         `json:"name,omitempty"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

type Profile added in v0.24.0

type Profile struct {
	ID       string         `json:"id,omitempty"`
	GroupID  string         `json:"group_id,omitempty"`
	Name     string         `json:"name,omitempty"`
	Config   map[string]any `json:"config,omitempty"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

Profile represents mainflux profile.

type ProfilesPage added in v0.24.0

type ProfilesPage struct {
	Profiles []Profile `json:"profiles"`
	// contains filtered or unexported fields
}

ProfilesPage contains list of profiles in a page with proper metadata.

type SDK

type SDK interface {
	// CreateUser creates mainflux user.
	CreateUser(user User, token string) (string, error)

	// GetUser returns user object by id.
	GetUser(id, token string) (User, error)

	// ListUsers returns list of users.
	ListUsers(pm PageMetadata, token string) (UsersPage, error)

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

	// RegisterUser registers mainflux user.
	RegisterUser(user User) (string, error)

	// UpdateUser updates existing user.
	UpdateUser(user User, token string) error

	// UpdatePassword updates user password.
	UpdatePassword(oldPass, newPass, token string) error

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

	// CreateThings registers new things and returns their ids.
	CreateThings(things []Thing, profileID, token string) ([]Thing, error)

	// ListThings returns page of things.
	ListThings(pm PageMetadata, token string) (ThingsPage, error)

	// ListThingsByProfile returns page of things assigned to the specified profile.
	ListThingsByProfile(profileID string, pm PageMetadata, token string) (ThingsPage, error)

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

	// GetThingMetadataByKey retrieves metadata about the thing identified by the given key.
	GetThingMetadataByKey(key domain.ThingKey) (Metadata, error)

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

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

	// DeleteThings removes existing things.
	DeleteThings(ids []string, token string) error

	// IdentifyThing validates thing's key and returns its ID
	IdentifyThing(key domain.ThingKey) (string, error)

	// UpdateExternalThingKey sets the external key of the Thing identified by `thingID`.`
	UpdateExternalThingKey(key, thingID, token string) error

	// CreateGroup creates new group and returns its id.
	CreateGroup(group Group, orgID, token string) (string, error)

	// DeleteGroup deletes users group.
	DeleteGroup(id, token string) error

	// DeleteGroups delete users groups.
	DeleteGroups(ids []string, token string) error

	// ListGroups returns page of groups.
	ListGroups(meta PageMetadata, token string) (GroupsPage, error)

	// ListGroupsByOrg returns a page of all Groups belonging to the spcified Org.
	ListGroupsByOrg(orgID string, meta PageMetadata, token string) (GroupsPage, error)

	// GetGroup returns users group object by id.
	GetGroup(id, token string) (Group, error)

	// ListThingsByGroup lists things that are members of specified group.
	ListThingsByGroup(groupID string, meta PageMetadata, token string) (ThingsPage, error)

	// GetGroupByThing retrieves a group that the specified thing is a member of.
	GetGroupByThing(thingID, token string) (Group, error)

	// UpdateGroup updates existing group.
	UpdateGroup(group Group, groupID, token string) error

	// CreateProfile creates new profile and returns its id.
	CreateProfile(profile Profile, groupID, token string) (string, error)

	// CreateProfiles registers new profiles and returns their ids.
	CreateProfiles(profiles []Profile, groupID, token string) ([]Profile, error)

	// ListProfiles returns page of profiles.
	ListProfiles(pm PageMetadata, token string) (ProfilesPage, error)

	// GetProfileByThing returns profile that are assigned to specified thing.
	GetProfileByThing(thingID, token string) (Profile, error)

	// GetProfile returns profile data by id.
	GetProfile(id, token string) (Profile, error)

	// UpdateProfile updates existing profile.
	UpdateProfile(profile Profile, profileID, token string) error

	// DeleteProfile removes existing profile.
	DeleteProfile(id, token string) error

	// DeleteProfiles removes existing profile.
	DeleteProfiles(ids []string, token string) error

	// ListProfilesByGroup lists profiles that are members of specified group.
	ListProfilesByGroup(groupID string, pm PageMetadata, token string) (ProfilesPage, error)

	// GetGroupByProfile retrieves a group that the specified profile is a member of.
	GetGroupByProfile(profileID, token string) (Group, error)

	// CreateGroupMemberships creates memberships to the specified group.
	CreateGroupMemberships(gms []GroupMembership, groupID, token string) error

	// UpdateGroupMemberships updates existing memberships.
	UpdateGroupMemberships(gms []GroupMembership, groupID, token string) error

	// RemoveGroupMemberships removes memberships from the specified group.
	RemoveGroupMemberships(ids []string, groupID, token string) error

	// ListGroupMemberships lists memberships created for a specified group.
	ListGroupMemberships(groupID string, pm PageMetadata, token string) (GroupMembershipsPage, error)

	// CreateOrg registers a new Org and returns its ID.
	CreateOrg(org Org, token string) (string, error)

	// GetOrg returns org data by id.
	GetOrg(id, token string) (Org, error)

	// UpdateOrg updates existing org.
	UpdateOrg(o Org, orgID, token string) error

	// DeleteOrg removes existing org.
	DeleteOrg(id, token string) error

	// ListOrgs returns page of orgs.
	ListOrgs(meta PageMetadata, token string) (OrgsPage, error)

	// CreateOrgMemberships creates memberships to the specified org.
	CreateOrgMemberships(oms []OrgMembership, orgID, token string) error

	// GetOrgMembership retrieves a membership for the specified org and member.
	GetOrgMembership(memberID, orgID, token string) (OrgMembership, error)

	// ListOrgMemberships lists memberships created for a specified org.
	ListOrgMemberships(orgID string, meta PageMetadata, token string) (OrgMembershipsPage, error)

	// UpdateOrgMemberships updates existing memberships.
	UpdateOrgMemberships(oms []OrgMembership, orgID, token string) error

	// RemoveOrgMemberships removes memberships from the specified org.
	RemoveOrgMemberships(memberIDs []string, orgID, token string) error

	// SendMessage send message.
	SendMessage(subtopic, msg string, key domain.ThingKey) error

	// ReadMessages read messages.
	ReadMessages(isAdmin bool, pm PageMetadata, keyType, token string) (map[string]any, error)

	// ListJSONMessages lists JSON messages with filtering.
	ListJSONMessages(pm JSONPageMetadata, token string, key domain.ThingKey) (map[string]any, error)

	// ListSenMLMessages lists SenML messages with filtering.
	ListSenMLMessages(pm SenMLPageMetadata, token string, key domain.ThingKey) (map[string]any, error)

	// DeleteJSONMessages deletes JSON messages by publisher.
	DeleteJSONMessages(publisherID, token string, pm JSONPageMetadata) error

	// DeleteSenMLMessages deletes SenML messages by publisher.
	DeleteSenMLMessages(publisherID, token string, pm SenMLPageMetadata) error

	// DeleteAllJSONMessages deletes all JSON messages (admin only).
	DeleteAllJSONMessages(token string, pm JSONPageMetadata) error

	// DeleteAllSenMLMessages deletes all SenML messages (admin only).
	DeleteAllSenMLMessages(token string, pm SenMLPageMetadata) error

	// ExportJSONMessages exports JSON messages.
	ExportJSONMessages(token string, pm JSONPageMetadata, convert, timeFormat string) ([]byte, error)

	// ExportSenMLMessages exports SenML messages.
	ExportSenMLMessages(token string, pm SenMLPageMetadata, convert, timeFormat string) ([]byte, error)

	// BackupMessages backs up all messages (admin only).
	BackupMessages(token string) ([]byte, error)

	// RestoreMessages restores messages from backup data (admin only).
	RestoreMessages(token string, data []byte) error

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

	// Health returns things service health check.
	Health() (mainflux.HealthInfo, error)

	// IssueCert issues a certificate for a thing required for mtls.
	IssueCert(thingID string, keyBits int, keyType, valid, token string) (Cert, error)

	// ViewCert retrieves a certificate by its serial number.
	ViewCert(serial, token string) (Cert, error)

	// RevokeCert revokes a certificate by its serial number.
	RevokeCert(serial, token string) error

	// RenewCert renews a certificate by its serial number.
	RenewCert(serial, token string) (Cert, error)

	// ListSerials lists certificate serial numbers for a given thing.
	ListSerials(thingID string, offset, limit uint64, token string) (CertsPage, error)

	// RemoveCert removes a certificate.
	RemoveCert(id, token string) error

	// Issue issues a new key, returning its token value alongside.
	Issue(duration time.Duration, token string) (KeyRes, error)

	// Revoke removes the key with the provided ID that is issued by the user identified by the provided key.
	Revoke(id, token string) error

	// RetrieveKey retrieves data for the key identified by the provided ID, that is issued by the user identified by the provided key.
	RetrieveKey(id, token string) (retrieveKeyRes, error)

	// CreateInvite creates and sends a new Invite.
	CreateInvite(orgID string, om OrgMembership, token string) (Invite, error)

	// RevokeInvite revokes a specific Invite.
	RevokeInvite(inviteID string, token string) error

	// InviteRespond responds to a specific Invite either accepting or declining it.
	InviteRespond(inviteID string, accept bool, token string) error

	// GetInvite retrieves a specific Invite.
	GetInvite(inviteID string, token string) (Invite, error)

	// ListInvitesByUser retrieves a list of Invites either sent out by, or sent to the user identifed by
	// the specific userID.
	ListInvitesByUser(userID string, userType string, pm PageMetadata, token string) (InvitesPage, error)

	// CreateWebhooks creates new webhooks.
	CreateWebhooks(whs []Webhook, groupID, token string) ([]Webhook, error)

	// ListWebhooksByGroup lists webhooks who belong to a specified group.
	ListWebhooksByGroup(groupID, token string) (WebhooksPage, error)

	// ListWebhooksByThing lists webhooks who belong to a specified thing.
	ListWebhooksByThing(thingID, token string) (WebhooksPage, error)

	// GetWebhook returns webhook data by id.
	GetWebhook(webhookID, token string) (Webhook, error)

	// UpdateWebhook updates existing webhook.
	UpdateWebhook(wh Webhook, webhookID, token string) error

	// DeleteWebhooks removes existing webhooks.
	DeleteWebhooks(ids []string, token string) error
}

SDK contains Mainflux API.

func NewSDK

func NewSDK(conf Config) SDK

NewSDK returns new mainflux SDK instance.

type SenMLPageMetadata added in v0.38.0

type SenMLPageMetadata struct {
	Offset      uint64   `json:"offset"`
	Limit       uint64   `json:"limit"`
	Subtopic    string   `json:"subtopic,omitempty"`
	Publisher   string   `json:"publisher,omitempty"`
	Protocol    string   `json:"protocol,omitempty"`
	Name        string   `json:"name,omitempty"`
	Value       float64  `json:"v,omitempty"`
	Comparator  string   `json:"comparator,omitempty"`
	BoolValue   bool     `json:"vb,omitempty"`
	StringValue string   `json:"vs,omitempty"`
	DataValue   string   `json:"vd,omitempty"`
	From        int64    `json:"from,omitempty"`
	To          int64    `json:"to,omitempty"`
	AggInterval string   `json:"agg_interval,omitempty"`
	AggValue    uint64   `json:"agg_value,omitempty"`
	AggType     string   `json:"agg_type,omitempty"`
	AggFields   []string `json:"agg_fields,omitempty"`
	Dir         string   `json:"dir,omitempty"`
}

SenMLPageMetadata represents query parameters for SenML message endpoints.

type Thing

type Thing struct {
	ID        string         `json:"id,omitempty"`
	GroupID   string         `json:"group_id,omitempty"`
	ProfileID string         `json:"profile_id,omitempty"`
	Name      string         `json:"name,omitempty"`
	Type      string         `json:"type,omitempty"`
	Key       string         `json:"key,omitempty"`
	Metadata  map[string]any `json:"metadata,omitempty"`
}

Thing represents mainflux thing.

type ThingsPage

type ThingsPage struct {
	Things []Thing `json:"things"`
	// contains filtered or unexported fields
}

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

type User

type User struct {
	ID       string         `json:"id,omitempty"`
	Email    string         `json:"email,omitempty"`
	Groups   []string       `json:"groups,omitempty"`
	Password string         `json:"password,omitempty"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

User represents mainflux user its credentials.

type UserPasswordReq

type UserPasswordReq struct {
	OldPassword string `json:"old_password,omitempty"`
	Password    string `json:"password,omitempty"`
}

UserPasswordReq contains old and new passwords

type UsersPage

type UsersPage struct {
	Users []User `json:"users"`
	// contains filtered or unexported fields
}

UsersPage contains list of users in a page with proper metadata.

type Webhook

type Webhook struct {
	ID      string            `json:"id"`
	GroupID string            `json:"group_id"`
	Name    string            `json:"name"`
	Url     string            `json:"url"`
	Headers map[string]string `json:"headers"`
}

type WebhooksPage added in v0.36.0

type WebhooksPage struct {
	Webhooks []Webhook `json:"webhooks"`
	// contains filtered or unexported fields
}

WebhooksPage contains list of webhooks in a page with proper metadata.

Jump to

Keyboard shortcuts

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