...

Source file src/github.com/redhat-developer/odo/pkg/config/context/context.go

Documentation: github.com/redhat-developer/odo/pkg/config/context

     1  package context
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/redhat-developer/odo/pkg/config"
     7  )
     8  
     9  type contextKey struct{}
    10  
    11  var key = contextKey{}
    12  
    13  // WithEnvConfig sets the environment configuration in ctx
    14  func WithEnvConfig(ctx context.Context, val config.Configuration) context.Context {
    15  	return context.WithValue(ctx, key, val)
    16  }
    17  
    18  // GetEnvConfig returns the environment configuration from ctx
    19  func GetEnvConfig(ctx context.Context) config.Configuration {
    20  	value := ctx.Value(key)
    21  	if cast, ok := value.(config.Configuration); ok {
    22  		return cast
    23  	}
    24  	panic("GetEnvConfig can be called only after WithEnvConfig has been called")
    25  }
    26  

View as plain text