Add authentication option via OnConnect field
The goal of this PR is to allow SASL-style authentication through the ASCII protocol (https://www.memcachier.com/documentation#protocols). I'm not confident this a particularly good way of going about it though.
Each TCP connection needs to be authenticated, using a set command. Unfortunately, both the connection structs and low-level set commands aren't exported, so it seems only possible to do from within the package.
In order to make this somewhat general, this PR adds an OnConnect field that will be called each time a new TCP connection is created and a SetAuthentication function that uses it.
@alevy do you have a usage example?
@jdcauley do you mean how this would be used?
package main;
import (
"./memcache"
"fmt"
)
func main() {
client := memcache.New("localhost:11211");
client.SetAuthentication("usernamd", []byte("password"));
res, err := client.Get("hello");
fmt.Println(res, err);
}
If you mean an actual use case in production, not exactly. We have a more MemCachier specific version (https://github.com/memcachier/gomemcache) which some MemCachier customers use.
I have tried your PR and run your demo listed above. But it didn't work. The error messages for Add or Get operations are EOF. Is anything wrong with my case? My memcached is launched with SASL and sasl accounts are managed by saslauthd in shadow mechanism type. And I succeed to run https://github.com/bmizerany/mc.