Extract public functions into utils

This commit is contained in:
kenshinx 2018-02-01 17:09:02 +08:00
parent 2e97278cb9
commit 43d8d65438
3 changed files with 18 additions and 13 deletions

View File

@ -4,7 +4,6 @@ import (
"bufio"
"net"
"os"
"regexp"
"strings"
"sync"
"time"
@ -240,15 +239,3 @@ func (f *FileHosts) Refresh() {
func (f *FileHosts) clear() {
f.hosts = make(map[string]string)
}
func isDomain(domain string) bool {
if isIP(domain) {
return false
}
match, _ := regexp.MatchString(`^([a-zA-Z0-9\*]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$`, domain)
return match
}
func isIP(ip string) bool {
return (net.ParseIP(ip) != nil)
}

18
utils.go Normal file
View File

@ -0,0 +1,18 @@
package main
import (
"net"
"regexp"
)
func isDomain(domain string) bool {
if isIP(domain) {
return false
}
match, _ := regexp.MatchString(`^([a-zA-Z0-9\*]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$`, domain)
return match
}
func isIP(ip string) bool {
return (net.ParseIP(ip) != nil)
}