import ( "github.com/gogits/gogs/modules/middleware" "net/http" ) func CustomContextParamHandler(w http.ResponseWriter, r *http.Request) { // Set a custom context parameter middleware.ContextSet(r, "my_param", "123") // Call next middleware/handler in the chain // ... }
import ( "github.com/gogits/gogs/modules/middleware" "net/http" ) func CustomHandler(w http.ResponseWriter, r *http.Request) { // Retrieve a context parameter myParam := middleware.ContextGet(r, "my_param").(string) // Use the retrieved context parameter // ... }This code example shows how to retrieve a context parameter previously set in the request context using the "ContextGet" function of the "middleware" package. The value retrieved is type-asserted to a string before use. Overall, the "Context Params" middleware module of the "gogits/gogs" package library provides a simple yet powerful way to handle context parameters in HTTP requests and responses in Go applications.