dipper

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2020 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package dipper is a library used for developing drivers for Honeydipper.

Index

Constants

View Source
const (
	ChannelEventbus = "eventbus"
	ChannelState    = "state"
	ChannelRPC      = "rpc"
	EventbusMessage = "message"
	EventbusCommand = "command"
	EventbusReturn  = "return"
)

channel names and subject names

View Source
const (
	SUCCESS = "success"
	FAILURE = "failure"
	ERROR   = "error"
)
View Source
const MaxID = 13684

MaxID : the maximum rpcID

Variables

View Source
var CommLocks = map[io.Writer]*sync.Mutex{}

CommLocks : comm channels are protected with locks

View Source
var FuncMap = template.FuncMap{
	"fromPath": MustGetMapData,
	"now":      time.Now,
	"duration": time.ParseDuration,
	"ISO8601":  func(t time.Time) string { return t.Format(time.RFC3339) },
	"toYaml": func(v interface{}) string {
		s, err := yaml.Marshal(v)
		if err != nil {
			panic(err)
		}
		return string(s)
	},
}

FuncMap : used to add functions to the go templates

View Source
var IDMapMetadata = map[IDMap]*IDMapMeta{}

IDMapMetadata : actual metadata for all IDMap objects

View Source
var Logger *logging.Logger

Logger provides methods to log to the configured logger backend.

View Source
var MasterCommLock = sync.Mutex{}

MasterCommLock : the lock used to protect the comm locks

Functions

func CatchError

func CatchError(err interface{}, handler func())

CatchError : use this in defer to catch a certain error

func CombineMap added in v1.0.0

func CombineMap(dst map[string]interface{}, src interface{}) map[string]interface{}

CombineMap : combine the data form two maps without merging them

func Compare

func Compare(actual string, criteria interface{}) bool

Compare : compare an actual value to a criteria

func CompareAll

func CompareAll(actual interface{}, criteria interface{}) bool

CompareAll : compare all conditions against an event data structure

func CompareMap added in v1.0.0

func CompareMap(actual interface{}, criteria interface{}) bool

CompareMap : compare a map to a map

func DecryptAll added in v1.0.1

func DecryptAll(rpc *RPCCaller, from interface{})

DecryptAll find and decrypt all eyaml style encrypted data in the given data structure

func DeepCopy

func DeepCopy(m interface{}) (interface{}, error)

DeepCopy : performs a deep copy of the map or slice.

func DeepCopyMap added in v1.0.0

func DeepCopyMap(m map[string]interface{}) (map[string]interface{}, error)

DeepCopyMap : performs a deep copy of the given map m.

func DeserializeContent

func DeserializeContent(content []byte) (ret interface{})

DeserializeContent : decode the content into interface

func GetIP

func GetIP() string

GetIP : get first non loopback IP address

func GetLogger

func GetLogger(module string, verbosity string, logFiles ...*os.File) *logging.Logger

GetLogger : getting a logger for the module

func GetMapData

func GetMapData(from interface{}, path string) (ret interface{}, ok bool)

GetMapData : get the data from the deep map following a KV path

func GetMapDataBool

func GetMapDataBool(from interface{}, path string) (ret bool, ok bool)

GetMapDataBool : get the data as bool from the deep map following a KV path

func GetMapDataStr

func GetMapDataStr(from interface{}, path string) (ret string, ok bool)

GetMapDataStr : get the data as string from the deep map following a KV path

func IDMapDel

func IDMapDel(m IDMap, key string)

IDMapDel : deleting a value from ID map

func IDMapGet added in v0.1.10

func IDMapGet(m IDMap, key string) interface{}

IDMapGet : getting a value from ID map

func IDMapPut

func IDMapPut(m IDMap, val interface{}) string

IDMapPut : putting an value in map return a unique ID

func IgnoreError

func IgnoreError(expectedError interface{})

IgnoreError : use this function in defer statement to ignore a particular error

func InitIDMap

func InitIDMap(m IDMap)

InitIDMap : create a new IDMap Object

func Interpolate

func Interpolate(source interface{}, data interface{}) interface{}

Interpolate : go through the map data structure to find and parse all the templates

func InterpolateGoTemplate added in v1.0.0

func InterpolateGoTemplate(pattern string, data interface{}) string

InterpolateGoTemplate : parse the string as go template

func InterpolateStr

func InterpolateStr(pattern string, data interface{}) string

InterpolateStr : interpolate a string and return a string

func LockCheckDeleteMap

func LockCheckDeleteMap(lock *sync.Mutex, resource interface{}, key interface{}, checkValue interface{}) (ret interface{})

LockCheckDeleteMap : acquire a lock and delete the entry from the map and return the previous value if available

func LockComm

func LockComm(out io.Writer)

LockComm : Lock the comm channel

func LockGetMap

func LockGetMap(lock *sync.Mutex, resource interface{}, key interface{}) (ret interface{}, ok bool)

LockGetMap : acquire a lock and look up a key in the map then return the result

func LockSetMap

func LockSetMap(lock *sync.Mutex, resource interface{}, key interface{}, val interface{}) (ret interface{})

LockSetMap : acquire a lock and set the value in the map by index and return the previous value if available

func MergeMap added in v1.0.0

func MergeMap(dst map[string]interface{}, src interface{}) map[string]interface{}

MergeMap : merge the data from source to destination with some overriding rule

func Must added in v1.7.0

func Must(ret interface{}, err error) interface{}

Must is used to catch function return with error

func MustDeepCopy added in v1.0.0

func MustDeepCopy(m interface{}) interface{}

MustDeepCopy : performs a deep copy of the given map or slice, panic if run into errors

func MustDeepCopyMap added in v1.0.0

func MustDeepCopyMap(m map[string]interface{}) map[string]interface{}

MustDeepCopyMap : performs a deep copy of the given map m, panic if run into errors

func MustGetMapData

func MustGetMapData(from interface{}, path string) interface{}

MustGetMapData : get the data from the deep map following a KV path, may raise errors

func MustGetMapDataBool

func MustGetMapDataBool(from interface{}, path string) bool

MustGetMapDataBool : get the data as bool from the deep map following a KV path or panic

func MustGetMapDataStr

func MustGetMapDataStr(from interface{}, path string) string

MustGetMapDataStr : get the data as string from the deep map following a KV path, may raise errors

func PanicError

func PanicError(args ...interface{})

PanicError accepts multiple variables and will panic if the last variable is not nil. It is used to wrap around functions that return error as the last return value.

dipper.PanicError(io.ReadFull(&b, lval))

The io.ReadFull return length read and an error. If error is returned, the function will panic.

func ParseYaml

func ParseYaml(pattern string) interface{}

ParseYaml : load the data in the string as yaml

func RandString

func RandString(n int) string

RandString : generating a random string of n bytes

func Recursive

func Recursive(from interface{}, process func(key string, val interface{}) (newval interface{}, ok bool))

Recursive : enumerate all the data element deep into the map call the function provided

func RecursiveWithPrefix

func RecursiveWithPrefix(
	parent interface{},
	prefixes string,
	key interface{},
	from interface{},
	process func(key string, val interface{}) (newval interface{}, ok bool),
)

RecursiveWithPrefix : enumerate all the data element deep into the map call the function provided

func RegexParser

func RegexParser(key string, val interface{}) (ret interface{}, replace bool)

RegexParser : used with Recursive to process the data in the conditions so they can be used for matching

func RemoveComm

func RemoveComm(out io.Writer)

RemoveComm : remove the lock when the comm channel is closed

func SafeExitOnError

func SafeExitOnError(args ...interface{})

SafeExitOnError : use this function in defer statement to ignore errors

func SendMessage

func SendMessage(out io.Writer, msg *Message)

SendMessage : send a message to the io.Writer, may change the message to raw

func SerializeContent

func SerializeContent(content interface{}) (ret []byte)

SerializeContent : encode payload content into bytes

func UnlockComm

func UnlockComm(out io.Writer)

UnlockComm : unlock the comm channel

Types

type CommandProvider

type CommandProvider struct {
	Commands     map[string]MessageHandler
	ReturnWriter io.Writer
	Channel      string
	Subject      string
}

CommandProvider : an interface for providing Command handling feature

func (*CommandProvider) Init

func (p *CommandProvider) Init(channel string, subject string, defaultWriter io.Writer)

Init : initializing rpc provider

func (*CommandProvider) Return

func (p *CommandProvider) Return(call *Message, retval *Message)

Return : return a value to rpc caller

func (*CommandProvider) ReturnError

func (p *CommandProvider) ReturnError(call *Message, pattern string, args ...interface{}) error

ReturnError: send an error message return to caller and create an error

func (*CommandProvider) Router

func (p *CommandProvider) Router(msg *Message)

Router : route the message to rpc handlers

func (*CommandProvider) UnpackLabels added in v1.3.0

func (p *CommandProvider) UnpackLabels(msg *Message) (retry int, timeout, backoff_ms time.Duration)

UnpackLabels loads necessary variables out of the labels

type Driver

type Driver struct {
	RPCCaller
	RPCProvider
	CommandProvider
	Name            string
	Service         string
	State           string
	In              io.Reader
	Out             io.Writer
	Options         interface{}
	MessageHandlers map[string]MessageHandler
	Start           MessageHandler
	Stop            MessageHandler
	Reload          MessageHandler
	ReadySignal     chan bool
	APITimeout      time.Duration
}

Driver : the helper stuct for creating a honey-dipper driver in golang

func NewDriver

func NewDriver(service string, name string) *Driver

NewDriver : create a blank driver object

func (*Driver) GetLogger

func (d *Driver) GetLogger() *logging.Logger

GetLogger : getting a logger for the driver

func (*Driver) GetName added in v1.0.1

func (d *Driver) GetName() string

GetName returns the name of the driver

func (*Driver) GetOption

func (d *Driver) GetOption(path string) (interface{}, bool)

GetOption : get the data from options map with the key

func (*Driver) GetOptionStr

func (d *Driver) GetOptionStr(path string) (string, bool)

GetOptionStr : get the string data from options map with the key

func (*Driver) GetStream added in v1.0.1

func (d *Driver) GetStream(feature string) io.Writer

GetStream getting a output stream for a feature

func (*Driver) Ping

func (d *Driver) Ping(msg *Message)

Ping : respond to daemon ping request with driver state

func (*Driver) ReceiveOptions

func (d *Driver) ReceiveOptions(msg *Message)

ReceiveOptions : receive options from daemon

func (*Driver) Run

func (d *Driver) Run()

Run : start a loop to communicate with daemon

func (*Driver) SendMessage

func (d *Driver) SendMessage(m *Message)

SendMessage : send a prepared message to daemon

type IDMap

type IDMap interface{}

IDMap : a map that store values with automatically generated keys

type IDMapMeta

type IDMapMeta struct {
	Counter int
	Lock    sync.Mutex
}

IDMapMeta : meta info structure for a IDMap object

type Message

type Message struct {
	// on the wire
	Channel string
	Subject string
	Size    int
	Labels  map[string]string
	Payload interface{}

	// runtime meta info in memory
	IsRaw    bool
	Reply    chan Message
	ReturnTo io.Writer
}

Message : the message passed between components of the system

func DeserializePayload

func DeserializePayload(msg *Message) *Message

DeserializePayload : decode a message payload from bytes

func FetchMessage

func FetchMessage(in io.Reader) (msg *Message)

FetchMessage : fetch message from input from daemon service

may block or throw io.EOF based on the fcntl setting

func FetchRawMessage

func FetchRawMessage(in io.Reader) (msg *Message)

FetchRawMessage : fetch encoded message from input from daemon service

may block or throw io.EOF based on the fcntl setting

func MessageCopy

func MessageCopy(m *Message) (*Message, error)

MessageCopy : performs a deep copy of the given map m.

func SerializePayload

func SerializePayload(msg *Message) *Message

SerializePayload : encode a message payload return the modified message

type MessageHandler

type MessageHandler func(*Message)

MessageHandler : a type of functions that take a pointer to a message and handle it

type RPCCaller

type RPCCaller struct {
	Parent  RPCCallerStub
	Channel string
	Subject string
	Result  map[string]chan interface{}
	Lock    sync.Mutex
	Counter int
}

RPCCaller : an object that makes RPC calls

func (*RPCCaller) Call

func (c *RPCCaller) Call(feature string, method string, params interface{}) ([]byte, error)

Call : making a RPC call to another driver with structured data

func (*RPCCaller) CallNoWait

func (c *RPCCaller) CallNoWait(feature string, method string, params interface{}) error

CallNoWait : making a RPC call to another driver with structured data not expecting any return

func (*RPCCaller) CallRaw

func (c *RPCCaller) CallRaw(feature string, method string, params []byte) ([]byte, error)

CallRaw : making a RPC call to another driver with raw data

func (*RPCCaller) CallRawNoWait

func (c *RPCCaller) CallRawNoWait(feature string, method string, params []byte, rpcID string) (ret error)

CallRawNoWait : making a RPC call to another driver with raw data not expecting return

func (*RPCCaller) HandleReturn

func (c *RPCCaller) HandleReturn(m *Message)

HandleReturn : receiving return of a RPC call

func (*RPCCaller) Init

func (c *RPCCaller) Init(parent RPCCallerStub, channel string, subject string)

Init : initializing rpc caller

type RPCCallerStub added in v1.0.1

type RPCCallerStub interface {
	GetName() string
	GetStream(feature string) io.Writer
}

RPCCallerStub is an interface which every RPC caller should implement

type RPCHandler

type RPCHandler func(string, string, []byte)

RPCHandler : a type of functions that handle RPC calls between drivers

type RPCProvider

type RPCProvider struct {
	RPCHandlers   map[string]MessageHandler
	DefaultReturn io.Writer
	Channel       string
	Subject       string
}

RPCProvider : an interface for providing RPC handling feature

func (*RPCProvider) Init

func (p *RPCProvider) Init(channel string, subject string, defaultWriter io.Writer)

Init : initializing rpc provider

func (*RPCProvider) Return

func (p *RPCProvider) Return(call *Message, retval *Message)

Return : return a value to rpc caller

func (*RPCProvider) ReturnError

func (p *RPCProvider) ReturnError(call *Message, reason string)

ReturnError : return error to rpc caller

func (*RPCProvider) Router

func (p *RPCProvider) Router(msg *Message)

Router : route the message to rpc handlers

Directories

Path Synopsis
Package mock_dipper is a generated GoMock package.
Package mock_dipper is a generated GoMock package.

Jump to

Keyboard shortcuts

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