dbuaparser

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: MIT Imports: 3 Imported by: 0

README

User Agent Parser

前言

这是一个对 Nodejs 的 ua-parser-js 包的 go版本

Get

go get github.com/ggchivalrous/db-uaparser

Example

package main

import "github.com/ggchivalrous/db-uaparser"

func main() {
    ua := "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 635) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537"
    uaInfo := dbuaparser.GetInfo(ua)

    fmt.Println(uaInfo.Browser) // iemobile
    fmt.Println(uaInfo.BrowserVer) // 11.0
    fmt.Println(uaInfo.Cpu) // arm
    fmt.Println(uaInfo.Device) // lumia 635
    fmt.Println(uaInfo.Vendor) // nokia
    fmt.Println(uaInfo.Type) // mobile
    fmt.Println(uaInfo.Engine) // trident
    fmt.Println(uaInfo.EngineVer) // 7.0
    fmt.Println(uaInfo.Os) // windows phone
    fmt.Println(uaInfo.OsVer) // 8.1
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BrowserInfo

type BrowserInfo struct {
	Browser    string // 浏览器名称
	BrowserVer string // 浏览器版本
}

func GetBrowser

func GetBrowser(ua string) BrowserInfo

type CpuInfo

type CpuInfo struct {
	Cpu string // CPU架构
}

func GetCpu

func GetCpu(ua string) CpuInfo

type DeviceInfo

type DeviceInfo struct {
	Device string // 设备名称
	Vendor string // 供应商
	Type   string // 设备类型
}

func GetDevice

func GetDevice(ua string) DeviceInfo

type EngineInfo

type EngineInfo struct {
	Engine    string // 引擎
	EngineVer string // 引擎版本
}

func GetEngine

func GetEngine(ua string) EngineInfo

type Handle

type Handle interface {
	// contains filtered or unexported methods
}

type HandleRegexpMap

type HandleRegexpMap struct {
	Regs []IRegexp
	Props
}

type IRegexp

type IRegexp struct {
	// contains filtered or unexported fields
}

func (*IRegexp) FindStringMatch

func (i *IRegexp) FindStringMatch(s string) []string

type OsInfo

type OsInfo struct {
	Os    string // 操作系统
	OsVer string // 操作系统版本
}

func GetOs

func GetOs(ua string) OsInfo

type PropMap

type PropMap struct {
	Index     int
	Reg       string
	Replace   string
	Handle    Handle
	Value     string
	HandleMap map[string]string
}

type Props

type Props struct {
	Name      PropMap
	Version   PropMap
	Device    PropMap
	Vendor    PropMap
	Type      PropMap
	Cpu       PropMap
	Engine    PropMap
	EngineVer PropMap
	Os        PropMap
	OsVer     PropMap
}

type RegexpMap

type RegexpMap struct {
	Regs []string
	Props
}

type UaInfo

type UaInfo struct {
	Browser    string // 浏览器名称
	BrowserVer string // 浏览器版本
	Cpu        string // CPU架构
	Device     string // 设备名称
	Vendor     string // 供应商
	Type       string // 设备类型
	Engine     string // 引擎名称
	EngineVer  string // 引擎版本
	Os         string // 操作系统
	OsVer      string // 操作系统版本
}

func GetInfo

func GetInfo(ua string) UaInfo

Jump to

Keyboard shortcuts

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