# Building dependencies and API #
The DeviceAtlas Go API provides a way to detect devices based on the data found
in HTTP headers. Using these headers, the API returns device information such as
screen width, screen height, is mobile, vendor, model etc.
To see a full list of properties in DeviceAtlas please visit:
https://deviceatlas.com/resources/available-properties .
### Data File ###
The DeviceAtlas API relies on a device data file to function. DeviceAtlas
provides daily data file updates so it is recommended to download the data file
on a regular basis. This can be done manually from your account page or
automated via the https://deviceatlas.com/getJSON page.
For more information please see:
https://deviceatlas.com/resources/getting-the-data
## Requirements ##
The DeviceAtlas Go API is a wrapper around the DeviceAtlas C API and requires
the following:
- DeviceAtlas C API
- Go (v1.3.1 or later)
Go is often available for install via the system package manager. If this is not
the case it can be downloaded from the [Go website](https://golang.org/) or
[installed from source](https://golang.org/doc/install/source).
## Building the Go API ##
There are two steps to build the Go API:
1. Build and install the DeviceAtlas C API library.
2. Build the Go API wrapper itself.
### Step 1: Building the C API library ###
The C API library is provided under the `Dependencies` folder with the
compilation instructions enclosed in the package or
[available online](https://docs.deviceatlas.com/apis/enterprise/c/2.3.5/README.DeviceApi.html).
A summary of instructions to build and install the C API library `libda.so` and `libci.so` are
below:
```sh
unzip deviceatlas-enterprise-c-{version}.zip
cd deviceatlas-enterprise-c-{version}/Src
cmake .
make
sudo make install
sudo ldconfig /usr/local/lib
```
Note: On Solaris and Illumos, Go only supports 64 bits architectures. For these
the C API must be explicitly compiled in 64 bits.
```sh
cd deviceatlas-enterprise-c-{version}/Src
cmake -DCMAKE_C_FLAGS="-m64"
make
sudo make install
sudo ldconfig /usr/local/lib
```
Note: For Windows based operating systems, please refer to the [README.Windows](https://docs.deviceatlas.com/apis/enterprise/c/2.3.5/README.Windows.html) documentation.
### Step 2: Building the Go API wrapper ###
The following commands build the Go API as a static compiled binary file called
`deviceatlas.a`.
** Unix operating systems **
```sh
cp -r deviceatlas-enterprise-go-wrapper-{version}/Api/src/deviceatlas $(go env GOPATH)/src/
```
** Windows / Powershell **
```sh
copy-item -recurse "deviceatlas-enterprise-go-wrapper-{version}\Api\src\deviceatlas" -destination "$(go env GOPATH)\src\"
```
** Windows / cmd **
```sh
Xcopy /E /I deviceatlas-enterprise-go-wrapper-{version}\Api\src\deviceatlas %GOPATH%\src\deviceatlas\
```
### Additional options ###
#### Custom C API Library path ####
If the Enterprise C API library (libda.so) is not installed in a system path
location, additional environment variables are necessary.
1. CGO_CFLAGS - the path to the C API header files.
2. CGO_LDFLAGS - the path to the C API library
** C API installed in a custom location **
```sh
export CGO_CFLAGS="$CGO_CFLAGS -I/custom/path/header/files"
export CGO_LDFLAGS="$CGO_LDFLAGS -L/custom/path/library/files"
go install deviceatlas/...
```
** C API not installed in the system **
```sh
export CGO_CFLAGS="$CGO_CFLAGS -I/Src"
export CGO_LDFLAGS="$CGO_LDFLAGS -L/Src -Wl,-rpath,/Src"
go install deviceatlas/...
```
Note: On Windows, the PCRE and C API DLLs locations must be present in the PATH
environment variable.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_ Copyright (c) DeviceAtlas 2022. All Rights Reserved. _
https://deviceatlas.com