-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.go
More file actions
50 lines (37 loc) · 892 Bytes
/
fetch.go
File metadata and controls
50 lines (37 loc) · 892 Bytes
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
package main
import (
"context"
"fmt"
"log"
"os"
"path/filepath"
"time"
"github.com/popmonkey/irdata"
)
const cacheDir = ".cache"
func main() {
args := os.Args[1:]
if len(args) != 3 {
fmt.Println("Usage: go run fetch.go <path to keyfile> <path to creds> <path to doc repository>")
os.Exit(1)
}
keyFn, credsFn, docDir := args[0], args[1], args[2]
api := irdata.Open(context.Background())
defer api.Close()
api.EnableCache(cacheDir)
if _, err := os.Stat(credsFn); err != nil {
api.AuthAndSaveProvidedCredsToFile(keyFn, credsFn, irdata.CredsFromTerminal{})
}
err := api.AuthWithCredsFromFile(keyFn, credsFn)
if err != nil {
log.Panic(err)
}
data, err := api.GetWithCache("data/doc", time.Duration(8)*time.Hour)
if err != nil {
log.Panic(err)
}
err = os.WriteFile(filepath.Join(docDir, "doc.json"), data, 0644)
if err != nil {
log.Panic(err)
}
}