sse

package module
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldId      = "id"
	FieldData    = "data"
	FieldEvent   = "event"
	FieldRetry   = "retry"
	FieldComment = ":"
)
View Source
const DefaultBufferSize = 1024
View Source
const (
	KindSSE transport.Kind = "sse"
)

Variables

This section is empty.

Functions

func SetOperation

func SetOperation(ctx context.Context, op string)

SetOperation sets the transport operation.

Types

type Any

type Any interface{}

type Event

type Event struct {
	ID      []byte
	Data    []byte
	Event   []byte
	Retry   []byte
	Comment []byte
	// contains filtered or unexported fields
}

Event holds all the event source fields

type EventLog

type EventLog []*Event

EventLog holds all of previous events

func (*EventLog) Add

func (e *EventLog) Add(ev *Event)

Add event to eventlog

func (*EventLog) Clear

func (e *EventLog) Clear()

Clear events from eventlog

func (*EventLog) Replay

func (e *EventLog) Replay(s *Subscriber)

Replay events to a subscriber

type MessagePayload

type MessagePayload Any

type Server

type Server struct {
	*http.Server
	// contains filtered or unexported fields
}

func NewServer

func NewServer(opts ...ServerOption) *Server

NewServer will create a server and setup defaults

func (*Server) CreateStream

func (s *Server) CreateStream(streamId StreamID) *Stream

CreateStream will create a new stream and register it

func (*Server) Endpoint

func (s *Server) Endpoint() (*url.URL, error)

Endpoint return a real address to registry endpoint.

func (*Server) Handle

func (s *Server) Handle(path string, h http.Handler)

Handle registers a new route with a matcher for the URL path.

func (*Server) HandleFunc

func (s *Server) HandleFunc(path string, h http.HandlerFunc)

HandleFunc registers a new route with a matcher for the URL path.

func (*Server) HandleHeader

func (s *Server) HandleHeader(key, val string, h http.HandlerFunc)

HandleHeader registers a new route with a matcher for request header values.

func (*Server) HandlePrefix

func (s *Server) HandlePrefix(prefix string, h http.Handler)

HandlePrefix registers a new route with a matcher for the URL path prefix.

func (*Server) HandleServeHTTP

func (s *Server) HandleServeHTTP(path string)

HandleServeHTTP registers a new route with a matcher for the URL path.

func (*Server) Name

func (s *Server) Name() string

Name of server

func (*Server) Publish

func (s *Server) Publish(_ context.Context, streamId StreamID, event *Event)

Publish sends a message to every client in a streamID. If the stream's buffer is full, it blocks until the message is sent out to all subscribers (but not necessarily arrived the clients), or when the stream is closed.

func (*Server) PublishData

func (s *Server) PublishData(ctx context.Context, streamId StreamID, data MessagePayload) error

PublishData will encode message and Publish it to every client in a streamID

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves new connections with events for a given stream ...

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts the HTTP server.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop stops the HTTP server.

func (*Server) TryPublish

func (s *Server) TryPublish(_ context.Context, streamId StreamID, event *Event) bool

TryPublish is the same as Publish except that when the operation would cause the call to be blocked, it simply drops the message and returns false. Together with a small BufferSize, it can be useful when publishing the latest message ASAP is more important than reliable delivery.

type ServerOption

type ServerOption func(o *Server)

func WithAddress

func WithAddress(addr string) ServerOption

WithAddress with server address

func WithAutoReply

func WithAutoReply(enable bool) ServerOption

WithAutoReply with server auto reply or not

func WithAutoStream

func WithAutoStream(enable bool) ServerOption

WithAutoStream with server auto stream or not

func WithBufferSize

func WithBufferSize(size int) ServerOption

WithBufferSize with server buffer size

func WithCodec

func WithCodec(c string) ServerOption

WithCodec with server codec

func WithEncodeBase64

func WithEncodeBase64(enable bool) ServerOption

WithEncodeBase64 with server encode base64

func WithEventTTL

func WithEventTTL(timeout time.Duration) ServerOption

WithEventTTL with server event TTL

func WithHeaders

func WithHeaders(headers map[string]string) ServerOption

WithHeaders with server custom headers

func WithListener

func WithListener(lis net.Listener) ServerOption

WithListener with server listener

func WithNetwork

func WithNetwork(network string) ServerOption

WithNetwork with server network

func WithPath added in v2.0.5

func WithPath(path string) ServerOption

WithPath with path string

func WithSplitData

func WithSplitData(enable bool) ServerOption

WithSplitData with server split data or not

func WithSubscriberFunction

func WithSubscriberFunction(sub SubscriberFunction, unsub SubscriberFunction) ServerOption

WithSubscriberFunction with server subscriber function

func WithTLSConfig

func WithTLSConfig(c *tls.Config) ServerOption

WithTLSConfig with server TLS config

func WithTimeout

func WithTimeout(timeout time.Duration) ServerOption

WithTimeout with server timeout

type Stream

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

func (*Stream) StreamID

func (s *Stream) StreamID() StreamID

StreamID .

type StreamID

type StreamID string

type StreamManager

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

func NewStreamManager

func NewStreamManager() *StreamManager

NewStreamManager returns a new stream manager

func (*StreamManager) Add

func (s *StreamManager) Add(stream *Stream)

Add puts a new stream if not existed

func (*StreamManager) Clean

func (s *StreamManager) Clean()

Clean removes all

func (*StreamManager) Count

func (s *StreamManager) Count() int

Count returns currently total number of streams

func (*StreamManager) Exist

func (s *StreamManager) Exist(streamId StreamID) bool

Exist whether the streamID existed or not

func (*StreamManager) Get

func (s *StreamManager) Get(streamId StreamID) *Stream

Get returns an existed stream

func (*StreamManager) Range

func (s *StreamManager) Range(fn func(*Stream))

Range walks through list of streams

func (*StreamManager) Remove

func (s *StreamManager) Remove(stream *Stream)

Remove deletes a stream

func (*StreamManager) RemoveWithID

func (s *StreamManager) RemoveWithID(streamId StreamID)

RemoveWithID deletes a stream by streamID

type StreamMap

type StreamMap map[StreamID]*Stream

type Subscriber

type Subscriber struct {
	URL *url.URL
	// contains filtered or unexported fields
}

Subscriber holds subscriber properties

type SubscriberFunction

type SubscriberFunction func(streamID StreamID, sub *Subscriber)

type Transport

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

Transport is a socket transport.

func (*Transport) Endpoint

func (tr *Transport) Endpoint() string

Endpoint returns the transport endpoint.

func (*Transport) Kind

func (tr *Transport) Kind() transport.Kind

Kind returns the transport kind.

func (*Transport) Operation

func (tr *Transport) Operation() string

Operation returns the transport operation.

func (*Transport) PathTemplate

func (tr *Transport) PathTemplate() string

PathTemplate returns the http path template.

func (*Transport) ReplyHeader

func (tr *Transport) ReplyHeader() transport.Header

ReplyHeader returns the reply header.

func (*Transport) Request

func (tr *Transport) Request() *http.Request

Request returns the HTTP request.

func (*Transport) RequestHeader

func (tr *Transport) RequestHeader() transport.Header

RequestHeader returns the request header.

type Transporter

type Transporter interface {
	transport.Transporter
	Request() *http.Request
	PathTemplate() string
}

Jump to

Keyboard shortcuts

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