I noticed the following code works fine:
c := *memcache.New()
err := c.Ping()
if err != nil {
panic(err)
}
fmt.Println("No problem")
At first glance it looks okay - no hosts to ping means no errors, but there are a couple of problems:
- An actual client is constructed which is essentially non functional. Furthermore
New() doesn't return an error and the only way to verify if the client is in fact functional is to run another operation.
- If we add further statements such as
err = c.Add(&memcache.Item{Key: "k", Value: []byte("v")}) those will fail which leads to inconsistent behaviour in the API.
I suppose there are 2 ways to fix that - either change Ping() to check the hosts size, or change New() to do that and return an error
I noticed the following code works fine:
At first glance it looks okay - no hosts to ping means no errors, but there are a couple of problems:
New()doesn't return an error and the only way to verify if the client is in fact functional is to run another operation.err = c.Add(&memcache.Item{Key: "k", Value: []byte("v")})those will fail which leads to inconsistent behaviour in the API.I suppose there are 2 ways to fix that - either change
Ping()to check the hosts size, or changeNew()to do that and return an error