github.com/blend/go-sdk@v1.20220411.3/vault/context.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package vault 9 10 import ( 11 "context" 12 ) 13 14 type clientKey struct{} 15 16 // WithClient sets the vault client on a given context. 17 func WithClient(ctx context.Context, client Client) context.Context { 18 return context.WithValue(ctx, clientKey{}, client) 19 } 20 21 // GetClient gets a vault client on a context. 22 func GetClient(ctx context.Context) Client { 23 if value := ctx.Value(clientKey{}); value != nil { 24 if typed, ok := value.(Client); ok { 25 return typed 26 } 27 } 28 return nil 29 }