-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathcli.go
65 lines (50 loc) · 961 Bytes
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"log"
"net/http"
"net/url"
"os"
"path"
"github.com/anyappinc/fitbit"
"resty.dev/v3"
)
type WorkoutConfig struct {
URL, APIKey string
syncWeight, syncHeight bool
syncSteps, syncActivities bool
persist bool
}
func (c *WorkoutConfig) CopyFrom(o *WorkoutConfig) {
if c.URL == "" {
c.URL = o.URL
}
if c.APIKey == "" {
c.APIKey = o.APIKey
}
}
type fitbitSync struct {
cfg config
WorkoutConfig WorkoutConfig
restClient *resty.Client
configDir string
configFile string
bind string
redirectURI *url.URL
server *http.Server
authCodeURL *url.URL
state, codeVerifier string
fitbitClient *fitbit.Client
waitForAuth chan bool
profile *fitbit.Profile
}
func newCLI() *fitbitSync {
fs := &fitbitSync{}
return fs
}
func configDir() string {
dir, err := os.UserConfigDir()
if err != nil {
log.Fatal(err)
}
return path.Join(dir, "workout-tracker")
}