sseclient

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAPIKey

func WithAPIKey(apikey string) func(*API)

func WithEventBufferSize

func WithEventBufferSize(eventBufferSize int) func(*Sub)

func WithHTTPClient

func WithHTTPClient(httpclient *http.Client) func(*API)

func WithJWTKey

func WithJWTKey(jwtKey string) func(*Sub)

func WithMaxBufferSize

func WithMaxBufferSize(maxBufferSize int) func(*Sub)

func WithReconnectStrategy

func WithReconnectStrategy(reconnectStrategy backoff.BackOff) func(*Sub)

Types

type API

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

func NewAPI

func NewAPI(url string, options ...func(*API)) *API

func (*API) GetOnlines

func (p *API) GetOnlines(ctx context.Context, params *GetOnlineParams) (map[string]PresenceItem, error)

GetOnlines allows getting channel online presence information (all clients currently subscribed on this channel)

func (*API) Publish

func (p *API) Publish(ctx context.Context, params *PublishParams) error

type APIMethod

type APIMethod string

type APIRequest

type APIRequest struct {
	Method string      `json:"method"`
	Params interface{} `json:"params"`
}

type BoolValue

type BoolValue struct {
	Value bool `json:"value,omitempty"`
}

type ErrBadStatus

type ErrBadStatus struct {
	Code int
	Body string
}

func (*ErrBadStatus) Error

func (err *ErrBadStatus) Error() string

type ErrLogic

type ErrLogic struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

func (*ErrLogic) Error

func (err *ErrLogic) Error() string

type EventData

type EventData struct {
	Channel string `json:"channel,omitempty"`
	Pub     struct {
		Data json.RawMessage `json:"data,omitempty"`
	} `json:"pub,omitempty"`
}

type GetOnlineParams

type GetOnlineParams struct {
	Channel string `json:"channel,omitempty"`
}

https://centrifugal.dev/docs/3/server/server_api#presence

type GetOnlineResponse

type GetOnlineResponse struct {
	Error  ErrLogic `json:"error,omitempty"`
	Result struct {
		Presence map[string]PresenceItem `json:"presence,omitempty"`
	} `json:"result,omitempty"`
}

type PresenceItem

type PresenceItem struct {
	Client string `json:"client,omitempty"`
	User   string `json:"user,omitempty"`
}

type PublishParams

type PublishParams struct {
	Channel     string          `json:"channel,omitempty"`
	Data        json.RawMessage `json:"data,omitempty"`
	SkipHistory bool            `json:"skip_history,omitempty"`
}

type PublishResponse

type PublishResponse struct {
	Error  ErrLogic `json:"error,omitempty"`
	Result struct {
		Offset int    `json:"offset,omitempty"`
		Epoch  string `json:"epoch,omitempty"`
	} `json:"result,omitempty"`
}

type Sub

type Sub struct {
	OnReconnectNotify backoff.Notify
	OnConnect         sse.ConnCallback
	OnDisconnect      sse.ConnCallback
	// contains filtered or unexported fields
}

func NewSub

func NewSub(logger *logr.Logger, sseURL string, options ...func(*Sub)) *Sub

func (*Sub) Subscribe

func (s *Sub) Subscribe(ctx context.Context, channel string, clientName string) (<-chan *sse.Event, error)

type SubscribeOptionOverride

type SubscribeOptionOverride struct {
	// Presence turns on participating in channel presence.
	Presence *BoolValue `json:"presence,omitempty"`
	// JoinLeave enables sending Join and Leave messages for this client in channel.
	JoinLeave *BoolValue `json:"join_leave,omitempty"`
	// ForcePushJoinLeave forces sending join/leave for this client.
	ForcePushJoinLeave *BoolValue `json:"force_push_join_leave,omitempty"`
	// ForcePositioning on says that client will additionally sync its position inside
	// a stream to prevent message loss. Make sure you are enabling ForcePositioning in channels
	// that maintain Publication history stream. When ForcePositioning is on  Centrifuge will
	// include StreamPosition information to subscribe response - for a client to be able
	// to manually track its position inside a stream.
	ForcePositioning *BoolValue `json:"force_positioning,omitempty"`
	// ForceRecovery turns on recovery option for a channel. In this case client will try to
	// recover missed messages automatically upon resubscribe to a channel after reconnect
	// to a server. This option also enables client position tracking inside a stream
	// (like ForcePositioning option) to prevent occasional message loss. Make sure you are using
	// ForceRecovery in channels that maintain Publication history stream.
	ForceRecovery *BoolValue `json:"force_recovery,omitempty"`
}

type SubscribeOptions

type SubscribeOptions struct {
	// Info defines custom channel information, zero value means no channel information.
	Info json.RawMessage `json:"info,omitempty"`
	// Base64Info is like Info but for binary.
	Base64Info string `json:"b64info,omitempty"`
	// Data to send to a client with Subscribe Push.
	Data json.RawMessage `json:"data,omitempty"`
	// Base64Data is like Data but for binary data.
	Base64Data string `json:"b64data,omitempty"`
	// Override channel options can contain channel options overrides.
	Override *SubscribeOptionOverride `json:"override,omitempty"`
}

Jump to

Keyboard shortcuts

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