Documentation
¶
Overview ¶
Package utils has all the utils required for hulak, including but not limited to CreateFilePath, CreateDir, CreateFiles, ListMatchingFiles, MergeMaps and more..
Index ¶
- Constants
- func ColorError(errMsg string, errs ...error) error
- func ConvertKeysToLowerCase(dict map[string]any) map[string]any
- func CopyEnvMap(original map[string]any) map[string]any
- func CreateDir(dirPath string) error
- func CreateFile(filePath string) error
- func CreatePath(filePath string) (string, error)
- func FileExists(path string) bool
- func FileNameWithoutExtension(path string) string
- func GetEnvFiles() ([]string, error)
- func ListFiles(dirPath string, options ...ListFilesOption) ([]string, error)
- func ListMatchingFiles(matchFile string, initialPath ...string) ([]string, error)
- func LookupValue(key string, data map[string]any) (any, error)
- func MarshalToJSON(value any) (any, error)
- func MergeMaps(main, sec map[string]string) map[string]string
- func PanicRedAndExit(msg string, args ...any)
- func ParseArrayKey(segment string) (bool, string, int)
- func PrintGreen(msg string)
- func PrintInfo(msg string)
- func PrintJSONColored(data []byte) error
- func PrintRed(msg string)
- func PrintWarning(msg string)
- func SanitizeDirPath(dirPath string) (string, error)
- type ListFilesOption
Constants ¶
const ( Red = "\033[91m" Green = "\033[92m" Yellow = "\033[93m" Grey = "\033[90m" ColorReset = "\033[0m" Blue = "\033[94m" )
Colors
const ( EnvironmentFolder = "env" EnvKey = "hulakEnv" DefaultEnvVal = "global" DefaultEnvFileSuffix = ".env" )
Environment
const ( UnResolvedVariable = "unresolved variable " EmptyVariables = "variable string can't be empty" IndexOutOfBounds = "array index out of bounds: " KeyNotFound = "key not found: " )
Errors message
const ( YAML = ".yaml" YML = ".yml" JSON = ".json" )
acceptable file patterns
const ( ResponseBase = "_response" ResponseFileSuffix = ".json" ResponseFileName = ResponseBase + ResponseFileSuffix )
response pattern for files saved
const ( JSONString = "string" JSONNumber = "number" JSONInt = "int" JSONBool = "bool" JSONNull = "null" )
JSON supported types
const ( DirPer fs.FileMode = 0755 FilePer fs.FileMode = 0644 )
Permissions for creating directory and files
const ( CheckMark = "\u2713" CrossMark = "\u2717" )
tick mark and x for success and failure
const ResponseType = "code"
ResponseType is Auth2.0 ResponseType
Variables ¶
This section is empty.
Functions ¶
func ColorError ¶
ColorError Creates an error message that optionally includes an additional error. If an error is provided, it formats the message with the error appended. The returned error is colored for console output.
func ConvertKeysToLowerCase ¶
ConvertKeysToLowerCase converts all keys in a map to lowercase recursively except "variables" as Graphql variables is case-sensitive
func CopyEnvMap ¶
CopyEnvMap Copies the Environment map[string]any and returns a map[string]string EnvMap is a simple JSON without any nested properties. Mostly used for goroutines.
func CreateDir ¶
CreateDir checks for the existence of a directory at the given path, and creates it with permissions 0755 if it does not exist.
func CreateFile ¶
CreateFile checks for the existence of a file at the given filePath, and creates it if it does not exist.
func CreatePath ¶
CreatePath creates and returns file or directory path by joining the project root with provided filePath
func FileExists ¶
FileExists checks if a file exists and is accessible at the given path Returns true if the file exists and is readable, false otherwise
func FileNameWithoutExtension ¶
FileNameWithoutExtension takes in filepath and returns the name of the file
func GetEnvFiles ¶
GetEnvFiles returns a list of environment file names from the env folder
func ListFiles ¶
func ListFiles(dirPath string, options ...ListFilesOption) ([]string, error)
ListFiles lists all .yaml, .yml, or .json files in a directory with configurable directory exclusion Files are added as they are discovered so it does not guarantee any files are run before the other
func ListMatchingFiles ¶
ListMatchingFiles searches for files matching the "matchFile" name (case-insensitive, .yaml/.yml or .json only) in the specified directory and its subdirectories. If no directory is specified, it starts from the project root. Includes all directories in traversal, including hidden ones. Returns slice of matched file paths and an error if no matching files are found or if there are file system errors.
func LookupValue ¶
LookupValue retrieves the value for a given key or path from the map. A key can be a simple string like "name", or a path like "user.name", where "user" is an object and "name" is a key inside it. Use {} to escape dots in keys (e.g., "{user.name}"). For arrays, reference an index with square brackets (e.g., myArr[0] for the first element). You can also access nested properties like myArr[0].name for the "name" key of the first array element.
func MarshalToJSON ¶
MarshalToJSON is basically JSON.stringify equivalent for go
func MergeMaps ¶
MergeMaps merges the secondary map into the main map. If keys are repeated, values from the secondary map replace those in the main map.
func PanicRedAndExit ¶
PanicRedAndExit Print message in Red and os.Exit(1)
func ParseArrayKey ¶
ParseArrayKey checks if array has proper syntax
func PrintJSONColored ¶ added in v0.1.3
PrintJSONColored Pretty-prints JSON using the fatih/color package
func SanitizeDirPath ¶
SanitizeDirPath cleans up the directory path to avoid traversals
Types ¶
type ListFilesOption ¶
type ListFilesOption func(*listFilesOptions)
ListFilesOption lists the options we should skip
func WithRespectDotDirs ¶
func WithRespectDotDirs(respect bool) ListFilesOption
WithRespectDotDirs controls whether to traverse dot directories
func WithSkipDirs ¶
func WithSkipDirs(dirs []string) ListFilesOption
WithSkipDirs specifies directories to skip