-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using echo.AcquireContext
#2698
base: master
Are you sure you want to change the base?
Conversation
echo.go
Outdated
@@ -633,8 +633,8 @@ func (e *Echo) Routes() []*Route { | |||
|
|||
// AcquireContext returns an empty `Context` instance from the pool. | |||
// You must return the context by calling `ReleaseContext()`. | |||
func (e *Echo) AcquireContext() Context { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a API breaking change. Echo core tries to adhere to semantic versioning and doing major version bump for this is a little to much to ask.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q. What is the difference between returning interface
and pointer -> struct
?
or changing as below is destructive?
func (e *Echo) AcquireContext() Context {
return e.pool.Get().(Context)
}
func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Acquire context
- c := e.pool.Get().(*context)
+ c := e.AcquireContext().(*context)
....
// Release context
- e.pool.Put(c)
+ e.ReleaseContext(c)
}
Or It means "Changes" too small to increase version, dosen't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can assign *echo.context
to echo.Context
because that struct satisfies that interface. but AcquireContext
is a public method than anyone can use and now changing it would/could make their code do not compile anymore because you can not assign other structs (like you own custom context implementation) to that struct (*echo.context
)
c := e.AcquireContext()
e.ReleaseContext(c)
c = new(MyCustomContext) // Cannot use 'new(MyCustomContext)' (type *MyCustomContext) as the type *context
Yes, this is hypotetical but it still breaks library user code, it does not compile even anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I understand it well. Thank you very much.
I changed not to affect public method.
CHANGE
use method,
echo.AcqurireContext
which defined.