irc

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

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

Go to latest
Published: Jan 10, 2023 License: MIT Imports: 8 Imported by: 1

README

irc

GoDoc Reference Go Report Card Build Status Coverage Status

irc is a fast IRC library in Go. It's inspired by other Go IRC libraries, but with performance improvements.

Benchmarks

benchmark                                              iter       time/iter   bytes alloc         allocs
---------                                              ----       ---------   -----------         ------
BenchmarkParseSimple/jakebailey/irc-4              20000000    102.00 ns/op       16 B/op    1 allocs/op
BenchmarkParseSimple/jakebailey/ircold-4           10000000    213.00 ns/op      144 B/op    3 allocs/op
BenchmarkParseSimple/fluffle/goirc/client-4         5000000    363.00 ns/op      288 B/op    4 allocs/op
BenchmarkParseSimple/sorcix/irc-4                  10000000    211.00 ns/op      144 B/op    3 allocs/op
BenchmarkParseSimple/thoj/go-ircevent-4             5000000    341.00 ns/op      256 B/op    4 allocs/op
BenchmarkParseSimple/goshuirc/irc-go/ircmsg-4      10000000    168.00 ns/op       48 B/op    2 allocs/op
BenchmarkParseSimple/gempir/go-twitch-irc-4        10000000    193.00 ns/op      448 B/op    3 allocs/op

BenchmarkParseTwitch/jakebailey/irc-4               1000000   1268.00 ns/op     1218 B/op    3 allocs/op
BenchmarkParseTwitch/jakebailey/ircold-4             300000   5765.00 ns/op     4015 B/op   64 allocs/op
BenchmarkParseTwitch/fluffle/goirc/client-4          300000   5843.00 ns/op     4159 B/op   65 allocs/op
BenchmarkParseTwitch/sorcix/irc-4                    300000   5633.00 ns/op     4015 B/op   64 allocs/op
BenchmarkParseTwitch/thoj/go-ircevent-4              300000   4551.00 ns/op     3071 B/op   23 allocs/op
BenchmarkParseTwitch/goshuirc/irc-go/ircmsg-4       1000000   2236.00 ns/op     2191 B/op    6 allocs/op
BenchmarkParseTwitch/gempir/go-twitch-irc-4          300000   5691.00 ns/op     3879 B/op   35 allocs/op

BenchmarkParseEscaping/jakebailey/irc-4              500000   2538.00 ns/op     1552 B/op    9 allocs/op
BenchmarkParseEscaping/jakebailey/ircold-4           200000   7812.00 ns/op     4878 B/op   84 allocs/op
BenchmarkParseEscaping/fluffle/goirc/client-4        200000   7966.00 ns/op     4958 B/op   84 allocs/op
BenchmarkParseEscaping/sorcix/irc-4                  200000   7842.00 ns/op     4878 B/op   84 allocs/op
BenchmarkParseEscaping/thoj/go-ircevent-4            200000   6373.00 ns/op     3549 B/op   31 allocs/op
BenchmarkParseEscaping/goshuirc/irc-go/ircmsg-4      500000   3108.00 ns/op     2462 B/op    9 allocs/op
BenchmarkParseEscaping/gempir/go-twitch-irc-4        300000   5388.00 ns/op     3678 B/op   30 allocs/op

BenchmarkEncodeSimple/jakebailey/irc-4             10000000    117.00 ns/op       48 B/op    1 allocs/op
BenchmarkEncodeSimple/jakebailey/irc_WriteTo-4     20000000    101.00 ns/op        0 B/op    0 allocs/op
BenchmarkEncodeSimple/jakebailey/ircold-4          20000000    101.00 ns/op       64 B/op    1 allocs/op
BenchmarkEncodeSimple/sorcix/irc-4                 20000000    102.00 ns/op       64 B/op    1 allocs/op
BenchmarkEncodeSimple/goshuirc/irc-go/ircmsg-4     20000000    105.00 ns/op       64 B/op    1 allocs/op

BenchmarkEncodeTwitch/jakebailey/irc-4              2000000    863.00 ns/op      352 B/op    1 allocs/op
BenchmarkEncodeTwitch/jakebailey/irc_WriteTo-4      2000000    782.00 ns/op        0 B/op    0 allocs/op
BenchmarkEncodeTwitch/jakebailey/ircold-4           1000000   1158.00 ns/op     1221 B/op    4 allocs/op
BenchmarkEncodeTwitch/sorcix/irc-4                  1000000   1139.00 ns/op     1057 B/op    3 allocs/op
BenchmarkEncodeTwitch/goshuirc/irc-go/ircmsg-4      1000000   1497.00 ns/op     1161 B/op    4 allocs/op

BenchmarkEncodeEscaping/jakebailey/irc-4            1000000   1421.00 ns/op      480 B/op    1 allocs/op
BenchmarkEncodeEscaping/jakebailey/irc_WriteTo-4    1000000   1304.00 ns/op        0 B/op    0 allocs/op
BenchmarkEncodeEscaping/jakebailey/ircold-4         1000000   1336.00 ns/op     1381 B/op    4 allocs/op
BenchmarkEncodeEscaping/sorcix/irc-4                1000000   1342.00 ns/op     1290 B/op    4 allocs/op
BenchmarkEncodeEscaping/goshuirc/irc-go/ircmsg-4    1000000   2170.00 ns/op     1677 B/op    8 allocs/op

See http://github.com/jakebailey/irc-benchmarks for more info.

Documentation

Overview

Package irc provides fast IRC support.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyMessage is returned when the parser encounters an empty message.
	ErrEmptyMessage = &ParseError{"empty message"}

	// ErrInvalidMessage is returned when the parser encounters an invalid message.
	// This error is likely to be replaced with a more helpful error (encoding something
	// like where the error occurred).
	ErrInvalidMessage = &ParseError{"invalid message"}
)
View Source
var ErrCTCPEmptyCommand = errors.New("empty ctcp command")

ErrCTCPEmptyCommand is returned by EncodeCTCP when the command is empty.

Functions

func EncodeCTCP

func EncodeCTCP(command, args string) (string, error)

EncodeCTCP encodes a command and its arguments into a string.

func ParseCTCP

func ParseCTCP(s string) (command, args string, ok bool)

ParseCTCP parses the commands and args out of a CTCP string.

Types

type BaseConn

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

BaseConn is a simple IRC connection.

func BaseDial

func BaseDial(addr string) (*BaseConn, error)

BaseDial is shorthand for calling net.Dial("tcp", addr) and calling NewBaseConn on the returned net.Conn.

func NewBaseConn

func NewBaseConn(conn net.Conn) *BaseConn

NewBaseConn creates a new BaseConn from a net.Conn.

func (*BaseConn) Close

func (b *BaseConn) Close() error

Close closes the underlying connection.

func (*BaseConn) Decode

func (b *BaseConn) Decode(m *Message) error

Decode decodes a message into the argument, which cannot be nil.

func (*BaseConn) Encode

func (b *BaseConn) Encode(m *Message) error

Encode encodes a message over the connection.

type Conn

type Conn interface {
	Encoder
	Decoder
	Close() error
}

Conn is both an Encoder and Decoder, but also includes a Close function.

type Decoder

type Decoder interface {
	Decode(*Message) error
}

Decoder decodes a message into the provided Message struct. Decode must set every field of the message struct.

type Encoder

type Encoder interface {
	Encode(*Message) error
}

Encoder takes a message and encodes it, sending it to wherever the encoder chooses.

type Message

type Message struct {
	Tags           map[string]string
	Prefix         Prefix
	Command        string
	Params         []string
	Trailing       string
	ForcedTags     bool
	ForcedTrailing bool

	// Raw contains the raw unparsed message. This is not used for encoding,
	// and is included for users which want the exact original message.
	// Including this incurs no extra overhead, since the other parts of the
	// message are references to parts of this string, meaning that the
	// lifetime of this string is just as long as the message as a whole.
	Raw string
}

Message is an IRC message.

func ParseMessage

func ParseMessage(raw string) (*Message, error)

ParseMessage parses a string and returns a new Message. A string is used as the input, as it was found that they're more performant than using a byte slice, even with an extra initial copy.

ParseMessage does not check the input for newlines, which are normally invalid.

func (*Message) Bytes

func (m *Message) Bytes() []byte

Bytes returns the message encoded as a byte slice. This slice is safe for reuse.

func (*Message) Len

func (m *Message) Len() int

Len returns the length of the encoded message. This message does not actually encode the message, instead simulating encoding and only calculates the length.

func (*Message) MarshalText

func (m *Message) MarshalText() (text []byte, err error)

MarshalText implements TextMarshaler for Message.

func (*Message) Parse

func (m *Message) Parse(raw string) error

Parse parses a string into a message. All fields of the message struct will be set (default as needed), so there is no need to zero before parsing.

Parse does not check the input for newlines, which are normally invalid.

func (*Message) String

func (m *Message) String() string

func (*Message) UnmarshalText

func (m *Message) UnmarshalText(text []byte) error

UnmarshalText implements TextUnmarshaler for Message.

func (*Message) WriteToWithNewline

func (m *Message) WriteToWithNewline(w io.Writer) (n int64, err error)

WriteToWithNewline writes the message to a writer with a terminating `\r\n`.

type ParseError

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

ParseError is returned when parsing a message. It's useful for distinguishing parse errors from network errors when using Conn.Encode.

func (ParseError) Error

func (p ParseError) Error() string

type Prefix

type Prefix struct {
	Name string
	User string
	Host string
}

Prefix is an IRC prefix.

Directories

Path Synopsis
Package irchandle implements net/http-like handler support.
Package irchandle implements net/http-like handler support.

Jump to

Keyboard shortcuts

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