I think we agree that it makes no sense for a controller to have any
state (especially on GAE).
I was thinking more along the lines of saving memory in the first
place. Imagine a complex website with 1,000 controllers... one
request comes in for ONE of the controllers. GAE kicks up the code,
and (due to Goweb requiring you map instances to routes) it creates
1,000 instances - just to serve one request.
It would be better if Goweb could ask a Factory for an instance (from
a given Type) and if the Factory has one, it returns it - or else it
creates an instance and caches it. This way, it will only use memory
it needs.
Mat
On Oct 21, 3:44 pm, Chris Farmiloe <
chrisfa...@gmail.com> wrote:
> If I understand you, I think you are talking about an issue I hit recently
> when running with GOMAXPROCS=4;
>
> Currently there is one global instance of a RestController used to serve all
> requests.
>
> So if you use variables on your controller type, you could be sharing memory
> between concurrent requests.
>
> type MyController struct {
> myVar string
>
> }
>
> func (me *MyController).Read(cx *Context, id string) {
> // set controller var
> me.myVar = cx.PathParams["value"]
> // call some blocking func that halts goroutine
> call.SomeBlockingFunc()
> // now we cannot trust myVar
> myVar == cx.PathParams["value"] // maybe or maybe not true!
>
> }
>
> This could be solved by just coping the RestController (or Resource in the
> case of my exp-resources experiment) instance before calling the handler
> func.
>
> Chris
>