relay

package
v0.0.0-...-5590911 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventWelcome = "001" // RPL_WELCOME
	EventPrivMsg = "PRIVMSG"
)

Variables

View Source
var Debug bool

Debug specifies debug logging should be enabled

Functions

func RegisterServer

func RegisterServer(initFunc InitFunc)

RegisterServer registers provided initFunc with relay

Types

type IRCServer

type IRCServer struct {
	*ServerBase
	// contains filtered or unexported fields
}

func NewIRCServer

func NewIRCServer(name string, config IRCServerConfig) *IRCServer

NewIRCServer returns a pointer to an initialised IRCServer struct

func (*IRCServer) Connect

func (s *IRCServer) Connect() error

Connect connects to the configured IRC homeserver

func (*IRCServer) Read

func (s *IRCServer) Read(ctx context.Context, readChan chan *TargetMessage) error

Read starts reading from the IRC server rooms

func (*IRCServer) SetTargets

func (s *IRCServer) SetTargets(targets []Target) error

SetTargets sets IRC server targets and joins corresponding IRC rooms

func (*IRCServer) Write

func (s *IRCServer) Write(msg *TargetMessage) error

Write writes TargetMessage msg to target destination

type IRCServerConfig

type IRCServerConfig struct {
	Host          string `mapstructure:"host"`
	UseTLS        bool   `mapstructure:"use_tls"`
	SkipTLSVerify bool   `mapstructure:"skip_tls_verify"`
	Username      string `mapstructure:"username"`
	Password      string `mapstructure:"password"`
	Nick          string `mapstructure:"nick"`
}

IRCServerConfig represents the configuration of an IRC server

type InitFunc

type InitFunc func() []Server

InitFunc represents a function which when called returns a slice of servers

type Manager

type Manager struct {
	Servers  []Server
	Mappings TargetMappings
}

func NewManager

func NewManager(mappings TargetMappings) *Manager

NewManager returns a new instance of Manager, hydrated with provided mappings and servers

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start iterates over all servers and: - Connects each server - Sets targets for each server - Starts reading from each server This will block until all servers have finished reading

type MatrixServer

type MatrixServer struct {
	*ServerBase
	// contains filtered or unexported fields
}

func NewMatrixServer

func NewMatrixServer(name string, config MatrixServerConfig) *MatrixServer

NewMatrixServer returns a pointer to an initialised MatrixServer struct

func (*MatrixServer) Connect

func (s *MatrixServer) Connect() error

Connect connects to the configured Matrix homeserver

func (*MatrixServer) Read

func (s *MatrixServer) Read(ctx context.Context, readChan chan *TargetMessage) error

Read starts reading from the Matrix server rooms

func (*MatrixServer) SetTargets

func (s *MatrixServer) SetTargets(targets []Target) error

SetTargets sets Matrix server targets and joins corresponding IRC rooms

func (*MatrixServer) Write

func (s *MatrixServer) Write(msg *TargetMessage) error

Write writes TargetMessage msg to target destination

type MatrixServerConfig

type MatrixServerConfig struct {
	Homeserver  string `mapstructure:"homeserver"`
	Username    string `mapstructure:"username"`
	Password    string `mapstructure:"password"`
	DisplayName string `mapstructure:"display_name"`
}

MatrixServerConfig represents the configuration of a Matrix server

type MatrixServerLogger

type MatrixServerLogger struct{}

func (*MatrixServerLogger) Debugfln

func (l *MatrixServerLogger) Debugfln(message string, args ...interface{})

type Server

type Server interface {
	Connect() error
	SetTargets(targets []Target) error
	Read(context.Context, chan *TargetMessage) error
	Name() string
	Write(*TargetMessage) error
}

type ServerBase

type ServerBase struct {
	Targets []Target
	// contains filtered or unexported fields
}

ServerBase provides common methods for use with implementations of Server

func NewServerBase

func NewServerBase(name string) *ServerBase

NewServerBase returns a pointer to an initialised ServerBase

func (*ServerBase) GetTarget

func (b *ServerBase) GetTarget(name string) (Target, error)

GetTarget returns a target matching given name or an error if target isn't found

func (*ServerBase) Name

func (b *ServerBase) Name() string

Name returns the name of the server

type Target

type Target struct {
	Server string
	Name   string
}

Target represents a single target

type TargetMapping

type TargetMapping struct {
	To   Target
	From Target
}

TargetMapping represents a one-to-one mapping of targets

type TargetMappings

type TargetMappings []TargetMapping

TargetMappings represents a slice of TargetMapping structs

func (*TargetMappings) WhereDestinationServer

func (t *TargetMappings) WhereDestinationServer(server string) []TargetMapping

WhereDestinationServer returns a slice of TargetMappings which reference specified server as a destination within configured target mappings

func (*TargetMappings) WhereMessageSource

func (t *TargetMappings) WhereMessageSource(msg *TargetMessage) []TargetMapping

WhereMessageSource returns a slice of TargetMappings which reference source in specified message msg

func (*TargetMappings) WhereSourceServer

func (t *TargetMappings) WhereSourceServer(server string) []TargetMapping

WhereSourceServer returns a slice of TargetMappings which reference specified server as a source within configured target mappings

type TargetMessage

type TargetMessage struct {
	Source      Target
	Destination Target
	Payload     TargetMessagePayload
}

TargetMessage represents a message between Source and Destination

func NewTargetMessage

func NewTargetMessage(source Target, destination Target, payload TargetMessagePayload) *TargetMessage

NewTargetMessage returns a pointer to an intialised TargetMessage

func (*TargetMessage) GetMessage

func (m *TargetMessage) GetMessage() string

GetMessage returns a formatted string representation of TargetMessage

type TargetMessagePayload

type TargetMessagePayload struct {
	User string
	Msg  string
}

TargetMessagePayload represents the payload of a TargetMessage

Jump to

Keyboard shortcuts

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