Documentation
¶
Index ¶
- Constants
- func Encode(w io.Writer, e *Event) (err error)
- func GetLastEventID(c *app.RequestContext) string
- type Client
- func (c *Client) GetBody() []byte
- func (c *Client) GetHeaders() map[string]string
- func (c *Client) GetHertzClient() do.Doer
- func (c *Client) GetLastEventID() []byte
- func (c *Client) GetMethod() string
- func (c *Client) GetURL() string
- func (c *Client) SetBody(body []byte)
- func (c *Client) SetDisconnectCallback(fn ConnCallback)
- func (c *Client) SetEncodingBase64(encodingBase64 bool)
- func (c *Client) SetHeaders(headers map[string]string)
- func (c *Client) SetHertzClient(hertzClient do.Doer)
- func (c *Client) SetMaxBufferSize(size int)
- func (c *Client) SetMethod(method string)
- func (c *Client) SetOnConnectCallback(fn ConnCallback)
- func (c *Client) SetResponseCallback(responseCallback ResponseCallback)
- func (c *Client) SetURL(url string)
- func (c *Client) Subscribe(handler func(msg *Event), opts ...SubscribeOption) error
- func (c *Client) SubscribeWithContext(ctx context.Context, handler func(msg *Event), opts ...SubscribeOption) (err error)
- type ClientOption
- type ClientOptions
- type ConnCallback
- type Event
- type EventStreamReader
- type ResponseCallback
- type Stream
- type SubscribeOption
- type SubscribeOptions
Constants ¶
const ( ContentType = "text/event-stream" LastEventID = "Last-Event-ID" )
Variables ¶
This section is empty.
Functions ¶
func GetLastEventID ¶
func GetLastEventID(c *app.RequestContext) string
GetLastEventID retrieve Last-Event-ID header if present.
Types ¶
type Client ¶ added in v0.0.2
type Client struct {
// contains filtered or unexported fields
}
Client handles an incoming server stream
func NewClient ¶ added in v0.0.2
NewClient creates a new client Deprecated, pls use NewClientWithOptions
func NewClientWithOptions ¶ added in v0.1.0
func NewClientWithOptions(opts ...ClientOption) (*Client, error)
NewClientWithOptions creates a new Client with specified ClientOption
func (*Client) GetHeaders ¶ added in v0.0.2
GetHeaders get sse client headers Deprecated
func (*Client) GetHertzClient ¶ added in v0.0.2
GetHertzClient get sse client Deprecated
func (*Client) GetLastEventID ¶ added in v0.0.2
GetLastEventID get sse client lastEventID Deprecated If you use a Client to initiate multiple SSE requests, the results returned by GetLastEventID do not identify which SSE request belongs to
func (*Client) SetBody ¶ added in v0.0.3
SetBody set sse client request body Deprecated, set in protocol.Request and use WithRequest instead
func (*Client) SetDisconnectCallback ¶ added in v0.0.2
func (c *Client) SetDisconnectCallback(fn ConnCallback)
SetDisconnectCallback specifies the function to run when the connection disconnects
func (*Client) SetEncodingBase64 ¶ added in v0.0.2
SetEncodingBase64 set sse client whether use the base64
func (*Client) SetHeaders ¶ added in v0.0.2
SetHeaders set sse client headers Deprecated, set in protocol.Request and use WithRequest instead
func (*Client) SetHertzClient ¶ added in v0.0.2
SetHertzClient set sse client Deprecated, set in NewClientWithOptions(WithHertzClient(hCli))
func (*Client) SetMaxBufferSize ¶ added in v0.0.2
SetMaxBufferSize set sse client MaxBufferSize
func (*Client) SetMethod ¶ added in v0.0.2
SetMethod set sse client request method Deprecated, set in protocol.Request and use WithRequest instead
func (*Client) SetOnConnectCallback ¶ added in v0.0.2
func (c *Client) SetOnConnectCallback(fn ConnCallback)
SetOnConnectCallback specifies the function to run when the connection is successful
func (*Client) SetResponseCallback ¶ added in v0.0.2
func (c *Client) SetResponseCallback(responseCallback ResponseCallback)
SetResponseCallback set sse client responseCallback
func (*Client) SetURL ¶ added in v0.0.2
SetURL set sse client url Deprecated, set in protocol.Request and use WithRequest instead
func (*Client) Subscribe ¶ added in v0.0.2
func (c *Client) Subscribe(handler func(msg *Event), opts ...SubscribeOption) error
Subscribe to a data stream
func (*Client) SubscribeWithContext ¶ added in v0.0.2
func (c *Client) SubscribeWithContext(ctx context.Context, handler func(msg *Event), opts ...SubscribeOption) (err error)
SubscribeWithContext to a data stream with context
type ClientOption ¶ added in v0.1.0
type ClientOption func(*ClientOptions)
func WithHertzClient ¶ added in v0.1.0
func WithHertzClient(cli do.Doer) ClientOption
WithHertzClient specifies the underlying Hertz Client
type ClientOptions ¶ added in v0.1.0
type ClientOptions struct {
// contains filtered or unexported fields
}
type ConnCallback ¶ added in v0.0.2
ConnCallback defines a function to be called on a particular connection event
type EventStreamReader ¶ added in v0.0.2
type EventStreamReader struct {
// contains filtered or unexported fields
}
EventStreamReader scans an io.Reader looking for EventStream messages.
func NewEventStreamReader ¶ added in v0.0.2
func NewEventStreamReader(eventStream io.Reader, maxBufferSize int) *EventStreamReader
NewEventStreamReader creates an instance of EventStreamReader.
type ResponseCallback ¶ added in v0.0.2
type ResponseCallback func(ctx context.Context, req *protocol.Request, resp *protocol.Response) error
ResponseCallback validates a response
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
func NewStream ¶
func NewStream(c *app.RequestContext) *Stream
NewStream creates a new stream for publishing Event.
func NewStreamWithWriter ¶ added in v0.0.6
func NewStreamWithWriter(c *app.RequestContext, writer network.ExtWriter) *Stream
NewStreamWithWriter creates a new stream with customize network.ExtWriter for publishing Event.
type SubscribeOption ¶ added in v0.1.0
type SubscribeOption func(*SubscribeOptions)
func WithRequest ¶ added in v0.1.0
func WithRequest(req *protocol.Request) SubscribeOption
WithRequest specifies the request sent by the Hertz Client each time Subscribe or SubscribeWithContext is performed. Request-related configuration items set via client.SetXX will not take effect when WithRequest is specified: (client.SetURL, client.SetBody, client.SetMethod, client.SetHeaders).
type SubscribeOptions ¶ added in v0.1.0
type SubscribeOptions struct {
// contains filtered or unexported fields
}
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
client/quickstart
* Copyright 2024 CloudWeGo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
|
* Copyright 2024 CloudWeGo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. |
server/quickstart
* Copyright 2024 CloudWeGo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
|
* Copyright 2024 CloudWeGo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. |