Teamwork/spamc

Ability to connect over Unix socket?

Opened this issue · 2 comments

Really useful but.. do you support unix socket? If not, would you accept a PR?

Thanks a lot! Awesome work

Thanks!

Do you support unix socket

Maybe? I never tried it. The New() function is func New(addr string, d Dialer), where Dialer is:

type Dialer interface {
    DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

This may already work if you write a thin wrapper around net.UnixConn or something.

It could (and should) definitely be more straightforward than that though!

would you accept a PR?

Sure; the only reason it's not supported is because I don't need/use it.

I think it won't work because of this line -> https://github.com/Teamwork/spamc/blob/master/spamc.go#L163

The only solution I see would be to add a third parameter to the New() function, something like:

func New(addr string, d Dialer, p string) {
    ...
    return &Client{
		addr:   addr,
		dialer: d,
                proto: p,
    }
}

and then instead of https://github.com/Teamwork/spamc/blob/master/spamc.go#L163 :

conn, err := c.dialer.DialContext(ctx, c.proto, c.addr)

Would it be ok? (I'll update the tests too)