envvars

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 4 Imported by: 14

Documentation

Overview

Package envvars provides utilities for converting environment variables between different formats. This package is designed to facilitate the handling of environment variables in Go applications, ensuring that they can be easily converted from strings, maps, and other common data structures into a standardized format.

The primary focus of this package is to provide functions that convert environment variables into slices of DaggerEnvVars, a custom type defined in the types package. These functions ensure that the environment variables are valid and handle edge cases such as empty strings or maps gracefully.

Key Functions:

  • ToDaggerEnvVarsFromStr: Converts a comma-separated string of key=value pairs into a slice of DaggerEnvVars.

  • ToDaggerEnvVarsFromMap: Converts a map of environment variables into a slice of DaggerEnvVars.

Example Usage:

Converting a comma-separated string of environment variables:

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

Converting a map of environment variables:

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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) ([]types.DaggerEnvVars, error)

ToDaggerEnvVarsFromStr converts a comma-separated string of key=value pairs into a slice of DaggerEnvVars. 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 slice of DaggerEnvVars, each containing the name and value of an environment variable.
  • An error if the input string is empty or if any of the key=value pairs are invalid.

Example:

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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