bxcodec / go-clean-arch

Go (Golang) Clean Architecture based on Reading Uncle Bob's Clean Architecture
MIT License
9.06k stars 1.19k forks source link

Why are you passing context to all layers? #10

Closed locona closed 6 years ago

locona commented 6 years ago

Hi!

I am composing it with reference to this repository in my project and I am very grateful!

Why did you pass context to all layers with the following changes? feat: add context #9

bxcodec commented 6 years ago

Hello @locona

When you working in production, context maybe useful. Let say in your usecase, there so many concurent / go routine running. You can use context to handle the cancelation, timeout or just passing value.
As quoted from this blog post: https://blog.golang.org/context

At Google, we require that Go programmers pass a Context parameter as the 
first argument to every function on the call path between incoming and outgoing requests.
This allows Go code developed by many different teams to interoperate well. 
It provides simple control over timeouts and cancelation and ensures that 
critical values like security credentials transit Go programs properly.

In google, they required the Context parameter as the first argument. So in larger projects, that may have so many programmer in one projects, every programmer will able to use the context based on their needs.

locona commented 6 years ago

Thank you! I will follow this also in my project!