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.
|
// Dialer abstracts the transport layer establishment.
|
||||||
type Dialer func(ctx context.Context) (net.Conn, error)
|
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.
|
// 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) {
|
return func(ctx context.Context) (net.Conn, error) {
|
||||||
// minimize timer use; covered by WireTimeout
|
// minimize timer use; covered by WireTimeout
|
||||||
dialer := net.Dialer{KeepAlive: -1}
|
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.
|
// 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) {
|
return func(ctx context.Context) (net.Conn, error) {
|
||||||
dialer := tls.Dialer{
|
dialer := tls.Dialer{
|
||||||
// minimize timer use; covered by WireTimeout
|
// minimize timer use; covered by WireTimeout
|
||||||
|
@@ -92,11 +92,11 @@ func parseConfig() *mqtt.Config {
|
|||||||
UserName: *userFlag,
|
UserName: *userFlag,
|
||||||
}
|
}
|
||||||
if *tlsFlag {
|
if *tlsFlag {
|
||||||
config.Dialer = mqtt.SecuredDialer(*netFlag, addr, &tls.Config{
|
config.Dialer = mqtt.NewTLSDialer(*netFlag, addr, &tls.Config{
|
||||||
ServerName: *serverFlag,
|
ServerName: *serverFlag,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
config.Dialer = mqtt.UnsecuredDialer(*netFlag, addr)
|
config.Dialer = mqtt.NewDialer(*netFlag, addr)
|
||||||
}
|
}
|
||||||
if *passFlag != "" {
|
if *passFlag != "" {
|
||||||
bytes, err := os.ReadFile(*passFlag)
|
bytes, err := os.ReadFile(*passFlag)
|
||||||
|
@@ -42,7 +42,7 @@ func init() {
|
|||||||
// It is good practice to install the client from main.
|
// It is good practice to install the client from main.
|
||||||
func ExampleNewClient_setup() {
|
func ExampleNewClient_setup() {
|
||||||
client := mqtt.NewClient(&mqtt.Config{
|
client := mqtt.NewClient(&mqtt.Config{
|
||||||
Dialer: mqtt.UnsecuredDialer("tcp", "localhost:1883"),
|
Dialer: mqtt.NewDialer("tcp", "localhost:1883"),
|
||||||
Store: mqtt.NewVolatileStore("demo-client"),
|
Store: mqtt.NewVolatileStore("demo-client"),
|
||||||
WireTimeout: time.Second,
|
WireTimeout: time.Second,
|
||||||
BufSize: 8192,
|
BufSize: 8192,
|
||||||
|
@@ -47,7 +47,7 @@ func race(t *testing.T, host string, deliveryLevel int) {
|
|||||||
testTopic := fmt.Sprintf("test/race-%d", deliveryLevel)
|
testTopic := fmt.Sprintf("test/race-%d", deliveryLevel)
|
||||||
|
|
||||||
client := mqtt.NewClient(&mqtt.Config{
|
client := mqtt.NewClient(&mqtt.Config{
|
||||||
Dialer: mqtt.UnsecuredDialer("tcp", net.JoinHostPort(host, "1883")),
|
Dialer: mqtt.NewDialer("tcp", net.JoinHostPort(host, "1883")),
|
||||||
WireTimeout: time.Second,
|
WireTimeout: time.Second,
|
||||||
BufSize: 1024,
|
BufSize: 1024,
|
||||||
Store: mqtt.NewVolatileStore(t.Name()),
|
Store: mqtt.NewVolatileStore(t.Name()),
|
||||||
|
Reference in New Issue
Block a user