func myFunction(ctx context.Context) { value := ctx.Value("mykey") // Do something with the value }
func myFunction(ctx context.Context) { newCtx := context.WithValue(ctx, "mykey", "myvalue") // Pass the new context object to another function }
func myFunction(ctx context.Context) { // Check if the context has been cancelled select { case <-ctx.Done(): // The context has been cancelled return default: // Continue with the function } }This example shows how to check if a context has been cancelled by using the Done() method. If the context has been cancelled, the function returns immediately. The package library for this Context package is github.com/go-gitea/gitea/modules/context. It is specifically designed for use within the Gitea Git hosting platform.