Back up /etc/hosts and allow local changes

This commit is contained in:
Shannon V. Davidson
2020-12-22 23:08:35 -06:00
parent a741b7e668
commit c43fcededc
3 changed files with 55 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"time"
"bufio"
// "strings"
)
@@ -114,6 +115,20 @@ func IsFile(path string) bool {
return false
}
func ReadFile(path string) ([]string, error) {
lines := []string{}
f, err := os.Open(path)
if err != nil {
return nil, err
}
scanner := bufio.NewScanner(f)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
f.Close()
return lines, nil
}
func ValidString(pattern string, expr string) bool {
if b, _ := regexp.MatchString(expr, pattern); b == true {
return true