Skip to content

Commit

Permalink
Implement presence checks
Browse files Browse the repository at this point in the history
New functions:
- `envp` checks if env is defined
- `filep` checks if file exists
  • Loading branch information
VOID404 committed Sep 11, 2024
1 parent 75d39d8 commit 75243ad
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ var funcMap map[string]any
func init() {
funcMap = make(map[string]any)
funcMap["file"] = File
funcMap["filep"] = Filep
funcMap["env"] = Env
funcMap["envp"] = Envp
}

// File reads a file and returns its content as a string
Expand All @@ -19,7 +21,19 @@ func File(name string) string {
return string(data)
}

// Filep checks if a file exists
func Filep(name string) bool {
_, err := os.Stat(name)
return err == nil
}

// Env expands environment variables in a string
func Env(text string) string {
return os.ExpandEnv(text)
}

// Envp checks if an environment variable is set
func Envp(name string) bool {
_, ok := os.LookupEnv(name)
return ok
}

0 comments on commit 75243ad

Please sign in to comment.