resolver

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

GoPackage resolver provides helper functions to resolve values by prioritizing CLI-provided values over configuration-defined values, ensuring proper validation and error handling when necessary

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveBool

func ResolveBool(cliValue, configValue bool) bool

ResolveBool determines the final boolean value by preferring the CLI flag over the configuration value.

Parameters:

  • cliValue: The boolean value provided via CLI flag (if any).
  • configValue: The boolean value from the configuration file.

Returns:

  • The resolved boolean value, defaulting to configValue if cliValue is false.

func ResolveInt

func ResolveInt(cliValue string, configValue int, fieldName string) (int, error)

ResolveInt determines the final integer value by prioritizing the CLI flag over the configuration value. If both values are zero, it returns an error indicating that the field is required.

Parameters:

  • cliValue: The value provided via CLI flag (if any).
  • configValue: The integer value from the configuration file.
  • fieldName: The name of the field being resolved (used for error messages).

Returns:

  • The resolved integer value (either cliValue or configValue).
  • An error if both values are zero, indicating that the field is required.

func ResolveString

func ResolveString(cliValue, configValue, fieldName, defaultValue string, allowedValues []string) (string, error)

ResolveString determines the final string value by prioritizing the CLI flag over the configuration value. It validates the resolved value against allowed options and falls back to a default if necessary.

If both the CLI and configuration values are empty, an error is returned, indicating that the field is required. If an invalid value is provided, the default value is silently returned.

Parameters:

  • cliValue: The value provided via CLI flag (if any).
  • configValue: The value from the configuration file (if any).
  • fieldName: The name of the field being resolved (used for error messages).
  • defaultValue: The fallback value if neither cliValue nor configValue are valid.
  • allowedValues: A list of permitted values for validation.

Returns:

  • The resolved string value (cliValue, configValue, or defaultValue).
  • An error if both values are empty or an invalid value is provided.

Types

This section is empty.

Jump to

Keyboard shortcuts

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