MCPcopy Create free account
hub / github.com/SummerSec/SpringExploit / ReadFile

Function ReadFile

cmd/commons/utils/readfile.go:13–61  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

11)
12
13func ReadFile(path string) (urls []string, err error) {
14 log.Info("Reading file: ", path)
15 file, err := os.Open(path)
16 if err != nil {
17 log.Error("An error occurred on opening the inputfile\n" +
18 "Does the file exist?\n" +
19 "Have you got acces to it?\n")
20 return nil, err
21 }
22 defer func(file *os.File) {
23 err := file.Close()
24 if err != nil {
25 log.Error("An error occurred on closing the inputfile\n" +
26 "Does the file exist?\n" +
27 "Have you got acces to it?\n")
28 }
29 }(file)
30 iReader := bufio.NewReader(file)
31 var lins []string
32 for {
33 str, err := iReader.ReadString('\n')
34 if err != nil {
35 return lins, err // error or EOF
36 }
37 // 如果是空行,则跳过
38 if strings.TrimSpace(str) == "" {
39 continue
40 }
41 //如果str结尾存在\n,则去掉
42 //if strings.HasSuffix(str, "\n") {
43 // str = strings.TrimSuffix(str, "\n")
44 //}
45 //如果str结尾存在\r,则去掉
46 //if strings.HasSuffix(str, "\r") {
47 // str = strings.TrimSuffix(str, "\r")
48 //}
49 //// 如果str结尾存在\r\n,则去掉
50 //if strings.HasSuffix(str, "\r\n") {
51 // str = strings.TrimSuffix(str, "\r\n")
52 //}
53
54 if stringsutil.HasSuffixAny(str, "\r\n", "\n", "\r") {
55 str = stringsutil.TrimSuffixAny(str, "\r\n", "\n", "\r")
56 }
57 log.Debugf("The url is : %s", str)
58 lins = append(lins, str)
59 }
60 return lins, nil
61}
62
63func getpath() string {
64 file, _ := exec.LookPath(os.Args[0])

Callers 1

RunMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected