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

Commit

Permalink
Force use of "custom" network string for DialWithCustomDialer
Browse files Browse the repository at this point in the history
  • Loading branch information
iaburton committed Jul 9, 2018
1 parent 4400610 commit 70c2e62
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
7 changes: 1 addition & 6 deletions dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,10 @@ func (df dialerFunctionWrapper) Call() (serverConn, string, error) {
// value), and adding a new network type is as easy as writing the dialer
// function and adding it to the map.
func (w *Writer) getDialer() dialerFunctionWrapper {
if w.customDial != nil {
// we use 'customDialer' as the name, since the custom dialer can technically
// override any network we pass in anyways
return dialerFunctionWrapper{"customDialer", w.customDialer}
}

dialers := map[string]dialerFunctionWrapper{
"": dialerFunctionWrapper{"unixDialer", w.unixDialer},
"tcp+tls": dialerFunctionWrapper{"tlsDialer", w.tlsDialer},
"custom": dialerFunctionWrapper{"customDialer", w.customDialer},
}
dialer, ok := dialers[w.network]
if !ok {
Expand Down
6 changes: 2 additions & 4 deletions dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestGetDialer(t *testing.T) {
t.Errorf("should get basicDialer, got: %v", dialer)
}

w.network = "custom"
w.customDial = func(string, string) (net.Conn, error) { return nil, nil }
dialer = w.getDialer()
if "customDialer" != dialer.Name {
Expand Down Expand Up @@ -209,10 +210,7 @@ func TestCustomDialer(t *testing.T) {
// A custom dialer can really be anything, so we don't test an actual connection
// instead we test the behavior of this code path

// a dialer implementation may still consult the passed network and address
// so make sure we don't change them before being passed in

nwork, addr := "custom_network_to_pass", "custom_addr_to_pass"
nwork, addr := "custom", "custom_addr_to_pass"
w := Writer{
priority: LOG_ERR,
tag: "tag",
Expand Down
1 change: 1 addition & 0 deletions srslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var ErrNilDialFunc = errors.New("srslog: nil DialFunc passed to DialWithCustomDi

// DialWithCustomDialer establishes a connection by calling customDial.
// Each write to the returned Writer sends a log message with the given facility, severity and tag.
// Network must be "custom" in order for this package to use customDial.
// While network and raddr will be passed to customDial, it is allowed for customDial to ignore them.
// If customDial is nil, this function returns ErrNilDialFunc.
func DialWithCustomDialer(network, raddr string, priority Priority, tag string, customDial DialFunc) (*Writer, error) {
Expand Down

0 comments on commit 70c2e62

Please sign in to comment.