func ExampleMiddleware(ctx *middleware.Context) { // Get transactional context value value := ctx.GetTrValue("key") // Set transactional context value ctx.SetTrValue("key", "value") }
func ExampleMiddleware2(ctx *middleware.Context) { // Set error message in context ctx.SetTrErrorMessage("Error Message") // Abort request ctx.Error(500, "Internal Server Error") }In these examples, we can see how the Context middleware package is used to set and retrieve transactional context, as well as handle errors. The package belongs to the Gogs library, which is a self-hosted Git service written in Go.