mirror of
https://github.com/nats-io/nats.go.git
synced 2025-09-27 04:46:01 +08:00
Add SkipTLSHandshake small interface to CustomDialer
Signed-off-by: Waldemar Quevedo <wally@nats.io> Co-authored-by: Piotr Piotrowski <piotr@synadia.com>
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
@@ -44,6 +45,40 @@ func ExampleConnect() {
|
||||
nc.Close()
|
||||
}
|
||||
|
||||
type skipTLSDialer struct {
|
||||
dialer *net.Dialer
|
||||
skipTLS bool
|
||||
}
|
||||
|
||||
func (sd *skipTLSDialer) Dial(network, address string) (net.Conn, error) {
|
||||
return sd.dialer.Dial(network, address)
|
||||
}
|
||||
|
||||
func (sd *skipTLSDialer) SkipTLSHandshake() bool {
|
||||
return sd.skipTLS
|
||||
}
|
||||
|
||||
func ExampleCustomDialer() {
|
||||
// Given the following CustomDialer implementation:
|
||||
//
|
||||
// type skipTLSDialer struct {
|
||||
// dialer *net.Dialer
|
||||
// skipTLS bool
|
||||
// }
|
||||
//
|
||||
// func (sd *skipTLSDialer) Dial(network, address string) (net.Conn, error) {
|
||||
// return sd.dialer.Dial(network, address)
|
||||
// }
|
||||
//
|
||||
// func (sd *skipTLSDialer) SkipTLSHandshake() bool {
|
||||
// return true
|
||||
// }
|
||||
//
|
||||
sd := &skipTLSDialer{dialer: &net.Dialer{Timeout: 2 * time.Second}, skipTLS: true}
|
||||
nc, _ := nats.Connect("demo.nats.io", nats.SetCustomDialer(sd))
|
||||
defer nc.Close()
|
||||
}
|
||||
|
||||
// This Example shows an asynchronous subscriber.
|
||||
func ExampleConn_Subscribe() {
|
||||
nc, _ := nats.Connect(nats.DefaultURL)
|
||||
|
Reference in New Issue
Block a user