Documentation
¶
Overview ¶
Package filex provides utility functions for working with files and directories, including validation of file extensions, existence, content, and structure. It offers functions to check if a file has a valid YAML extension, if it exists, if it has content, and if it can be properly unmarshaled into a provided struct.
The package includes the following main functions:
- ValidateYAMLExtension(filename string) bool: Checks if the given file has a .yaml or .yml extension.
- ValidateYAMLExists(filename string) bool: Checks if the given YAML file exists.
- ValidateYAMLHasContent(filename string) (bool, error): Checks if the given YAML file is not empty and returns a boolean indicating whether the file has content and an error if any occurred during reading the file.
- ValidateYAMLStructure(filename string, out interface{}) error: Checks if the given YAML file can be properly unmarshaled into the provided struct.
- ValidateYAML(filename string, out interface{}) error:
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateYAML ¶
ValidateYAML performs all YAML validations: extension, existence, content, and structure. It returns an error if any of the validations fail.
Example usage:
var config Config
err := ValidateYAML("config.yaml", &config)
if err != nil {
log.Fatal(err)
}
func ValidateYAMLExists ¶
ValidateYAMLExists checks if the given YAML file exists. It returns true if the file exists, otherwise false.
Example usage:
exists := ValidateYAMLExists("config.yaml")
fmt.Println(exists) // Output: true
func ValidateYAMLExtension ¶
ValidateYAMLExtension checks if the given file has a .yaml or .yml extension. It returns true if the file has a valid YAML extension, otherwise false.
Example usage:
valid := ValidateYAMLExtension("config.yaml")
fmt.Println(valid) // Output: true
func ValidateYAMLHasContent ¶
ValidateYAMLHasContent checks if the given YAML file is not empty. It returns a boolean indicating whether the file has content and an error if any occurred during reading the file.
Example usage:
hasContent, err := ValidateYAMLHasContent("config.yaml")
if err != nil {
log.Fatal(err)
}
fmt.Println(hasContent) // Output: true
func ValidateYAMLStructure ¶
ValidateYAMLStructure checks if the given YAML file can be properly unmarshaled into the provided struct. It returns an error if the file cannot be read or if the content cannot be unmarshaled into the provided struct.
Example usage:
var config Config
err := ValidateYAMLStructure("config.yaml", &config)
if err != nil {
log.Fatal(err)
}
Types ¶
This section is empty.