context.go 479 B

1234567891011121314151617181920
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. )
  6. type contextKey struct{}
  7. // FromContext returns the Client stored in a context, or nil if there isn't one.
  8. func FromContext(ctx context.Context) *Client {
  9. c, _ := ctx.Value(contextKey{}).(*Client)
  10. return c
  11. }
  12. // NewContext returns a new context with the given Client attached.
  13. func NewContext(parent context.Context, c *Client) context.Context {
  14. return context.WithValue(parent, contextKey{}, c)
  15. }