Skip to content

Commit 75243ad

Browse files
committed
Implement presence checks
New functions: - `envp` checks if env is defined - `filep` checks if file exists
1 parent 75d39d8 commit 75243ad

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

functions.go

+14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ var funcMap map[string]any
77
func init() {
88
funcMap = make(map[string]any)
99
funcMap["file"] = File
10+
funcMap["filep"] = Filep
1011
funcMap["env"] = Env
12+
funcMap["envp"] = Envp
1113
}
1214

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

24+
// Filep checks if a file exists
25+
func Filep(name string) bool {
26+
_, err := os.Stat(name)
27+
return err == nil
28+
}
29+
2230
// Env expands environment variables in a string
2331
func Env(text string) string {
2432
return os.ExpandEnv(text)
2533
}
34+
35+
// Envp checks if an environment variable is set
36+
func Envp(name string) bool {
37+
_, ok := os.LookupEnv(name)
38+
return ok
39+
}

0 commit comments

Comments
 (0)