I would have taken a different approach for handling unsupported resource methods. I'd love to hear some feedback on whether or not this is considered idiomatic. Instead of this:<p><pre><code> type HelloResource struct {
sleepy.PostNotSupported
sleepy.PutNotSupported
sleepy.DeleteNotSupported
}
</code></pre>
Something like this:<p><pre><code> type HelloResource struct {
sleepy.DefaultResponder
}
</code></pre>
DefaultResponder is simply a struct which has all the methods of sleepy.PostNotSupported, sleepy.PutNotSupported, etc, and is defined:<p><pre><code> type DefaultResponder struct{}
func (DefaultResponder) Get(values url.Values) (int, interface{}) {
return 405, map[string]string{"error": "Not implemented"}
}
func (DefaultResponder) Post(values url.Values) (int, interface{}) {
return 405, map[string]string{"error": "Not implemented"}
}
func (DefaultResponder) Put(values url.Values) (int, interface{}) {
return 405, map[string]string{"error": "Not implemented"}
}
func (DefaultResponder) Delete(values url.Values) (int, interface{}) {
return 405, map[string]string{"error": "Not implemented"}
}
</code></pre>
Now, if you want to implement resource methods, you define them on the top-level struct, like so:<p><pre><code> type HelloResource struct {
sleepy.DefaultResponder
}
def (HelloResource) Get(values url.Values) (int, interface{}) {
data := map[string]string{"hello": "world"}
return 200, data
}
</code></pre>
So now, if you call Get on a HelloResource type, it uses the method defined on HelloResource, not the one defined on it's embedded DefaultResponder type. But if you call HelloResource.Post, it uses the method defined on DefaultResponder, i.e., it returns a 405 error. This is effectively like "overriding" in Java or other object oriented languages and saves a few lines when people are using your library.<p>What do you think? Again, I'm really just looking for feedback here as I too am new to go. Is this something that would be considered idiomatic, or is the original solution better?<p>(Apologies in advance for any typos or syntax errors. Didn't check this with a compiler, but hopefully you get the idea.)