quasar

package module
v0.0.0-...-fb73fb0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

README

Quasar

Currently being developed. It's usable in it's current state but should be considered highly unstable.

Library for implementing Tenyks services in Go

Install

go get github.com/kyleterry/quasar

Usage

Better instructions coming later when it's more stable, but you can look at the example.

Documentation

Index

Constants

View Source
const (
	// DefaultSend is the default tcp address for sending data to the server.
	DefaultSend = "tcp://localhost:61124"
	// DefaultRecv is the default tcp address for recieving data from the server.
	DefaultRecv = "tcp://localhost:61123"
)

Variables

View Source
var NoopHandler = MsgHandler{MatchHandler: HandlerFunc(func(r Result, m Message, c Communication) {})}

Functions

This section is empty.

Types

type Communication

type Communication struct {
	// contains filtered or unexported fields
}

func (*Communication) Send

func (c *Communication) Send(line string, message Message)

type Config

type Config struct {
	Name    string        `json:"name"`
	Version string        `json:"version"`
	UUID    string        `json:"uuid"`
	Service ServiceConfig `json:"service"`
}

Config holds configuration values passed into quasar on bootstrap. Recommended way to use this object is to unmarshal some JSON into an instance. You can also build this by hand using flags.

func NewConfigFromJSONFile

func NewConfigFromJSONFile(path string) (*Config, error)

NewConfigFromJSONFile takes a file path to a JSON file and unmarshals it into a new Config instance.

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(conf *Config) (*Connection, error)

type Handler

type Handler interface {
	HandleMatch(Result, Message, Communication)
}

Handler is an interface that has a Handle method that takes a Result and Message as arguments. What you do with these is up to you. This is a function that will be triggered if it's matcher returns a valid match.

func PrivmsgMiddlware

func PrivmsgMiddlware(handler Handler) Handler

type HandlerFunc

type HandlerFunc func(Result, Message, Communication)

func (HandlerFunc) HandleMatch

func (fn HandlerFunc) HandleMatch(r Result, m Message, c Communication)

type Matcher

type Matcher interface {
	Match(Message) Result
}

Matcher is an interface that has a match method that receives a Message and tries to match it against a set of rules. If no match is found, then you should return nil.

type MatcherFunc

type MatcherFunc func(Message) Result

MatcherFunc registers the wrapped function as a Matcher.

func (MatcherFunc) Match

func (fn MatcherFunc) Match(msg Message) Result

type Message

type Message struct {
	Target      string
	Command     string
	Mask        string
	Direct      bool
	Nick        string
	Host        string
	FullMessage string
	User        string
	FromChannel bool
	Connection  string
	Payload     string
	Meta        Meta
}

type Meta

type Meta struct {
	Name    string
	Version string
}

type MsgHandler

type MsgHandler struct {
	MatcherFunc  Matcher
	DirectOnly   bool
	PrivateOnly  bool
	MatchHandler Handler
	HelpText     string
}

type RegexMatcher

type RegexMatcher struct {
	// contains filtered or unexported fields
}

RegexMatcher satisfies the Matcher interface and will match messages against a provided list of regular expressions.

func NewRegexMatcher

func NewRegexMatcher(expressions ...string) RegexMatcher

NewRegexMatcher will return a new RegexMatcher setup with expressions

func (RegexMatcher) Match

func (r RegexMatcher) Match(msg Message) Result

type Result

type Result map[string]string

type Service

type Service struct {
	Name        string
	UUID        string
	Description string
	HelpText    string
	Config      *Config
	// contains filtered or unexported fields
}

Service is the state of the service. It holds the handlers and matchers and helps relay messages to the right handler when they come in from the Tenyks server.

func New

func New(config *Config) *Service

func (*Service) Cleanup

func (s *Service) Cleanup()

Cleanup will close open connections and clean up anything that shouldn't linger after shutdown.

func (*Service) DefaultHandle

func (s *Service) DefaultHandle(handler MsgHandler)

func (*Service) Handle

func (s *Service) Handle(handler MsgHandler)

func (*Service) Run

func (s *Service) Run() error

Run runs forever or until a signal stops the program. This function blocks.

type ServiceConfig

type ServiceConfig struct {
	// SendAddr is the host and port in a TCP URL format: tcp://localhost:61124.
	// If the SendAddr string is blank, the default tenyks port is used.
	SendAddr string `json:"send_addr"`
	// RecvAddr is the host and port in a TCP URL format: tcp://localhost:61124.
	// If the RecvAddr string is blank, the default tenyks port is used.
	RecvAddr string `json:"recv_addr"`
}

ServiceConfig holds the addresses for pubsub actions

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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