mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
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
24 lines
523 B
Cheetah
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 }}
|