MCPcopy
hub / github.com/nats-io/nats.go / Connect

Function Connect

nats.go:976–987  ·  nats.go::Connect

Connect will attempt to connect to the NATS system. The url can contain username/password semantics. e.g. nats://derek:pass@localhost:4222 Comma separated arrays are also supported, e.g. urlA, urlB. Options start with the defaults but can be overridden. To connect to a NATS Server's websocket port,

(url string, options ...Option)

Source from the content-addressed store, hash-verified

974// To connect to a NATS Server's websocket port, use the `ws` or `wss` scheme, such as
975// `ws://localhost:8080`. Note that websocket schemes cannot be mixed with others (nats/tls).
976func Connect(url string, options ...Option) (*Conn, error) {
977 opts := GetDefaultOptions()
978 opts.Servers = processUrlString(url)
979 for _, opt := range options {
980 if opt != nil {
981 if err := opt(&opts); err != nil {
982 return nil, err
983 }
984 }
985 }
986 return opts.Connect()
987}
988
989// Options that can be passed to Connect.
990

Callers 6

TestWSNoMixingSchemeFunction · 0.85
TestWSProxyPathFunction · 0.85
TestNKeyOptionFromSeedFunction · 0.85
TestLameDuckModeFunction · 0.85

Calls 3

GetDefaultOptionsFunction · 0.85
processUrlStringFunction · 0.85
ConnectMethod · 0.80

Tested by 6

TestWSNoMixingSchemeFunction · 0.68
TestWSProxyPathFunction · 0.68
TestNKeyOptionFromSeedFunction · 0.68
TestLameDuckModeFunction · 0.68