utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFileNotFound indicates the .hcl file was not found in the expected locations.
	ErrFileNotFound = fmt.Errorf("could not find .hcl file")

	// ErrParseFailed indicates a failure in parsing the .hcl file content.
	ErrParseFailed = fmt.Errorf("could not parse .hcl file")
)

Predefined errors for file operations.

View Source
var (
	// ErrFindUpwards is returned when the target directory is not found.
	ErrFindUpwards = fmt.Errorf("target directory not found")
)

Predefined errors for file operations.

Functions

func ComputeRelativePath

func ComputeRelativePath(basePath, targetPath string) (string, error)

ComputeRelativePath computes the relative path from base to target. It returns the relative path as a string and any error encountered.

func FindFileInParent

func FindFileInParent(fileName string) (string, error)

func FindFileInParentTarget

func FindFileInParentTarget(parentFolder, targetFolder, fileName string) (string, error)

FindFileInParentTarget searches a file in a parent target folder.

func Get

func Get(h HCL, key string) (string, bool)

Get retrieves the value associated with a given key, supporting nested keys.

func WrapError

func WrapError(customErr, originalErr error) error

Types

type HCL

type HCL struct {
	KeyValues map[string]interface{}
}

func GetHCLFromParent

func GetHCLFromParent(name string) (HCL, error)

GetHCLFromParent retrieves the configuration from an HCL file located within the project directory or any parent directory. The function searches for a file with the provided name appended with ".hcl". It wraps and returns any error encountered during the file search or parsing process, with additional context.

func NewHCL

func NewHCL(keyValues map[string]interface{}) HCL

NewHCL creates a new instance of HCL with the provided key-values.

func ParseHCL

func ParseHCL(path string) (HCL, error)

ParseHCL attempts to parse an HCL file at the given path into an HCL instance.

Jump to

Keyboard shortcuts

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