How to share data between middleware when using the middleware function of gorilla/mux

package main

import (
    "net/http"

    "github.com/gorilla/mux"
)

func main() {
    r := mux.NewRouter()
    
    r.Use(middleware1)
    r.Use(middleware2)
    
    r.HandleFunc("/user", getUser)
}

now I need to do some processing on token in middleware1, and then save the result and provide it to subsequent middleware. Where can I save it, or do I need to implement it in some other way?

Mar.09,2021

http.Request Context can be used to share data between middleware.


gorilla also has a package dedicated to context sharing data

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9573e-47313.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9573e-47313.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?