In my go backend application I generated a token when my app is initialised.And I want to use this token as a global variable for further authentications.
type Token struct { Name string Value string RefreshValue string Expires time.Time}func main() { AppToken := GetToken() router := mux.NewRouter() router.HandleFunc("/employees", GetEmployeesHandler).Methods("GET")}func GetEmployeesHandler (w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) //here i want to pass token, here i validate token and check token is expired //check token function checks token is valid and if token //expired, check token updates AppToken. err := CheckToken(AppToken) if err != nil { return err } fmt.Fprintf(w, "API is up and running")}
My requirement is that whenever the token expires I want to refresh the token I also want to ensure the refresh token should be blocked when there is already a refresh token process that is taking place. Please help me.