Files
ent/examples/start/ent/context.go
Ariel Mashraki 6d159024e7 ent/doc: fix getting started example and add link to Github
Reviewed By: alexsn

Differential Revision: D17734937

fbshipit-source-id: abced88c23b7385d371361c5069292de5c1c5b1e
2019-10-03 01:40:58 -07:00

25 lines
699 B
Go

// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
// 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)
}