maraudir/common/read.go

49 lines
945 B
Go

package common
import (
"bufio"
"os"
"strings"
)
var (
Paths []string
)
func Readfile(filename string, out chan<- string) error {
file, err := os.Open(filename)
if err != nil {
return err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
out <- line
}
return scanner.Err()
}
func ReadPaths() ([]string, error) {
if Conf.Pathlist == "" {
// default fallback paths, some of the most common opendir uris
return []string{"/", "/files", "/ftp", "/backup", "/backups", "/config", "/dev", "/archive", "/old", "/scripts", "/logs", "/data", "/uploads", "/temp", "/tmp", "/static"}, nil
}
var paths []string
file, err := os.Open(Conf.Pathlist)
if err != nil {
return nil, err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
paths = append(paths, strings.TrimSpace(scanner.Text()))
}
return paths, scanner.Err()
}