Package device provides a way to detect devices based on the HTTP headers.
device.go device_web.go
ApiVersion Public API versioning.
const ApiVersion string = "2.3.5"
func Close(f *DaGo)
Allows to reuse the re-set DaGo instance, only the internal data are cleared so no calls to New can be used.
func Config(f *DaGo, c *DaConfig) error
Config sets a DaConfig (new or the one passed via parameter) to a DaGo instance.
func Detect(f *DaGo, headers map[string]string) (map[string]interface{}, error)
Detect returns a map of device properties from HTTP headers.
func DetectHttpRequest(f *DaGo, req *http.Request) (map[string]interface{}, error)
DetectHttpRequest returns a map of device properties using a DaGo and http.Request instances.
func DetectV(f *DaGo, params ...string) (map[string]interface{}, error)
DetectV returns a map of device properties from a User-Agent and optional client-side (variadic version).
func Free(f *DaGo)
Releases the DaGo resource, a call to New will create another DaGo instance.
func LoadDataFromFile(f *DaGo, path string) (int, error)
LoadDataFromFile loads (and/or re-loads) the data file from a given path. For the re-loads make sure the provided Close() is called beforehand.
A DaConfig describes the configuration for the device API.
type DaConfig struct { CookieName string // cookie name that the client side properties would be set to - "DAPROPS" UaProps bool // the User-Agent properties are being included in the property set or not LangProps bool // language/locale properties are being included in the property set or not MatchInfo bool // matched and unmatched parts of the User-Agent (unsupported by the API, present for cross-compatibility) }
func NewConfig() *DaConfig
NewConfig returns a default configuration used by a DaGo instance.
A DaError describes a custom error handled by the device API.
type DaError struct {
// contains filtered or unexported fields
}
func (a DaError) Error() string
A DaGo describes the main type for the API's lifetime.
type DaGo struct {
// contains filtered or unexported fields
}
func New() *DaGo
New creates a DaGo instance with default configs.
func NewWithConfig(config *DaConfig) *DaGo
NewWithConfig creates a DaGo instance with custom config.
func (f *DaGo) Close()
Allows to reuse the reset DaGo instance Only the internal data are cleared so no calls to New can be used.
func (f *DaGo) Config(c *DaConfig) error
Config sets a DaConfig (new or the one passed via parameter) to a DaGo instance.
func (f *DaGo) Detect(headers map[string]string) (map[string]interface{}, error)
Detect returns a map of device properties from HTTP headers.
func (f *DaGo) DetectHttpRequest(req *http.Request) (map[string]interface{}, error)
DetectHttpRequest returns a map of device properties using a DaGo and http.Request instances.
func (f *DaGo) DetectV(params ...string) (map[string]interface{}, error)
DetectV returns a map of device properties from a User-Agent and optional client-side (variadic version).
func (f *DaGo) Free()
Releases the DaGo resource, a call to New will create another DaGo instance.
func (f *DaGo) JSONMeta() (DaJSONMeta, error)
Returns the Data file metadata, e.g version, date of creation and revision
func (f *DaGo) LoadDataFromFile(path string) (int, error)
LoadDataFromFile loads (and/or re-loads) the data file from a given path. For the re-loads make sure the provided Close() is called beforehand.
A DaJSONMeta describes the data file metadata.
type DaJSONMeta struct { Version string Dcreation time.Time Revision int }
func JSONMeta(f *DaGo) (DaJSONMeta, error)
Returns the Data file metadata, e.g version, date of creation and revision