github.com/hashicorp/go-getter/v2@v2.2.2/client_option.go (about)

     1  package getter
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  type clientContextKey int
     8  
     9  const clientContextValue clientContextKey = 0
    10  
    11  func NewContextWithClient(ctx context.Context, client *Client) context.Context {
    12  	return context.WithValue(ctx, clientContextValue, client)
    13  }
    14  
    15  func ClientFromContext(ctx context.Context) *Client {
    16  	// ctx.Value returns nil if ctx has no value for the key;
    17  	client, ok := ctx.Value(clientContextValue).(*Client)
    18  	if !ok {
    19  		return nil
    20  	}
    21  	return client
    22  }
    23  
    24  // configure configures a client with options.
    25  func (c *Client) configure() error {
    26  	// Default decompressor values
    27  	if c.Decompressors == nil {
    28  		c.Decompressors = Decompressors
    29  	}
    30  	// Default getter values
    31  	if c.Getters == nil {
    32  		c.Getters = Getters
    33  	}
    34  	return nil
    35  }