Documentation ¶
Index ¶
- Variables
- func Notify(uri string, client *http.Client, getReq getReqFunc, evCh chan<- *Event) error
- type Conn
- func (c *Conn) Close()
- func (c *Conn) IsOpen() bool
- func (c *Conn) Write(msg []byte) error
- func (c *Conn) WriteEvent(typ string, msg []byte) error
- func (c *Conn) WriteEventWithID(id, typ string, msg []byte) error
- func (c *Conn) WriteJson(value interface{}) error
- func (c *Conn) WriteJsonEvent(typ string, value interface{}) error
- func (c *Conn) WriteString(msg string) error
- func (c *Conn) WriteStringEvent(typ, msg string) error
- func (c *Conn) WriteXml(value interface{}) error
- func (c *Conn) WriteXmlEvent(typ string, value interface{}) error
- type Event
- type Upgrader
Constants ¶
This section is empty.
Variables ¶
var ( ErrStreamingNotSupported = errors.New("streaming unsupported") ErrConnectionClosed = errors.New("connection already closed") )
var DefaultClient = &http.Client{}
Client is the default client used for requests.
var DefaultGetReq = func(method, uri string, body io.Reader) (*http.Request, error) { return http.NewRequest(method, uri, body) }
DefaultGetReq is a function to return a single request. It will be used by notify to get a request and can be replaced if additional configuration is desired on the request. The "Accept" header will necessarily be overwritten.
var ( // ErrNilChan will be returned by Notify if it is passed a nil channel ErrNilChan = fmt.Errorf("nil channel given") )
Functions ¶
func Notify ¶ added in v1.1.0
Notify takes the uri of an SSE stream, http.Client, request generator function and a channel, and will send an Event down the channel when recieved, until the stream is closed. This is blocking, and so you will likely want to call this
in a new goroutine (via `go Notify(..)`). If client or getReq ire nil, the
DefaultClient and DefaultGetReq values are used.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func Upgrade ¶
Global Upgrade for method for usage without a Upgrader instance. Refer to Upgrader.Upgrade for complete documentation.
func (*Conn) Close ¶
func (c *Conn) Close()
Forces the connection to close. The Conn object should not be used anymore.
func (*Conn) Write ¶
Sends a byte-slice to the connected client. Returns an error if the connection is already closed.
func (*Conn) WriteEvent ¶
Sends a byte-slice to the connected client and triggers the specified event with the data. Returns an error if the connection is already closed.
func (*Conn) WriteEventWithID ¶
Sends a byte-slice to the connected client and triggers the specified event with the data. Returns an error if the connection is already closed.
func (*Conn) WriteJson ¶
Sends a json-encoded struct to the connected client. Returns an error if the connection is already closed or if the encoding failed.
func (*Conn) WriteJsonEvent ¶
Sends a json-encoded struct to the connected client, targeting the specified event. Returns an error if the connection is already closed or if the encoding failed.
func (*Conn) WriteString ¶
Sends a string to the connected client. Returns an error if the connection is already closed.
func (*Conn) WriteStringEvent ¶
Sends a string to the connected client, targeting the specified event. Returns an error if the connection is already closed.
func (*Conn) WriteXml ¶
Sends a xml-encoded struct to the connected client. Returns an error if the connection is already closed or if the encoding failed.
func (*Conn) WriteXmlEvent ¶
Sends a xml-encoded struct to the connected client, targeting the specified event. Returns an error if the connection is already closed or if the encoding failed.
type Upgrader ¶
func (Upgrader) Upgrade ¶
Takes over a HTTP-connection and returns a SSE-Connection, which can be used to send events. Returns an error, if the connection does not support streaming. Please note, that in this case the client will also be notified and the HTTP-connection should therefore not be used anymore.