github.com/blend/go-sdk@v1.20220411.3/env/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 env
     9  
    10  import (
    11  	"context"
    12  )
    13  
    14  type varsKey struct{}
    15  
    16  // WithVars adds environment variables to a context.
    17  func WithVars(ctx context.Context, vars Vars) context.Context {
    18  	return context.WithValue(ctx, varsKey{}, vars)
    19  }
    20  
    21  // GetVars gets environment variables from a context.
    22  func GetVars(ctx context.Context) Vars {
    23  	if raw := ctx.Value(varsKey{}); raw != nil {
    24  		if typed, ok := raw.(Vars); ok {
    25  			return typed
    26  		}
    27  	}
    28  	return Env()
    29  }