You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

context_template.go 739B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package context
  4. import (
  5. "context"
  6. "time"
  7. )
  8. var _ context.Context = TemplateContext(nil)
  9. func NewTemplateContext(ctx context.Context) TemplateContext {
  10. return TemplateContext{"_ctx": ctx}
  11. }
  12. func (c TemplateContext) parentContext() context.Context {
  13. return c["_ctx"].(context.Context)
  14. }
  15. func (c TemplateContext) Deadline() (deadline time.Time, ok bool) {
  16. return c.parentContext().Deadline()
  17. }
  18. func (c TemplateContext) Done() <-chan struct{} {
  19. return c.parentContext().Done()
  20. }
  21. func (c TemplateContext) Err() error {
  22. return c.parentContext().Err()
  23. }
  24. func (c TemplateContext) Value(key any) any {
  25. return c.parentContext().Value(key)
  26. }