func MyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) { // Do something here... if ctx.HasError() { // Handle error here... } // Continue processing request... }
func WithDB(db *sql.DB) func(ctx context.Context, w http.ResponseWriter, r *http.Request) { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) { // Modify the request context here... ctx.Set("db", db) // Continue processing request... } }In this example, the middleware function adds a `db` object to the request context, allowing downstream handlers to access it as needed. Overall, the `context` package in Gogs is a useful tool for managing request context in HTTP applications.