Re:A RESTful Micro-Framework in Go
by optymizer1 on Monday January 27, 2014 @07:36AM
(#7129987)
You could even go further and assume all user resources are logical extensions of sleepy.Resource:
type HelloResource struct {
sleepy.Resource
}
This makes it clear that you're inheriting everything from sleepy.Resource, so you can provide reasonable implementations for all methods of resources, not just HTTP methods handlers, e.g. getBodyAsJSON(), redirect(resource), etc.Also, depending on how your mux works, you could store app-level data in sleepy.Resource, to be accessed by all resources:
sleepy.Resource.DB
sleepy.Resource.Session
sleepy.Resource.Root
and other things I can't think of right now.
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?
(Apologies in advance for any typos or syntax errors. Didn't check this with a compiler, but hopefully you get the idea.)