Help us shape the future of Go! Take the 2026 Go Developer Survey

useragent

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseUserAgent

func ParseUserAgent(ua string) string

ParseUserAgent 解析 User-Agent 字符串并提取操作系统和浏览器信息。

参数:

  • ua: User-Agent 字符串

返回值:

  • string: 格式为 "OS/Version Browser/Version" 的字符串,空字符串返回 "-"

用法:

ua := "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/91.0"
info := ParseUserAgent(ua)
// info = "Windows 10 Chrome/91.0"

支持的操作系统:

  • Windows (XP, Vista, 7, 8, 8.1, 10/11)
  • macOS
  • Linux
  • Android
  • iOS

支持的浏览器:

  • Chrome, Firefox, Safari, Edge, Opera, IE

局限:

  • 空字符串返回 "-"
  • 无法识别的浏览器返回空字符串
  • 依赖 User-Agent 字符串的准确性

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL