package
1.3.0
Repository: https://github.com/iofog/container-sdk-go.git
Documentation: pkg.go.dev

# README

Microservices Package

This package gives you all the functionality to interact with ioFog both via Local API and WebSockets:

  • send new message to ioFog with REST (PostMessage)
  • fetch next unread messages from ioFog (GetNextMessages)
  • fetch messages for time period and list of publishers (GetMessagesFromPublishersWithinTimeFrame)
  • get config options (GetConfig)
  • create IoMessage, encode(decode) to(from) raw bytes, encode(decode) data to(from) base64 string (IoMessage methods)
  • connect to ioFog Control Channel via WebSocket (EstablishControlWsConnection)
  • connect to ioFog Message Channel via WebSocket (EstablishMessageWsConnection) and publish new message via this channel (SendMessageViaSocket)

Code snippets:

Get sdk:

   go get github.com/eclipse-iofog/iofog-sdk-go

Import package:

   import (
   msvcs "github.com/eclipse-iofog/iofog-sdk-go/pkg/microservices"
   )

Create IoFog client with default settings:

	client, err := msvcs.NewDefaultIoFogClient()
	if err != nil {
		println(err.Error())
		return
	} else {
	    // work with client
	}

Or specify host, port, ssl and container id explicitly:

	client, err := msvcs.NewIoFogClient("IoFog", 54321, false, "containerId")
        if err != nil {
		println(err.Error())
		return
	} else {
	    // work with client
	}

REST calls

Get list of next unread IoMessages:

	messages, err := client.GetNextMessages()
	if err != nil {
	    // handle bad request or error
		println(err.Error())
	} else {
	    // messages array contains received
	    // and parsed IoMessages
	    fmt.Printf("%+v", messages)
	}

Post new IoMessage to ioFog via REST call:

	postMessageResponse, err := client.PostMessage(&msvcs.IoMessage{
		SequenceNumber:1,
		SequenceTotal:1,
		InfoType:"text",
		InfoFormat:"utf-8",
		ContentData: []byte("foo"),
		ContextData: []byte("bar"),
	})
	if err != nil {
	    // handle bad request or error
		println(err.Error())
	} else {
	    // postMessageResponse contains sent message
	    // ID and generated Timestamp 
	    fmt.Printf("%+v", postMessageResponse)
	}

Get an array of IoMessages from specified publishers within given timeframe:

	timeFrameMessages, err := client.GetMessagesFromPublishersWithinTimeFrame(&msvcs.MessagesQueryParameters{
		TimeFrameStart: 1234567890123,
		TimeFrameEnd: 1234567892123,
		Publishers: []string{"sefhuiw4984twefsdoiuhsdf", "d895y459rwdsifuhSDFKukuewf", "SESD984wtsdidsiusidsufgsdfkh"},

	})
	if err != nil {
	    // handle bad request or error
		println(err.Error())
	} else {
	    // timeFrameMessages contains fields Messages - an array of IoMessages,
	    // TimeFrameStart and TimeFrameEnd 
        fmt.Printf("%+v", timeFrameMessages)
    }

Get container's config:

	config, err := client.GetConfig()
	if err != nil {
	    // handle bad request or error
		println(err.Error())
	} else {
	    // config is plain old go map with string keys
	    // and interface{} values
	    fmt.Println("Config: ", config)
	}

WebSocket calls

Establish connection with message ws. This call returns two channels, so you can listen to incoming messages and receipts:

		dataChannel, receiptChannel := client.EstablishMessageWsConnection()
		for {
			select {
			case msg := <-dataChannel:
				// msg is IoMessage received
			case r := <-receiptChannel:
				// r is response with ID and Timestamp
		}

After establishing this connection you can send your own message to IoFog:

		client.SendMessageViaSocket(&msvcs.IoMessage{
        	Tag: "aaa",
        	SequenceNumber: 127,
        	ContentData: []byte("Here goes some test data"),
        	ContextData: []byte("This one is test too"),
        })

Establish connection with control ws and pass channel to listen to incoming config update signals:

	confChannel := client.EstablishControlWsConnection()
	for {
		select {
		case <-confChannel:
		    // signal received
		    // we can fetch new config now
			config, err := client.GetConfig()
			if err != nil {
				println(err.Error())
			} else {
			    fmt.Println("Config: ", config)
			}
	}

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
URL_POST_MESSAGE
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author