Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

结果写入小bug #70

Open
Wnltc opened this issue Jul 10, 2023 · 1 comment
Open

结果写入小bug #70

Wnltc opened this issue Jul 10, 2023 · 1 comment

Comments

@Wnltc
Copy link

Wnltc commented Jul 10, 2023

写入路径的目录名或文件名带 "." 时,会不写入结果到文件中,如/tmp/.sss/1.json、test.xx.json这种,结果都不会写入

@r1is
Copy link

r1is commented Apr 2, 2024

这个小Bug存在于:module/finger/output.go文件的outfile函数/tmp/.sss/1.json,test.xx.json 明显不会进入if逻辑,其次获取文件后缀的方式也有问题。

func outfile(filename string, allresult []Outrestul) {
	file := strings.Split(filename, ".")
	if len(file) == 2 {
		if file[1] == "json" {
			buf, err := json.MarshalIndent(allresult, "", " ")
			if err != nil {
				fmt.Println(err.Error())
				return
			}
			outjson(filename, buf)
		}
		if file[1] == "xlsx" {
			outxlsx(filename, allresult)
		}
	}

}

修复后的代码:

func outfile(filename string, allresult []Outrestul) {
	fileExt := filepath.Ext(filename)     //获取后缀名 .json .xlsx ,需要 import "path/filepath"
	if fileExt == ".json" {
		buf, err := json.MarshalIndent(allresult, "", " ")
		if err != nil {
			fmt.Println(err.Error())
			return
		}
		outjson(filename, buf)
	}
	if fileExt == ".xlsx" {
		outxlsx(filename, allresult)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants