server

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxMessageSize = 1024
	MaxMessages    = 1024
	StreamTTL      = time.Duration(1024) * time.Second
)

Variables

View Source
var Default = New()

Functions

func GetCommandsHandler added in v0.12.0

func GetCommandsHandler(w http.ResponseWriter, r *http.Request)

func GetEvents added in v0.11.0

func GetEvents(w http.ResponseWriter, r *http.Request)

func GetHandler added in v0.11.0

func GetHandler(w http.ResponseWriter, r *http.Request)

func GetStreamsHandler added in v0.11.0

func GetStreamsHandler(w http.ResponseWriter, r *http.Request)

func IsWebSocket added in v0.10.0

func IsWebSocket(r *http.Request) bool

check if the request is for websockets

func NewStreamHandler added in v0.11.0

func NewStreamHandler(w http.ResponseWriter, r *http.Request)

func PostCommandHandler added in v0.12.0

func PostCommandHandler(w http.ResponseWriter, r *http.Request)

func PostHandler added in v0.11.0

func PostHandler(w http.ResponseWriter, r *http.Request)

func Random

func Random(i int) string

random generate i length alphanum string

func Run added in v0.11.0

func Run()

func ServeWebSocket added in v0.10.0

func ServeWebSocket(w http.ResponseWriter, r *http.Request, o *Observer)

serve an actual websocket

func SetHeaders added in v0.10.0

func SetHeaders(w http.ResponseWriter, r *http.Request)

func WithCors added in v0.11.0

func WithCors(h http.Handler) http.Handler

Types

type Message

type Message struct {
	Id       string
	Text     string
	Type     string
	Created  int64 `json:",string"`
	Stream   string
	Metadata *Metadata
}

func NewCommand added in v0.12.0

func NewCommand(prompt, stream string) *Message

func NewEvent

func NewEvent(text, stream string) *Message

func NewMessage

func NewMessage(text, stream string) *Message

type Metadata

type Metadata struct {
	Created     int64
	Title       string
	Description string
	Type        string
	Image       string
	Url         string
	Site        string
}

func GetMetadata

func GetMetadata(uri string) *Metadata

type Observer

type Observer struct {
	Id     string
	Stream string
	Events chan *Message
	Kill   chan bool
}

func NewObserver added in v0.11.0

func NewObserver(stream string) *Observer

type Server

type Server struct {
	Created int64
	Events  chan *Message
	// contains filtered or unexported fields
}

func New

func New() *Server

func (*Server) Broadcast

func (s *Server) Broadcast(message *Message)

func (*Server) List

func (s *Server) List() map[string]*Stream

func (*Server) Metadata

func (s *Server) Metadata(t *Message)

func (*Server) New

func (s *Server) New(stream, secret string, private bool, ttl int) error

func (*Server) Observe

func (s *Server) Observe(o *Observer)

func (*Server) Retrieve

func (s *Server) Retrieve(message string, streem string, direction, last, limit int64) []*Message

func (*Server) Run

func (s *Server) Run()

func (*Server) Store

func (s *Server) Store(message *Message)

type Stream

type Stream struct {
	// A unique id
	Id string
	// A secret for access
	Secret string
	// Messages in the stream
	Messages []*Message
	// not listed
	Private bool
	// In nanoseconds
	Updated int64
	// In seconds
	TTL int64
	// stream observers
	Observers int64
}

func NewStream

func NewStream(id, secret string, private bool, ttl int) *Stream

Jump to

Keyboard shortcuts

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