using new line as split token for data from file

This commit is contained in:
mzack 2021-08-23 01:22:56 +02:00
parent 7a59d6702b
commit 6804cda5e4
2 changed files with 4 additions and 4 deletions

View File

@ -12,7 +12,7 @@ func (c *CustomList) String() string {
// Set a new global header
func (c *CustomList) Set(value string) error {
values := fileutil.LoadCidrsFromSliceOrFile(value)
values := fileutil.LoadCidrsFromSliceOrFile(value, ",")
*c = append(*c, values...)
return nil
}

View File

@ -76,8 +76,8 @@ func FileNameIsGlob(pattern string) bool {
return err == nil
}
func LoadCidrsFromSliceOrFile(option string) (networkList []string) {
items := stringz.SplitByCharAndTrimSpace(option, ",")
func LoadCidrsFromSliceOrFile(option string, splitchar string) (networkList []string) {
items := stringz.SplitByCharAndTrimSpace(option, splitchar)
for _, item := range items {
// ip
if net.ParseIP(item) != nil {
@ -86,7 +86,7 @@ func LoadCidrsFromSliceOrFile(option string) (networkList []string) {
networkList = append(networkList, item)
} else if fileutil.FileExists(item) {
if filedata, err := ioutil.ReadFile(item); err == nil && len(filedata) > 0 {
networkList = append(networkList, LoadCidrsFromSliceOrFile(string(filedata))...)
networkList = append(networkList, LoadCidrsFromSliceOrFile(string(filedata), "\n")...)
}
}
}