self-go-sdk

module
v0.0.0-...-ee4a2e9 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2017 License: Apache-2.0

README

self-go-sdk

Golang library to interact with self via the WS APIs

GoDoc

Usage

import (
  "github.com/open-horizon/self-go-sdk"
)

Initialize a connection to a self instance.

conn, err := self.Init("localhost")

Subscribe to a list of target.

conn.Sub([]self.Target{self.TargetBlackboardStream, self.TargetAgentSociety})

Register an event hander. Give it some unique name so you can unregister it latter.

handleFunc := func(thing self.Thing){
  // do something with the thing
}
conn.Reg("handle func 1", handleFunc)

Once you are done, unregister it.

conn.Unreg("handle func 1")

handleFunc will be called for all things received. This is often undesirable.

MakeFilteredHandler() constructs a ThingHandlerFunc which only calls the main handle func if filter func returns true.

filterFunc := func(thing self.Thing) bool {
  if thing is desirable {
    return true
  }
  return false
}

handleFunc := func(thing self.Thing){
  // do something with the thing
}
conn.Reg("handle func 1", self.MakeFilteredHandler(filterFunc, handleFunc)))

We can combine ThingFilters. Say that we want to print the text of the things whose types are anything but certain types.

conn.Reg("misc_types", self.MakeFilteredHandler(
  self.Not(
    self.Or(
      []self.ThingFilter{
        self.MakeThingTypeFilter("Health"),
        self.MakeThingTypeFilter("IThing"),
        self.MakeThingTypeFilter("Proxy"),
        self.MakeThingTypeFilter("Failure"),
        self.MakeThingTypeFilter("RequestIntent"),
      },
    ),
  ),
  self.PrintThingText,
))

Directories

Path Synopsis
Package self lets you connect to a self instance via the WS API.
Package self lets you connect to a self instance via the WS API.

Jump to

Keyboard shortcuts

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