Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

Commit

Permalink
Add ErrNilDialFunc and return it from DialWithCustomDialer. We add it…
Browse files Browse the repository at this point in the history
… here instead of the customDialer method since it only needs to be checked once, not every time a dial attempt is made, and it is similiar to other checks made by Dial* funcs
  • Loading branch information
iaburton committed Jul 9, 2018
1 parent 2a1fc6b commit 4400610
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion srslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package srslog
import (
"crypto/tls"
"crypto/x509"
"errors"
"io/ioutil"
"log"
"net"
Expand Down Expand Up @@ -36,11 +37,18 @@ func Dial(network, raddr string, priority Priority, tag string) (*Writer, error)
return DialWithTLSConfig(network, raddr, priority, tag, nil)
}

// ErrNilDialFunc is returned from DialWithCustomDialer when a nil DialFunc is passed,
// avoiding a nil pointer deference panic.
var ErrNilDialFunc = errors.New("srslog: nil DialFunc passed to DialWithCustomDialer")

// DialWithCustomDialer establishes a connection by calling customDial.
// Each write to the returned Writer sends a log message with the given facility, severity and tag.
// While network and raddr will be passed to customDial, it is allowed for customDial to ignore them.
// If customDial is nil, this function behaves like Dial.
// If customDial is nil, this function returns ErrNilDialFunc.
func DialWithCustomDialer(network, raddr string, priority Priority, tag string, customDial DialFunc) (*Writer, error) {
if customDial == nil {
return nil, ErrNilDialFunc
}
return dialAllParameters(network, raddr, priority, tag, nil, customDial)
}

Expand Down

0 comments on commit 4400610

Please sign in to comment.