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

Function ExampleConnect

example_test.go:27–46  ·  view source on GitHub ↗

Shows different ways to create a Conn.

()

Source from the content-addressed store, hash-verified

25
26// Shows different ways to create a Conn.
27func ExampleConnect() {
28 nc, _ := nats.Connect("demo.nats.io")
29 nc.Close()
30
31 nc, _ = nats.Connect("nats://derek:secretpassword@demo.nats.io:4222")
32 nc.Close()
33
34 nc, _ = nats.Connect("tls://derek:secretpassword@demo.nats.io:4443")
35 nc.Close()
36
37 opts := nats.Options{
38 AllowReconnect: true,
39 MaxReconnect: 10,
40 ReconnectWait: 5 * time.Second,
41 Timeout: 1 * time.Second,
42 }
43
44 nc, _ = opts.Connect()
45 nc.Close()
46}
47
48type skipTLSDialer struct {
49 dialer *net.Dialer

Callers

nothing calls this directly

Calls 2

ConnectMethod · 0.95
CloseMethod · 0.45

Tested by

no test coverage detected