Skip to content

Commit

Permalink
staticcheck fixes, godoc
Browse files Browse the repository at this point in the history
Signed-off-by: Waldemar Quevedo <wally@nats.io>
  • Loading branch information
wallyqs committed Nov 29, 2022
1 parent a15a1fc commit 5ae4fe2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
35 changes: 35 additions & 0 deletions example_test.go
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"fmt"
"log"
"net"
"time"

"github.com/nats-io/nats.go"
Expand Down Expand Up @@ -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 true
}

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}}
nc, _ := nats.Connect("demo.nats.io", SetCustomDialer(sd))
defer nc.Close()
}

// This Example shows an asynchronous subscriber.
func ExampleConn_Subscribe() {
nc, _ := nats.Connect(nats.DefaultURL)
Expand Down
5 changes: 3 additions & 2 deletions nats.go
Expand Up @@ -247,8 +247,9 @@ type asyncCallbacksHandler struct {
// Option is a function on the options for a connection.
type Option func(*Options) error

// CustomDialer can be used to specify any dialer, not necessarily
// a *net.Dialer.
// CustomDialer can be used to specify any dialer, not necessarily a
// *net.Dialer. A CustomDialer may also implement `SkipTLSHandshake() bool`
// in order to skip the TLS handshake in case not required.
type CustomDialer interface {
Dial(network, address string) (net.Conn, error)
}
Expand Down
2 changes: 1 addition & 1 deletion services/service.go
Expand Up @@ -31,7 +31,7 @@ import (

type (

// Service is an interface for sevice management.
// Service is an interface for service management.
// It exposes methods to stop/reset a service, as well as get information on a service.
Service interface {
ID() string
Expand Down
4 changes: 2 additions & 2 deletions ws_test.go
Expand Up @@ -897,7 +897,7 @@ func TestWSWithTLSCustomDialer(t *testing.T) {
copts := make([]Option, 0)
copts = append(copts, Secure(&tls.Config{InsecureSkipVerify: true}))
copts = append(copts, SetCustomDialer(sd))
nc, err := Connect(fmt.Sprintf("wss://localhost:%d", sopts.Websocket.Port), copts...)
_, err := Connect(fmt.Sprintf("wss://localhost:%d", sopts.Websocket.Port), copts...)
if err == nil {
t.Fatalf("Expected error on connect: %v", err)
}
Expand All @@ -915,7 +915,7 @@ func TestWSWithTLSCustomDialer(t *testing.T) {
}
copts = append(copts, Secure(&tls.Config{InsecureSkipVerify: true}))
copts = append(copts, SetCustomDialer(sd))
nc, err = Connect(fmt.Sprintf("wss://localhost:%d", sopts.Websocket.Port), copts...)
nc, err := Connect(fmt.Sprintf("wss://localhost:%d", sopts.Websocket.Port), copts...)
if err != nil {
t.Fatalf("Unexpected error on connect: %v", err)
}
Expand Down

0 comments on commit 5ae4fe2

Please sign in to comment.