Open Workout

Development draft, v0. The schema may change; every change is in the changelog.

Go quickstart

clients/go is a thin client on the standard library. Getting the token is your app's job (OAuth 2.1 with PKCE, found from the server's 401); for trying it out, borrow one.

A token

Run it

mkdir ows-go && cd ows-go
go mod init example.com/ows-go
go get github.com/openexercise/open-workout/clients/go

main.go:

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

	openworkout "github.com/openexercise/open-workout/clients/go"
)

func main() {
	ctx := context.Background()
	c := openworkout.New(os.Getenv("OWS_BASE_URL"), os.Getenv("OWS_TOKEN"))

	reps, load := 5, 100.0
	logged, err := c.LogWorkout(ctx, openworkout.WorkoutInput{
		ExternalID: fmt.Sprintf("go-quickstart-%d", time.Now().Unix()),
		Exercises: []openworkout.ExerciseInput{{
			Name: "back squat",
			Sets: []openworkout.SetInput{{Reps: &reps, Load: &load, Unit: openworkout.Kg}},
		}},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(logged.Summary)

	// Everything that changed in the last day, oldest first; deleted workouts as tombstones.
	for ch, err := range c.Changes(ctx, openworkout.ChangesOptions{UpdatedSince: time.Now().Add(-24 * time.Hour), IncludeDeleted: true}) {
		if err != nil {
			log.Fatal(err)
		}
		if ch.Deleted != nil {
			fmt.Println("deleted", ch.Deleted.ID)
		} else {
			fmt.Println("changed", ch.Workout.ID)
		}
	}
}
OWS_BASE_URL=https://lifterclub-api.runmighty.dev OWS_TOKEN=lca_… go run .
OWS_BASE_URL=http://localhost:8080 OWS_TOKEN=dev-token go run .

Next