cannot store *app.RequestContext to package scope variable
Closed this issue · 6 comments
(in i18n.go) atl18n is a package scope variable, while app.RequestContext only valid in the request lifetime, it will be freed when request end. after that, call the GetMessage API may cause memory use after released.
func Localize(opts ...Option) app.HandlerFunc {
newI18n(opts...)
return func(c context.Context, ctx *app.RequestContext) {
atI18n.setCurrentContext(c, ctx)
}
}
May I ask if you are having problems with the above mentioned situation? If so, please provide me with a copy of the code used to reproduce it so that I can solve your problem.
Hertz's app.RequestContext is not thread-safe and does not currently support direct asynchronous use.
May I ask if you are having problems with the above mentioned situation? If so, please provide me with a copy of the code used to reproduce it so that I can solve your problem.
I think you can refer to the implementation method of this library : gin-contrib/i18n and use the context.Context as a parameter to the MustGetMessage method instead of store any Context in the package scope variable atl18n
May I ask if you are having problems with the above mentioned situation? If so, please provide me with a copy of the code used to reproduce it so that I can solve your problem.
I think you can refer to the implementation method of this library : gin-contrib/i18n and use the context.Context as a parameter to the MustGetMessage method instead of store any Context in the package scope variable atl18n
gin.Context will also be recycled and We'll optimise it.
Can I ask if this is an issue you are experiencing in your production environment or? This will determine the priority of refinement.