envvars

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 5 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToContainers

func AddToContainers(ctr *dagger.Container, envVars []types.DaggerEnvVars) *dagger.Container

AddToContainers adds a list of environment variables to a Dagger container.

Parameters:

  • ctr: A pointer to the Dagger container to which the environment variables will be added.
  • envVars: A slice of DaggerEnvVars, each containing the name, value, and expansion option for an environment variable.

Returns:

  • A pointer to the Dagger container with the added environment variables.

Example:

// Create a new Dagger container
ctr := dagger.NewContainer()

// Define environment variables
envVars := []types.DaggerEnvVars{
    {Name: "VAR1", Value: "value1", Expand: false},
    {Name: "VAR2", Value: "value2", Expand: true},
}

// Add environment variables to the container
updatedCtr := AddToContainers(ctr, envVars)

// Now, updatedCtr has the environment variables VAR1 and VAR2

func ToDaggerEnvVarsFromMap

func ToDaggerEnvVarsFromMap(envVarsMap map[string]string) ([]types.DaggerEnvVars, error)

ToDaggerEnvVarsFromMap converts a map of environment variables into a slice of DaggerEnvVars. It ensures all entries are valid and handles empty maps gracefully.

Parameters:

  • envVarsMap: A map of environment variables where each key is a variable name and each value is the corresponding value.

Returns:

  • A slice of DaggerEnvVars, each containing the name and value of an environment variable.
  • An error if the input map is empty or contains an empty key.

Example:

envVarsMap := map[string]string{"FOO": "bar", "BAZ": "qux"}
envVarsSlice, err := ToDaggerEnvVarsFromMap(envVarsMap)
if err != nil {
    // handle error
}
// Use envVarsSlice, e.g., fmt.Println(envVarsSlice)

func ToDaggerEnvVarsFromSlice

func ToDaggerEnvVarsFromSlice(envVarsSlice []string) ([]types.DaggerEnvVars, error)

ToDaggerEnvVarsFromSlice converts a slice of key=value strings into a slice of DaggerEnvVars. It validates each entry and skips invalid entries.

Parameters:

  • envVarsSlice: A slice of strings where each string is a key=value pair representing an environment variable.

Returns:

  • A slice of DaggerEnvVars, each containing the name and value of an environment variable.
  • An error if the input slice is empty or if any of the key=value pairs are invalid.

Example:

envVarsSlice := []string{"FOO=bar", "BAZ=qux"}
envVars, err := ToDaggerEnvVarsFromSlice(envVarsSlice)
if err != nil {
    // handle error
}
// Use envVars, e.g., fmt.Println(envVars)

func ToDaggerEnvVarsFromStr

func ToDaggerEnvVarsFromStr(envVars string) (map[string]string, error)

ToDaggerEnvVarsFromStr converts a comma-separated string of key=value pairs into a map. It ensures all entries are valid and handles empty strings gracefully.

Parameters:

  • envVars: A comma-separated string of key=value pairs. For example: "key1=value1,key2=value2,key3=value3".

Returns:

  • A map of strings where each key is an environment variable name and each value is the corresponding value.
  • An error if the input string is empty or if any of the key=value pairs are invalid.

Example:

envVarsStr := "FOO=bar,BAZ=qux"
envVarsMap, err := ToDaggerEnvVarsFromStr(envVarsStr)
if err != nil {
    // handle error
}
// Use envVarsMap, e.g., fmt.Println(envVarsMap["FOO"]) // Output: bar

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL