context.go 878 B

123456789101112131415161718192021222324252627282930313233
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. )
  6. type clientCtxKey struct{}
  7. // FromContext returns a Client stored inside a context, or nil if there isn't one.
  8. func FromContext(ctx context.Context) *Client {
  9. c, _ := ctx.Value(clientCtxKey{}).(*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, clientCtxKey{}, c)
  15. }
  16. type txCtxKey struct{}
  17. // TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
  18. func TxFromContext(ctx context.Context) *Tx {
  19. tx, _ := ctx.Value(txCtxKey{}).(*Tx)
  20. return tx
  21. }
  22. // NewTxContext returns a new context with the given Tx attached.
  23. func NewTxContext(parent context.Context, tx *Tx) context.Context {
  24. return context.WithValue(parent, txCtxKey{}, tx)
  25. }