sarif

package
v0.0.0-...-0dfd57a Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sarif implements the sarif protocol, including client and broker.

Package sarif implements the sarif protocol, including client and broker.

Index

Constants

View Source
const VERSION = "0.5"

Variables

This section is empty.

Functions

func GenerateId

func GenerateId() string

Types

type Client

type Client interface {
	DeviceId() string
	Connect(conn Connection) error
	Disconnect() error

	Publish(msg Message) error
	Subscribe(action, device string, h func(Message)) error

	SetRequestTimeout(timeout time.Duration)
	Request(msg Message) <-chan Message
	Reply(orig, reply Message) error
	ReplyBadRequest(orig Message, err error) error
	ReplyInternalError(orig Message, err error) error

	Discover(action string) <-chan Message
	Log(typ, text string, args ...interface{}) error
}

func NewClient

func NewClient(ci ClientInfo) Client

type ClientFactory

type ClientFactory interface {
	NewClient(ci ClientInfo) (Client, error)
}

type ClientInfo

type ClientInfo struct {
	Name         string    `json:"name,omitempty"`
	Auth         string    `json:"auth,omitempty"`
	Capabilities []string  `json:"capabilities,omitempty"`
	LastSeen     time.Time `json:"last_seen,omitempty"`
}

type Connection

type Connection interface {
	Publish(msg Message) error
	Subscribe(src, action, device string) error
	Consume() (<-chan Message, error)
	Close() error
}

type Message

type Message struct {
	Version     string  `json:"sarif,omitempty"`
	Id          string  `json:"id,omitempty"`
	Action      string  `json:"action,omitempty"`
	Source      string  `json:"src,omitempty"`
	Destination string  `json:"dst,omitempty"`
	Payload     Partial `json:"p,omitempty"`
	CorrId      string  `json:"corr,omitempty"`
	Text        string  `json:"text,omitempty"`
}

func BadRequest

func BadRequest(reason error) Message

func ConvertURL

func ConvertURL(u string) (Message, error)

func CreateMessage

func CreateMessage(action string, payload interface{}) Message

func InternalError

func InternalError(reason error) Message

func (Message) ActionSuffix

func (m Message) ActionSuffix(action string) string

func (Message) DecodePayload

func (m Message) DecodePayload(v interface{}) error

func (*Message) EncodePayload

func (m *Message) EncodePayload(v interface{}) error

func (Message) IsAction

func (m Message) IsAction(action string) bool

func (Message) IsValid

func (m Message) IsValid() error

func (Message) Reply

func (orig Message) Reply(m Message) Message

type Partial

type Partial struct {
	Raw []byte
}

func (*Partial) Decode

func (p *Partial) Decode(v interface{}) error

func (*Partial) Encode

func (p *Partial) Encode(v interface{}) (err error)

func (*Partial) Map

func (p *Partial) Map() (m map[string]interface{}, err error)

func (Partial) MarshalJSON

func (p Partial) MarshalJSON() ([]byte, error)

func (*Partial) MustDecode

func (p *Partial) MustDecode(v interface{})

func (Partial) String

func (p Partial) String() string

func (*Partial) UnmarshalJSON

func (p *Partial) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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