-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for properties file
- Loading branch information
1 parent
437f081
commit eec3b8a
Showing
4 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# check.disabled.http=true | ||
# check.disabled.dns=true | ||
# check.disabled.s3=true | ||
|
||
# check.disabled.tcp=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package utils | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"strings" | ||
|
||
"github.com/flanksource/commons/logger" | ||
) | ||
|
||
type Properties map[string]string | ||
|
||
func ParsePropertiesFile(filename string) (Properties, error) { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer file.Close() | ||
|
||
props := Properties{} | ||
scanner := bufio.NewScanner(file) | ||
for scanner.Scan() { | ||
line := strings.TrimSpace(scanner.Text()) | ||
if strings.TrimSpace(line) == "" || strings.HasPrefix(line, "#") { | ||
continue | ||
} | ||
|
||
tokens := strings.SplitN(line, "=", 2) | ||
if len(tokens) != 2 { | ||
logger.Warnf("invalid line: %s", line) | ||
continue | ||
} | ||
|
||
key := strings.TrimSpace(tokens[0]) | ||
value := strings.TrimSpace(tokens[1]) | ||
props[key] = value | ||
} | ||
|
||
if scanner.Err() != nil { | ||
return nil, scanner.Err() | ||
} | ||
|
||
return props, nil | ||
} |