Extract public functions into utils
This commit is contained in:
parent
2e97278cb9
commit
43d8d65438
13
hosts.go
13
hosts.go
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue