I want pass a context with some data from one request to another.
I’ve read the echo framework docs regarding contexts, but its not clear to me.
So far I set a new value in echo.Context.Set(“key”). When I tried to call it
in a different request, the context key was null. What am I missing to be able to pass that data from the original request to the other request?
echo.Context represents the context of the current HTTP request. It holds request and response reference, path, path parameters, data, registered handler and APIs to read request and write response.
A context is always specific to a single HTTP-Request. If you want to share data between different requests you will have to use some synchronized data sharing.
Depending on your use case you should probably use go channels, a concurrent map, a Mutexed Global variable or atomics.
To give more detail, I want to store a user’s email after they login
so it can be used in a different request method.
Based on what you said what would be simplest to implement?
If I understand correctly you want to create a session for your user and store data for all requests by the same user.
This is usually handled via cookies, since your server cannot easily know which requests come from the same user. Since multiple users might share an IP address and a single user might even change IP address on the go (changing from mobile data to a WiFi network)
You can search for the keywords server side user session management.