catbird

package module
v0.0.0-...-58c4a32 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 10 Imported by: 2

README

Go Reference

CatBird

A simple and robust Go websocket connection hub.

hub, _ := catbird.New(catbird.Config{Secret: secret})
defer hub.Stop()

// ...

mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
    hub.HandleWebsocket(w, r, r.Context().Value("user").(string), []string{"clock"})
})

// ...

ticker := time.NewTicker(time.Second)
defer ticker.Stop()

go func() {
    for {
        select {
        case t := <-ticker.C:
            hub.SendString("clock", fmt.Println("Current time", t))
        }
    }
}()

http.ListenAndServe("localhost:3000", mux)

Install

go get -u github.com/ugent-library/catbird

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bridge

type Bridge interface {
	Send(string, string, []byte) error
	Receive(string, func(string, []byte)) error
	SendHeartbeat(string, string, []string) error
	ReceiveHeartbeat(string, func(string, []string)) error
}

type Config

type Config struct {
	ErrorHandler  func(error)
	MessageBuffer int
	WriteTimeout  time.Duration
	Bridge        Bridge
}

type Hub

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

func New

func New(c Config) (*Hub, error)

func (*Hub) HandleWebsocket

func (h *Hub) HandleWebsocket(w http.ResponseWriter, r *http.Request, userID string, topics []string) error

func (*Hub) Presence

func (h *Hub) Presence(topic string) []string

func (*Hub) Send

func (h *Hub) Send(topic string, msg []byte)

func (*Hub) SendString

func (h *Hub) SendString(topic string, msg string)

func (*Hub) Stop

func (h *Hub) Stop()

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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