Files
ent/entc/gen/template/context.tmpl
Ariel Mashraki cef32f1fb4 entc: add option to override codegen header
Summary:
Set the standard header ("Code generated by entc, DO NOT EDIT.") as default, and override it using option in graph.

No changes to graph except the `generate.go` file.

Reviewed By: idoshveki

Differential Revision: D16642348

fbshipit-source-id: d9fd1d2046e2fd96acbb100ef061fda75d99ce52
2019-08-04 05:12:33 -07:00

24 lines
523 B
Cheetah

{{ define "context" }}
{{ $pkg := base $.Config.Package }}
{{ template "header" $ }}
import (
"context"
)
type contextKey struct{}
// FromContext returns the Client stored in a context, or nil if there isn't one.
func FromContext(ctx context.Context) *Client {
c, _ := ctx.Value(contextKey{}).(*Client)
return c
}
// NewContext returns a new context with the given Client attached.
func NewContext(parent context.Context, c *Client) context.Context {
return context.WithValue(parent, contextKey{}, c)
}
{{ end }}