user_agent

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2012 License: MIT Imports: 2 Imported by: 451

README

UserAgent Build Status

UserAgent is a Go library that parses HTTP User Agents.

Usage

// ...
ua := new(UserAgent);
ua.Parse("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11");

fmt.Printf("%v\n", ua.Mobile());   // => false
fmt.Printf("%v\n", ua.Bot());      // => false
fmt.Printf("%v\n", ua.Mozilla());  // => "5.0"

fmt.Printf("%v\n", ua.Platform()); // => "X11"
fmt.Printf("%v\n", ua.OS());       // => "Linux x86_64"

name, version := ua.Engine();
fmt.Printf("%v\n", name);          // => "AppleWebKit"
fmt.Printf("%v\n", version);       // => "537.11"

name, version = ua.Browser();
fmt.Printf("%v\n", name);          // => "Chrome"
fmt.Printf("%v\n", version);       // => "23.0.1271.97"
// ...

Copyright © 2012 Miquel Sabaté Solà, released under the MIT License.

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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Browser

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

A struct containing all the information that we might be interested from the browser.

type UASection

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

A "section" of the User-Agent string. A section contains the name of the product, its version and an optional comment.

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 (*UserAgent) Bot

func (p *UserAgent) Bot() bool

Returns true if it's a bot, false otherwise.

func (*UserAgent) Browser

func (p *UserAgent) Browser() (string, string)

Public: get the info from the browser itself. Returns:

  • a string containing the name of the browser.
  • a string containing the version of the browser.

func (*UserAgent) Engine

func (p *UserAgent) Engine() (string, string)

Public: get the info from the browser's rendering engine. Returns:

  • a string containing the name of the Engine.
  • a string containing the version of the Engine.

func (*UserAgent) Localization

func (p *UserAgent) Localization() string

Returns a string containing the localization.

func (*UserAgent) Mobile

func (p *UserAgent) Mobile() bool

Returns true if it's a mobile device, false otherwise.

func (*UserAgent) Mozilla

func (p *UserAgent) Mozilla() string

Public: get the mozilla version (it's how the User Agent string begins: "Mozilla/5.0 ...", unless we're dealing with Opera, of course). Returns a string containing the mozilla version.

func (*UserAgent) OS

func (p *UserAgent) OS() string

Returns a string containing the name of the Operating System.

func (*UserAgent) Parse

func (p *UserAgent) Parse(ua string) (err error)

Public: parse a User-Agent string. After calling this function, the receiver will be setted up with all the information that we've extracted.

ua - a string containing the User-Agent from the browser (or the bot).

Returns an error if something went wrong, nil otherwise.

func (*UserAgent) Platform

func (p *UserAgent) Platform() string

Returns a string containing the platform..

Jump to

Keyboard shortcuts

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