Skip to content
Discussion options

You must be logged in to vote

I found the github.com/timandy/routine and can do

package ctx
import "github.com/timandy/routine"

var threadLocal = routine.NewThreadLocal[echo.Context]()

func Get() echo.Context {
	return threadLocal.Get()
}
func Set(val echo.Context) {
	threadLocal.Set(val)
}
func Remove() {
	threadLocal.Remove()
}

Middleware

func ThreadLocal() echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(c echo.Context) error {
			ctx.Set(c)
			var resp = next(c)
			ctx.Remove()
			return resp
		}
	}
}

Anywhere

ctx.Get()

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@seepine
Comment options

Answer selected by seepine
@aldas
Comment options

@seepine
Comment options

@aldas
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants