Documentation ¶
Index ¶
- Constants
- func Observe(ctx app.Context, value *Connection) app.Observer
- type ChangeReason
- type Component
- type Connection
- func (c *Connection) ChangeReason() ChangeReason
- func (c *Connection) ClientName() string
- func (c *Connection) InProcessConn() (netConn net.Conn, err error)
- func (c *Connection) IsConnected() bool
- func (c *Connection) Nats() (conn *nats.Conn, err error)
- func (c *Connection) Publish(subject string, message []byte) (err error)
- func (c *Connection) Subscribe(subject string, cb nats.MsgHandler) (err error)
- type Manager
- type Proxy
Examples ¶
Constants ¶
View Source
const Ping = State + ".ping"
View Source
const State = "natsws.Connection"
View Source
const StateClientName = State + ".clientName"
View Source
const UseDialer = "GOAPP_NATSWS_DIALER"
Variables ¶
This section is empty.
Functions ¶
func Observe ¶
func Observe(ctx app.Context, value *Connection) app.Observer
Observe simplifies observing the State of the Connection.
The pointer to the Connection must not be nil. See example for ways to initialize the Connection pointer.
Example ¶
package main import "github.com/maxence-charriere/go-app/v9/pkg/app" type Demo struct { app.Compo conn Connection } // OnMount demonstrating non pointer Connection. func (d *Demo) OnMount(ctx app.Context) { Observe(ctx, &d.conn).OnChange(func() { if d.conn.ChangeReason() == Connect { // first time setup } else { // reconnect setup } }) } type DemoTwo struct { app.Compo conn *Connection } // OnMount demonstrating pointer Connection. func (d *DemoTwo) OnMount(ctx app.Context) { d.conn = &Connection{} Observe(ctx, d.conn) } func main() { // the two components above show two different methods // for calling Observe with a non nil pointer Connection }
Output:
Types ¶
type ChangeReason ¶ added in v1.0.1
type ChangeReason string
const Connect ChangeReason = "connect"
const Disconnect ChangeReason = "disconnect"
const Reconnect ChangeReason = "reconnect"
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func (*Connection) ChangeReason ¶ added in v1.0.1
func (c *Connection) ChangeReason() ChangeReason
func (*Connection) ClientName ¶
func (c *Connection) ClientName() string
func (*Connection) InProcessConn ¶
func (c *Connection) InProcessConn() (netConn net.Conn, err error)
func (*Connection) IsConnected ¶
func (c *Connection) IsConnected() bool
func (*Connection) Nats ¶
func (c *Connection) Nats() (conn *nats.Conn, err error)
func (*Connection) Publish ¶
func (c *Connection) Publish(subject string, message []byte) (err error)
func (*Connection) Subscribe ¶
func (c *Connection) Subscribe(subject string, cb nats.MsgHandler) (err error)
type Manager ¶
type Manager interface { // Backends should return a list of current nats websocket endpoints. // If the format is ws[s]://host:port then a websocket proxy will be used. // If the format is http[s]://host:port then a httputil.ReverseProxy will be used. Backends() []string // TLSConfig passed to tls.Dial for testing tls backends. TLSConfig() *tls.Config // OnError will be called when errors occur within the websocket proxy only. OnError(message string, err error) // Randomize indicates Backends() should be shuffled before connection attempts. Randomize() bool // IsDebug will log all payloads on the websocket proxy only when true. IsDebug() bool }
func StaticManager ¶
Click to show internal directories.
Click to hide internal directories.