Go
Go 1.24+
An idiomatic Go client with context on every call, typed pointer fields for optional parameters, and a separate ingest client so a device credential cannot be confused with an organization key.
Install
go get
go get github.com/engmohamed05/bardiya-go@v0.1.0Published packagehttps://pkg.go.dev/github.com/engmohamed05/bardiya-goSource repositoryhttps://github.com/EngMohamed05/bardiya-go
What it supports
- Maps, places, directions and distance matrix
- Tracking sessions, ingest and history
- Webhooks and client tokens
- Streaming with a scoped ingest client
Initialise the client
go
package main
import (
"context"
"os"
bardiya "github.com/engmohamed05/bardiya-go"
)
func main() {
client, err := bardiya.New(bardiya.Config{APIKey: os.Getenv("BARDIYA_API_KEY")})
if err != nil {
panic(err)
}
defer client.Close()
latitude, longitude := 30.0444, 31.2357
places, err := client.Maps.SearchPlaces(context.Background(), &bardiya.SearchPlacesParams{
Q: "coffee",
Latitude: &latitude,
Longitude: &longitude,
Limit: bardiya.Ptr(3),
})
if err != nil {
panic(err)
}
for _, place := range places.Results {
println(place.Name)
}
}Typical operations
Error inspection
go
var apiErr *bardiya.APIError
if errors.As(err, &apiErr) {
fmt.Println(apiErr.StatusCode, apiErr.Code, apiErr.RequestID, apiErr.Retryable)
}Device ingest with a scoped credential
go
// Backend: mint a session-scoped credential with the organization key.
ingest, err := client.NewIngest(sessionID, organizationID, credential)
if err != nil {
return err
}
// Device: ingest can only write to that session.
return ingest.SendLocation(ctx, event)Things that catch people out
- The import path is github.com/engmohamed05/bardiya-go. Older instructions that set GOPRIVATE and imported the module from inside the private application repository are obsolete.
- Every call takes a context.Context: use a deadline, the client does not impose one.
- Call Close() to release idle connections.
