refactor: merge internal/sync into internal/garmin, regroup api files and routes

Garmin auth/sync routes move under /api/garmin/*; sync.Service becomes
garmin.Sync with garmin.SyncConfig/ClientConfig; applog becomes
internal/log; the test mock moves into the garmin package as MockClient
(breaking the test-only import cycle the merge created); stale test
URLs and type names updated to match.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-04 16:04:18 +02:00
parent 19c9aecdeb
commit e2b2bf9611
61 changed files with 2007 additions and 982 deletions

View File

@@ -1,5 +1,5 @@
// Package garmin wraps a direct garminconnect subprocess (see
// pyscript/wrapper.py) as a narrow Go client interface, so the rest of
// wrapper/wrapper.py) as a narrow Go client interface, so the rest of
// geniusrun never deals with the wire protocol directly.
package garmin
@@ -18,10 +18,10 @@ import (
"sync"
"time"
"geniusrun/backend/internal/applog"
"geniusrun/backend/internal/log"
)
//go:embed pyscript/wrapper.py
//go:embed wrapper/wrapper.py
var wrapperScript string
// maxWrapperLineBytes bounds one JSON-line response from the wrapper
@@ -57,8 +57,8 @@ type Client interface {
Close() error
}
// Config configures how the Garmin wrapper subprocess is spawned.
type Config struct {
// ClientConfig configures how the Garmin wrapper subprocess is spawned.
type ClientConfig struct {
// PythonPath is the python3 interpreter to run the embedded wrapper
// script with. Empty defaults to "python3" resolved via PATH.
PythonPath string
@@ -121,7 +121,7 @@ func mapAuthStatus(s string) AuthStatus {
// subprocessClient is the real Client implementation, backed by a wrapper
// subprocess spoken to over newline-delimited JSON on stdio.
type subprocessClient struct {
cfg Config
cfg ClientConfig
mu sync.Mutex // serializes calls; the wrapper holds a single shared Garmin client
cmd *exec.Cmd
@@ -366,7 +366,7 @@ var _ Client = (*subprocessClient)(nil)
// NewClient builds a Client. The subprocess is not spawned until the first
// call that needs it (Authenticate, or any data call once authenticated).
func NewClient(cfg Config) Client {
func NewClient(cfg ClientConfig) Client {
return &subprocessClient{cfg: cfg}
}