-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
49 lines (41 loc) · 895 Bytes
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package catfruits
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
)
// ----------- Helper functions
// FilePath returns a filepath
func (sc *Scanner) FilePath(path string) string {
return filepath.Join(sc.dir, path)
}
// FileExist returns a bool
func (sc *Scanner) FileExist(path string) bool {
fname := sc.FilePath(path)
_, err := os.Stat(fname)
return err == nil
}
// ReadFile returns a file value
func (sc *Scanner) ReadFile(path string) ([]byte, error) {
return ioutil.ReadFile(sc.FilePath(path))
}
func (sc *Scanner) hasPackage(pkg, name string) bool {
pkgs, ok := sc.info.Packages[pkg]
if !ok {
return false
}
for _, v := range pkgs {
if v == name {
return true
}
}
return false
}
func (sc *Scanner) FileContains(path, content string) bool {
b, err := sc.ReadFile(path)
if err != nil {
return false
}
return strings.Contains(string(b), content)
}