Documentation ¶
Overview ¶
Package user_agent implements an HTTP User Agent string parser. It defines the type UserAgent that contains all the information from the parsed string. It also implements the Parse function and getters for all the relevant information that has been extracted from a parsed User Agent string.
Index ¶
- Constants
- Variables
- func GetEnvKey(ua, referrer string) string
- type Browser
- type Env
- type OSInfo
- type Qq
- type Referrer
- func (r *Referrer) GetAliMiniInfo() *ReferrerMiniInfo
- func (r *Referrer) GetBaiduMiniInfo() *ReferrerMiniInfo
- func (r *Referrer) GetBytedanceMiniInfo() *ReferrerMiniInfo
- func (r *Referrer) GetQqMiniInfo() *ReferrerMiniInfo
- func (r *Referrer) GetWechatMiniInfo() *ReferrerMiniInfo
- func (r *Referrer) IsAliMini() bool
- func (r *Referrer) IsBaiduMini() bool
- func (r *Referrer) IsBytedanceMini() bool
- func (r *Referrer) IsMini() bool
- func (r *Referrer) IsQqMini() bool
- func (r *Referrer) IsWechatMini() bool
- func (r *Referrer) MiniKey() (string, string)
- type ReferrerMiniInfo
- type UserAgent
- func (p *UserAgent) Bot() bool
- func (p *UserAgent) Browser() (string, string)
- func (p *UserAgent) Engine() (string, string)
- func (p *UserAgent) InQq() bool
- func (p *UserAgent) InQqBrowser() bool
- func (p *UserAgent) InQqBrowserAndroid() bool
- func (p *UserAgent) InQqBrowserIos() bool
- func (p *UserAgent) InQqMini() bool
- func (p *UserAgent) InWechat() bool
- func (p *UserAgent) InWechatAndroid() bool
- func (p *UserAgent) InWechatBrowser() bool
- func (p *UserAgent) InWechatIphone() bool
- func (p *UserAgent) InWechatMac() bool
- func (p *UserAgent) InWechatMini() bool
- func (p *UserAgent) InWechatWindow() bool
- func (p *UserAgent) InWechatWork() bool
- func (p *UserAgent) Localization() string
- func (p *UserAgent) Mobile() bool
- func (p *UserAgent) Model() string
- func (p *UserAgent) Mozilla() string
- func (p *UserAgent) OS() string
- func (p *UserAgent) OSInfo() OSInfo
- func (p *UserAgent) Parse(ua string)
- func (p *UserAgent) Platform() string
- func (p *UserAgent) QqKey() string
- func (p *UserAgent) UA() string
- func (p *UserAgent) WechatKey() string
- type Wechat
Constants ¶
const ( QqBrowserId = "MQQBrowser" QqUniqueId = "QQ" QqMiniId = "miniProgram" )
const ( WechatUniqueId = "MicroMessenger" WechatBrowserId = "micromessenger" WechatWorkUniqueId = "wxwork" WechatNetTypeId = "NetType" WechatMiniId = "miniProgram" )
Variables ¶
var (
CommentSplit = []string{"; ", "/"}
)
Functions ¶
Types ¶
type Browser ¶
type Browser struct { // The name of the browser's engine. Engine string // The version of the browser's engine. EngineVersion string // The name of the browser. Name string // The version of the browser. Version string }
Browser is a struct containing all the information that we might be interested from the browser.
type OSInfo ¶
type OSInfo struct { // Full name of the operating system. This is identical to the output of ua.OS() FullName string // Name of the operating system. This is sometimes a shorter version of the // operating system name, e.g. "Mac OS X" instead of "Intel Mac OS X" Name string // Operating system version, e.g. 7 for Windows 7 or 10.8 for Max OS X Mountain Lion Version string }
OSInfo represents full information on the operating system extracted from the user agent.
type Referrer ¶
type Referrer struct {
// contains filtered or unexported fields
}
func NewReferrer ¶
func (*Referrer) GetAliMiniInfo ¶
func (r *Referrer) GetAliMiniInfo() *ReferrerMiniInfo
func (*Referrer) GetBaiduMiniInfo ¶
func (r *Referrer) GetBaiduMiniInfo() *ReferrerMiniInfo
func (*Referrer) GetBytedanceMiniInfo ¶
func (r *Referrer) GetBytedanceMiniInfo() *ReferrerMiniInfo
func (*Referrer) GetQqMiniInfo ¶
func (r *Referrer) GetQqMiniInfo() *ReferrerMiniInfo
func (*Referrer) GetWechatMiniInfo ¶
func (r *Referrer) GetWechatMiniInfo() *ReferrerMiniInfo
func (*Referrer) IsAliMini ¶
IsAliMini 是否为阿里小程序 https://opendocs.alipay.com/mini/api/owycmh https://{appid}.hybrid.alipay-eco.com/{appid}/{version}/index.html#{page}
func (*Referrer) IsBaiduMini ¶
IsBaiduMini 是否为百度小程序 https://smartprogram.baidu.com/docs/develop/api/net/net_rule/ https://{域名}/{appKey}/{version}/page-frame.html https://smartapp.baidu.com/{appKey}/{version}/page-frame.html https://smartapps.cn/{appKey}/{version}/page-frame.html 自基础库版本 V3.170.0 起,其中域名由原来的 https://smartapp.baidu.com 更改为 https://smartapps.cn
func (*Referrer) IsBytedanceMini ¶
IsBytedanceMini 是否为字节跳动小程序 https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/guide/basic-ability/network/ https://tmaservice.developer.toutiao.com/?appid={appid}&version={version}
func (*Referrer) IsQqMini ¶
IsQqMini 是否为qq小程序 https://q.qq.com/wiki/develop/miniprogram/frame/basic_ability/basic_network.html https://appservice.qq.com/{appid}/{version}/page-frame.html
func (*Referrer) IsWechatMini ¶
IsWechatMini 是否是微信小程序请求 https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html https://servicewechat.com/{appid}/{version}/page-frame.html
type ReferrerMiniInfo ¶
type UserAgent ¶
type UserAgent struct {
// contains filtered or unexported fields
}
The UserAgent struct contains all the info that can be extracted from the User-Agent string.
func New ¶
New parses the given User-Agent string and get the resulting UserAgent object.
Returns an UserAgent object that has been initialized after parsing the given User-Agent string.
func (*UserAgent) Browser ¶
Browser returns two strings. The first string is the name of the browser and the second one is the version of the browser.
func (*UserAgent) Engine ¶
Engine returns two strings. The first string is the name of the engine and the second one is the version of the engine.
func (*UserAgent) InQqBrowser ¶
func (*UserAgent) InQqBrowserAndroid ¶
func (*UserAgent) InQqBrowserIos ¶
func (*UserAgent) InWechatAndroid ¶
func (*UserAgent) InWechatBrowser ¶
func (*UserAgent) InWechatIphone ¶
func (*UserAgent) InWechatMac ¶
func (*UserAgent) InWechatMini ¶
func (*UserAgent) InWechatWindow ¶
func (*UserAgent) InWechatWork ¶
func (*UserAgent) Localization ¶
Localization returns a string containing the localization.
func (*UserAgent) Mozilla ¶
Mozilla returns the mozilla version (it's how the User Agent string begins: "Mozilla/5.0 ...", unless we're dealing with Opera, of course).
func (*UserAgent) Parse ¶
Parse the given User-Agent string. After calling this function, the receiver will be setted up with all the information that we've extracted.