mirror of
https://github.com/onyx-and-iris/gogn.git
synced 2026-04-16 14:23:35 +00:00
initial commit
This commit is contained in:
22
context.go
Normal file
22
context.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cuonglm/gogi"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
var clientKey = contextKey("client")
|
||||
|
||||
// WithClient adds a gogi HTTP client to the context.
|
||||
func WithClient(ctx context.Context, client *gogi.Client) context.Context {
|
||||
return context.WithValue(ctx, clientKey, client)
|
||||
}
|
||||
|
||||
// ClientFromContext retrieves the gogi client from the context.
|
||||
func ClientFromContext(ctx context.Context) (*gogi.Client, bool) {
|
||||
client, ok := ctx.Value(clientKey).(*gogi.Client)
|
||||
return client, ok
|
||||
}
|
||||
Reference in New Issue
Block a user