util

package
v1.26.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPointer is returned when the provided pointer is invalid.
	ErrInvalidPointer = errors.New("invalid pointer provided")
	// ErrMalformedEnvVar is returned when an environment variable is malformed.
	ErrMalformedEnvVar = errors.New("malformed environment variable")
)

Functions

func ArgvToStrings

func ArgvToStrings(argv **c.Char) []string

ArgvToStrings converts a C-style NULL-terminated array of strings to a Go string slice. This function is used to convert OpenVPN plugin arguments passed from C to Go.

Parameters:

  • argv: Pointer to a NULL-terminated array of C strings

Returns:

  • []string: A slice containing the converted strings, or nil if argv is nil

Types

type List

type List map[string]string

func NewEnvList

func NewEnvList(envVarsChar **c.Char) (List, error)

NewEnvList converts a NULL-terminated C string array of environment variables into a Go map.

The function expects environment variables in the standard "KEY=value" format, where:

  • Each string in the array should contain exactly one '=' character
  • The key (before '=') is trimmed of leading/trailing whitespace
  • The value (after '=') is preserved as-is, including any whitespace or additional '=' characters
  • Empty strings in the array are silently skipped

Example input:

["PATH=/usr/bin:/bin", "USER=testuser", "HOME=/home/user", NULL]

Returns a map:

{"PATH": "/usr/bin:/bin", "USER": "testuser", "HOME": "/home/user"}

Parameters:

  • envVarsChar: A pointer to a NULL-terminated array of C strings, where each string represents an environment variable in KEY=value format

Returns:

  • List: A map containing the parsed environment variables
  • error: An error if the pointer is nil (ErrInvalidPointer) or if any variable is malformed (ErrMalformedEnvVar)

Errors:

  • ErrInvalidPointer: returned when envVarsChar is nil
  • ErrMalformedEnvVar: returned when a variable is missing '=' or has an empty key

Note: If duplicate keys are present (after trimming whitespace), the last occurrence wins.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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