2020-07-21 17:23:38 +08:00
|
|
|
package tools
|
|
|
|
|
2020-07-21 17:54:57 +08:00
|
|
|
import (
|
|
|
|
"strings"
|
2020-09-27 00:37:55 +08:00
|
|
|
"regexp"
|
2020-07-21 17:54:57 +08:00
|
|
|
)
|
2020-07-21 17:23:38 +08:00
|
|
|
|
2020-09-27 00:37:55 +08:00
|
|
|
func AddInfoIp4(origin string, ip string, info string) (result string) {
|
|
|
|
re := regexp.MustCompile("(^|[^0-9.])(" + strings.ReplaceAll(ip, ".", "\\.") + ")($|[^0-9.])")
|
|
|
|
result = re.ReplaceAllString(origin, "$1$2"+" ["+info+"]$3")
|
2020-07-21 17:54:57 +08:00
|
|
|
return strings.TrimRight(result, " \t")
|
2020-07-21 17:23:38 +08:00
|
|
|
}
|
2020-09-27 00:37:55 +08:00
|
|
|
|
|
|
|
func AddInfoIp6(origin string, ip string, info string) (result string) {
|
|
|
|
re := regexp.MustCompile("(^|[^0-9a-fA-F:])(" + strings.ReplaceAll(ip, ".", "\\.") + ")($|[^0-9a-fA-F:])")
|
|
|
|
result = re.ReplaceAllString(origin, "$1$2"+" ["+info+"]$3")
|
|
|
|
return strings.TrimRight(result, " \t")
|
|
|
|
}
|
|
|
|
|
|
|
|
func AddInfoDomain(origin string, domain string, info string) (result string) {
|
|
|
|
re := regexp.MustCompile("(^|[^0-9a-zA-Z-])(" + strings.ReplaceAll(domain, ".", "\\.") + ")($|[^0-9a-zA-Z-\\.])")
|
|
|
|
result = re.ReplaceAllString(origin, "$1$2"+" ["+info+"]$3")
|
|
|
|
return strings.TrimRight(result, " \t")
|
|
|
|
}
|