code.gitea.io/gitea@v1.22.3/services/context/context_template.go (about)

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