github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/context.go (about) 1 // Code generated by ent, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "context" 7 ) 8 9 type clientCtxKey struct{} 10 11 // FromContext returns a Client stored inside a context, or nil if there isn't one. 12 func FromContext(ctx context.Context) *Client { 13 c, _ := ctx.Value(clientCtxKey{}).(*Client) 14 return c 15 } 16 17 // NewContext returns a new context with the given Client attached. 18 func NewContext(parent context.Context, c *Client) context.Context { 19 return context.WithValue(parent, clientCtxKey{}, c) 20 } 21 22 type txCtxKey struct{} 23 24 // TxFromContext returns a Tx stored inside a context, or nil if there isn't one. 25 func TxFromContext(ctx context.Context) *Tx { 26 tx, _ := ctx.Value(txCtxKey{}).(*Tx) 27 return tx 28 } 29 30 // NewTxContext returns a new context with the given Tx attached. 31 func NewTxContext(parent context.Context, tx *Tx) context.Context { 32 return context.WithValue(parent, txCtxKey{}, tx) 33 }