fix review
This commit is contained in:
parent
f699e559e9
commit
451649e915
1 changed files with 3 additions and 6 deletions
|
@ -32,7 +32,6 @@ func EndsWith(s string, suff string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetExprEnv(ctx map[string]interface{}) map[string]interface{} {
|
func GetExprEnv(ctx map[string]interface{}) map[string]interface{} {
|
||||||
|
|
||||||
var ExprLib = map[string]interface{}{"Atof": Atof, "JsonExtract": JsonExtract, "JsonExtractLib": JsonExtractLib, "File": File, "RegexpInFile": RegexpInFile}
|
var ExprLib = map[string]interface{}{"Atof": Atof, "JsonExtract": JsonExtract, "JsonExtractLib": JsonExtractLib, "File": File, "RegexpInFile": RegexpInFile}
|
||||||
for k, v := range ctx {
|
for k, v := range ctx {
|
||||||
ExprLib[k] = v
|
ExprLib[k] = v
|
||||||
|
@ -51,7 +50,7 @@ func FileInit(fileFolder string, filename string, fileType string) error {
|
||||||
filepath := path.Join(fileFolder, filename)
|
filepath := path.Join(fileFolder, filename)
|
||||||
file, err := os.Open(filepath)
|
file, err := os.Open(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
|
@ -64,9 +63,7 @@ func FileInit(fileFolder string, filename string, fileType string) error {
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
switch fileType {
|
switch fileType {
|
||||||
case "regex":
|
case "regex", "regexp":
|
||||||
dataFileRegex[filename] = append(dataFileRegex[filename], regexp.MustCompile(scanner.Text()))
|
|
||||||
case "regexp":
|
|
||||||
dataFileRegex[filename] = append(dataFileRegex[filename], regexp.MustCompile(scanner.Text()))
|
dataFileRegex[filename] = append(dataFileRegex[filename], regexp.MustCompile(scanner.Text()))
|
||||||
case "string":
|
case "string":
|
||||||
dataFile[filename] = append(dataFile[filename], scanner.Text())
|
dataFile[filename] = append(dataFile[filename], scanner.Text())
|
||||||
|
@ -76,7 +73,7 @@ func FileInit(fileFolder string, filename string, fileType string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
log.Fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue