> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baato.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Go

> Integrate the Baato API into Go projects with the official Go client.

The Go client exposes each Baato service as a module hanging off a single `Baato` value,
with a typed request-options struct per call.

<Columns cols={2}>
  <Card title="Source on GitHub" icon="github" href="https://github.com/baato/baato-go-client" horizontal>
    `baato/baato-go-client`
  </Card>

  <Card title="Authentication" icon="key" href="/about/authentication" horizontal>
    Read the token from the environment, not source.
  </Card>
</Columns>

## Installation

```bash theme={null}
go get github.com/baato/baato-go-client
```

## Initialisation

```go theme={null}
// Import core APIs
import (
	baato "github.com/baato/baato-go-client/lib"
	geocode "github.com/baato/baato-go-client/lib/geocode"
)

// initialize Baato core module
accessToken := "YOUR BAATO ACCESS TOKEN HERE" // Get Baato token from environment
baatoMap := baato.Baato(accessToken)
```

Supported services: Geocoding (Search), Reverse Geocoding, Nearby Places and Directions.

## Usage

<AccordionGroup>
  <Accordion title="Geocode — search for places by keyword" icon="magnifying-glass" defaultOpen>
    **Required:** `Q` (`string`) — the query to search for.\
    **Optional:** `Limit` (`int`) — cap the number of results.

    ```go theme={null}
    // intialize geocoding request options
    var geocodingRequest = geocode.GeocodeRequestOptions{
    	Q:     "do",
    	Limit: 5,
    }

    geocode, _ := baatoMap.Geocode.GetGeocode(geocodingRequest)

    fmt.Println(geocode.Data)
    ```
  </Accordion>

  <Accordion title="Reverse Geocode — coordinates to an address" icon="location-crosshairs">
    **Required:** `Lat` and `Lon` (`float`) — the coordinate to look up.

    ```go theme={null}
    // intialize reverse geocoding request options
    var reverseGeocodingRequest = reversegeocode.ReverseGeocodeRequestOptions{
    	Lat: 27.717728723291803,
    	Lon: 85.32784938812257,
    }

    reverseGeocode, _ := baatoMap.ReverseGeocode.GetReverseGeocode(reverseGeocodingRequest)

    fmt.Println(reverseGeocode.Data)
    ```
  </Accordion>

  <Accordion title="Nearby Places — places around a point" icon="compass">
    **Required:** `Type` (`string`), `Lat` and `Lon` (`float`). The supported values for `Type` are listed on the
    [Nearby Places](/services/nearby-places#supported-place-types) page.

    ```go theme={null}
    // intialize nearby places request options
    var nearbyPlacesRequest = nearby.NearbyPlacesRequestOptions{
    	Type: "eat",
    	Lat:  27.717728723291803,
    	Lon:  85.32784938812257,
    }

    nearbyplaces, _ := baatoMap.NearbyPlaces.GetNearbyPlaces(nearbyPlacesRequest)

    fmt.Println(nearbyplaces.Data)
    ```
  </Accordion>

  <Accordion title="Directions — routes between points" icon="route">
    **Required:** `PointsArray` (`[]string`) as `"lat,lon"` pairs, and `Mode` (`car`, `bike` or `foot`).\
    **Optional:** `Alternatives` and `Instructions` (`bool`).

    ```go theme={null}
    // intialize directions request options. PointsArray represents points that we should pass through.
    directionsRequest := directions.DirectionsRequestOptions{
    	PointsArray: []string{"27.6733433,85.2763307", "27.67444444,85.28047222"},
    	Mode:        "bike",
    }

    directions, _ := baatoMap.Directions.GetDirections(directionsRequest)

    fmt.Println(directions.Data)
    ```
  </Accordion>
</AccordionGroup>

<Warning>
  `PointsArray` entries are `"lat,lon"` strings, the reverse of the `[lon, lat]` order map
  renderers use. See [coordinate order](/about/concepts#coordinate-order).
</Warning>

## Next

<Columns cols={2}>
  <Card title="API reference" icon="code" href="/services/overview">
    Every parameter, with a live playground.
  </Card>

  <Card title="Errors and status codes" icon="triangle-exclamation" href="/services/errors">
    What to retry, and what to fix.
  </Card>
</Columns>
