Files
go-garth/README.md
2025-09-22 10:53:41 -07:00

2.5 KiB

Garmin Connect Go Client

Go Reference

Go port of the Garth Python library for accessing Garmin Connect data. Provides full API coverage with improved performance and type safety.

Installation

go get github.com/sstent/go-garth/pkg/garmin

Basic Usage

package main

import (
	"fmt"
	"time"
	"github.com/sstent/go-garth/pkg/garmin"
)

func main() {
	// Create client and authenticate
	client, err := garmin.NewClient("garmin.com")
	if err != nil {
		panic(err)
	}
	
	err = client.Login("your@email.com", "password")
	if err != nil {
		panic(err)
	}

	// Get yesterday's body battery data (detailed)
	yesterday := time.Now().AddDate(0, 0, -1)
	bb, err := client.GetBodyBatteryData(yesterday)
	if err != nil {
		panic(err)
	}
	
	if bb != nil {
		fmt.Printf("Body Battery: %d\n", bb.BodyBatteryValue)
	}

	// Get weekly steps
	steps := garmin.NewDailySteps()
	stepData, err := steps.List(time.Now(), 7, client)
	if err != nil {
		panic(err)
	}
	
	for _, s := range stepData {
		fmt.Printf("%s: %d steps\n",
			s.(garmin.DailySteps).CalendarDate.Format("2006-01-02"),
			*s.(garmin.DailySteps).TotalSteps)
	}
}

Data Types

Available data types with Get() methods:

  • BodyBatteryData
  • HRVData
  • SleepData
  • WeightData

Stats Types

Available stats with List() methods:

Daily Stats

  • DailySteps
  • DailyStress
  • DailyHRV
  • DailyHydration
  • DailyIntensityMinutes
  • DailySleep

Weekly Stats

  • WeeklySteps
  • WeeklyStress
  • WeeklyHRV

Error Handling

All methods return errors implementing:

type GarthError interface {
	error
	Message() string
	Cause() error
}

Specific error types:

  • APIError - HTTP/API failures
  • IOError - File/network issues
  • AuthError - Authentication failures

Performance

Benchmarks show 3-5x speed improvement over Python implementation for bulk data operations:

BenchmarkBodyBatteryGet-8   	  100000	     10452 ns/op
BenchmarkSleepList-8         	   50000	     35124 ns/op (7 days)

Documentation

Full API docs: https://pkg.go.dev/github.com/sstent/go-garth/pkg/garmin

CLI Tool

Includes cmd/garth CLI for data export. Supports both daily and weekly stats:

# Daily steps
go run cmd/garth/main.go --data steps --period daily --start 2023-01-01 --end 2023-01-07

# Weekly stress
go run cmd/garth/main.go --data stress --period weekly --start 2023-01-01 --end 2023-01-28