func Logger(ctx *middleware.Context) { log.Printf("%s %s", ctx.Req.Method, ctx.Req.URL.Path) ctx.Next() }
func Auth(ctx *middleware.Context) { sessionID := ctx.GetCookie("session_id") if sessionID == "" { ctx.Redirect("/login", 302) return } user, err := db.GetUserBySession(sessionID) if err != nil { ctx.Redirect("/login", 302) return } ctx.User = user ctx.Next() }This middleware function checks if the user has a valid session cookie and redirects them to the login page if they do not. If the user is logged in, it sets the `User` property of the context object to the logged in user, which can be used by later middleware functions or application code. Overall, the Gogs Context Handle package is a powerful tool for managing middleware and sharing data between middleware functions in your Gogs application.