Files
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

48 lines
1.1 KiB
Go

package ysurl
import (
"net/url"
"regexp"
)
// 广告跳转类型
type URLJumpType int
const (
ExBrowserJump URLJumpType = iota //外部浏览器跳转
InBrowserJump //内部浏览器跳转
AppJump //APP内部跳转
)
const (
Http = "http" //外部http跳转
Https = "https" //外部https跳转
Yinselink = "yinselink" //内部http跳转
Yinselinks = "yinselinks" //内部https跳转
Yinseinner = "yinseinner" //应用内⻚面跳转
)
func IsValidURL(jumpType URLJumpType, rawurl string) bool {
url, err := url.Parse(rawurl)
if err != nil {
return false
}
switch jumpType {
case ExBrowserJump:
return url.Scheme == Http || url.Scheme == Https
case InBrowserJump:
return url.Scheme == Yinselink || url.Scheme == Yinselinks
case AppJump:
return url.Scheme == Yinseinner
}
return false
}
func IsValidHostName(hostName string) bool {
re, err := regexp.Compile(`^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`)
if err != nil {
return false
}
return re.MatchString(hostName)
}