Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

poteto0
Copy link

@poteto0 poteto0 commented Nov 7, 2024

CHANGE

use method, echo.AcqurireContext which defined.

-func (e *Echo) AcquireContext() Context {
-	return e.pool.Get().(Context)
+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()
        ....
        // Release context
-	e.pool.Put(c)
+	e.ReleaseContext(c)
}

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 {
Copy link
Contributor

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.

Copy link
Author

@poteto0 poteto0 Nov 7, 2024

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?

Copy link
Contributor

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

Copy link
Author

@poteto0 poteto0 Nov 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants