Context.Context, Dependencies and Avoiding Package Globals

I really appreciate the well thought out response.

I’ll stick to your suggestion and use an application specific context and function parameters. It was I was doing before… then I saw something about using context somewhere and thought that this was an interesting use case. I’m glad I asked before I committed to it in my current project.

The onion layers of http handlers always seems to pop into my apps because 9/10 times there is a bunch of stuff that I want to run on every request. Mostly things like figuring out if the user is authenticated, grab the user from the db, load their preferences… the application specific boring stuff that most handlers and view need access to. I’ll play around with trying to remove that layer and see how things turn out.

Thanks

1 Like