mirror of
https://github.com/go-mqtt/mqtt.git
synced 2025-08-08 22:42:05 +03:00
Follow constructor convention for Dialers.
This commit is contained in:
@@ -47,9 +47,9 @@ var (
|
||||
// Dialer abstracts the transport layer establishment.
|
||||
type Dialer func(ctx context.Context) (net.Conn, error)
|
||||
|
||||
// UnsecuredDialer creates plain network connections.
|
||||
// NewDialer provides plain network connections.
|
||||
// See net.Dial for details on the network & address syntax.
|
||||
func UnsecuredDialer(network, address string) Dialer {
|
||||
func NewDialer(network, address string) Dialer {
|
||||
return func(ctx context.Context) (net.Conn, error) {
|
||||
// minimize timer use; covered by WireTimeout
|
||||
dialer := net.Dialer{KeepAlive: -1}
|
||||
@@ -57,9 +57,9 @@ func UnsecuredDialer(network, address string) Dialer {
|
||||
}
|
||||
}
|
||||
|
||||
// SecuredDialer creates TLS network connections.
|
||||
// NewTLSDialer provides secured network connections.
|
||||
// See net.Dial for details on the network & address syntax.
|
||||
func SecuredDialer(network, address string, config *tls.Config) Dialer {
|
||||
func NewTLSDialer(network, address string, config *tls.Config) Dialer {
|
||||
return func(ctx context.Context) (net.Conn, error) {
|
||||
dialer := tls.Dialer{
|
||||
// minimize timer use; covered by WireTimeout
|
||||
|
@@ -92,11 +92,11 @@ func parseConfig() *mqtt.Config {
|
||||
UserName: *userFlag,
|
||||
}
|
||||
if *tlsFlag {
|
||||
config.Dialer = mqtt.SecuredDialer(*netFlag, addr, &tls.Config{
|
||||
config.Dialer = mqtt.NewTLSDialer(*netFlag, addr, &tls.Config{
|
||||
ServerName: *serverFlag,
|
||||
})
|
||||
} else {
|
||||
config.Dialer = mqtt.UnsecuredDialer(*netFlag, addr)
|
||||
config.Dialer = mqtt.NewDialer(*netFlag, addr)
|
||||
}
|
||||
if *passFlag != "" {
|
||||
bytes, err := os.ReadFile(*passFlag)
|
||||
|
@@ -42,7 +42,7 @@ func init() {
|
||||
// It is good practice to install the client from main.
|
||||
func ExampleNewClient_setup() {
|
||||
client := mqtt.NewClient(&mqtt.Config{
|
||||
Dialer: mqtt.UnsecuredDialer("tcp", "localhost:1883"),
|
||||
Dialer: mqtt.NewDialer("tcp", "localhost:1883"),
|
||||
Store: mqtt.NewVolatileStore("demo-client"),
|
||||
WireTimeout: time.Second,
|
||||
BufSize: 8192,
|
||||
|
@@ -47,7 +47,7 @@ func race(t *testing.T, host string, deliveryLevel int) {
|
||||
testTopic := fmt.Sprintf("test/race-%d", deliveryLevel)
|
||||
|
||||
client := mqtt.NewClient(&mqtt.Config{
|
||||
Dialer: mqtt.UnsecuredDialer("tcp", net.JoinHostPort(host, "1883")),
|
||||
Dialer: mqtt.NewDialer("tcp", net.JoinHostPort(host, "1883")),
|
||||
WireTimeout: time.Second,
|
||||
BufSize: 1024,
|
||||
Store: mqtt.NewVolatileStore(t.Name()),
|
||||
|
Reference in New Issue
Block a user