mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
adding ent client context load/store support
Summary: Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1148 Reviewed By: a8m Differential Revision: D16202464 fbshipit-source-id: 15174e19e5e514774928e4e682d1c2743e863a26
This commit is contained in:
committed by
Facebook Github Bot
parent
f46c8f8848
commit
ad051e6d72
20
entc/integration/ent/context.go
Normal file
20
entc/integration/ent/context.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// Code generated (@generated) by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user