messages

package
v0.0.0-...-4d778f5 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler runs message server and holds connection to known peers.

func NewHandler

func NewHandler(
	r *rand.Rand,
	log *logger.Logger,
	self *peers.Peer,
) *Handler

NewHandler returns new messages handler.

func (*Handler) Received

func (h *Handler) Received() <-chan *Message

Received returns a channel with new messages.

func (*Handler) SendText

func (h *Handler) SendText(ctx context.Context, text string, toID string) error

SendText sends a text message.

func (*Handler) Sent

func (h *Handler) Sent() <-chan *Message

Sent returns a channel with sent messages.

func (*Handler) Start

func (h *Handler) Start(ctx context.Context) error

Start starts the server.

type Message

type Message struct {
	ID        string      `json:"id"`
	From      *peers.Peer `json:"from"`
	To        *peers.Peer `json:"to"`
	Timestamp time.Time   `json:"timestamp"`
	Type      Type        `json:"type"`
	Text      string      `json:"text"`
}

Message is a single message.

type Type

type Type string

Type is a message type.

var (
	TypeInvalid Type
	TypeText    Type = "text"
)

Known types.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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