Design question: Your various application services..
coquizen opened this issue · comments
... have methods that takes in echo.Context
as one of its parameters:
Line 12 in af20bef
Line 17 in af20bef
gorsk/pkg/api/password/password.go
Line 16 in af20bef
I noticed the same trend in gorsk-gin:
here
among others..
Why do you have it as a parameter if it is never used within the methods? Is its inclusion a placeholder for edge use cases?
Thanks for publishing this code. I find it immensely useful to think about how to go about structuring API in Go.
You'll notice that in Go in general, context.Context
is passed as first argument nearly everywhere.
This is used for cancellations, timeouts and passing values via context.WithValue
/ ctx.Value
. An example is storing user information inside context within middleware, and then pulling it wherever need. Or storing an instance of logger.
Unfortunately echo uses a custom context for this (and other purposes), thus it was mostly unused.
These days I write my APIs using gorilla/mux
all the time.
So echo.Context doesn't implement context.Context interfaces I take it?
Thanks for posting this example.. Not only helped me understand DDD but finally I grokked the purpose and use of Go's interfaces..