Skip to content

is8ac/self-go-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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,
))

About

Golang library to interact with self via the WS APIs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages