tangled
alpha
login
or
join now
treethought.xyz
/
attie
5
fork
atom
AT Protocol Terminal Interface Explorer
5
fork
atom
overview
issues
pulls
pipelines
switch to slog
Cam Sweeney
3 weeks ago
e8b8fd27
48ad8879
+22
-60
5 changed files
expand all
collapse all
unified
split
at
client.go
main.go
ui
app.go
collection.go
search.go
+2
-23
at/client.go
···
4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
7
+
"log/slog"
7
8
8
9
comatproto "github.com/bluesky-social/indigo/api/atproto"
9
9
-
log "github.com/sirupsen/logrus"
10
10
11
11
"github.com/bluesky-social/indigo/api/agnostic"
12
12
"github.com/bluesky-social/indigo/atproto/atclient"
···
97
97
if err != nil {
98
98
return nil, fmt.Errorf("failed to lookup identifier: %w", err)
99
99
}
100
100
-
log.WithFields(log.Fields{
101
101
-
"handle": idd.Handle,
102
102
-
"DID": idd.DID,
103
103
-
"PDS": idd.PDSEndpoint(),
104
104
-
}).Info("identifier resolved")
100
100
+
slog.Info("identifier resolved", "handle", idd.Handle, "DID", idd.DID, "PDS", idd.PDSEndpoint())
105
101
return idd, nil
106
102
}
107
103
···
118
114
if err != nil {
119
115
return nil, fmt.Errorf("failed to get client with identifier: %w", err)
120
116
}
121
121
-
122
122
-
log.WithFields(log.Fields{
123
123
-
"client_host": client.Host,
124
124
-
"repo": repo,
125
125
-
"pds": id.PDSEndpoint(),
126
126
-
}).Info("describe repo")
127
117
128
118
// TODO: download repo as car
129
119
// https://github.com/bluesky-social/cookbook/blob/main/go-repo-export/main.go#L46
···
138
128
}
139
129
140
130
func (c *Client) ListRecords(ctx context.Context, collection, repo string) (*RecordsWithIdentity, error) {
141
141
-
log.WithFields(log.Fields{
142
142
-
"collection": collection,
143
143
-
"repo": repo,
144
144
-
}).Info("list records")
145
145
-
146
131
client, id, err := c.withIdentifier(ctx, repo)
147
132
if err != nil {
148
133
return nil, fmt.Errorf("failed to get client with identifier: %w", err)
···
165
150
}
166
151
167
152
func (c *Client) GetRecord(ctx context.Context, collection, repo, rkey string) (*RecordWithIdentity, error) {
168
168
-
log.WithFields(log.Fields{
169
169
-
"collection": collection,
170
170
-
"repo": repo,
171
171
-
"rkey": rkey,
172
172
-
}).Info("get record")
173
173
-
174
153
client, id, err := c.withIdentifier(ctx, repo)
175
154
if err != nil {
176
155
return nil, fmt.Errorf("failed to get client with identifier: %w", err)
+6
-9
main.go
···
1
1
package main
2
2
3
3
import (
4
4
+
"log/slog"
4
5
"os"
5
6
6
6
-
log "github.com/sirupsen/logrus"
7
7
"github.com/treethought/attie/ui"
8
8
9
9
"github.com/bluesky-social/indigo/atproto/identity"
···
15
15
}
16
16
17
17
func main() {
18
18
-
log.SetFormatter(&log.TextFormatter{
19
19
-
FullTimestamp: false,
20
20
-
DisableTimestamp: true,
21
21
-
})
22
18
f, err := os.Create("/tmp/attie.log")
23
19
if err != nil {
24
24
-
log.Fatal(err)
20
20
+
slog.Error("failed to create log file", "error", err)
21
21
+
os.Exit(1)
25
22
}
26
23
defer f.Close()
27
27
-
log.SetOutput(f)
28
28
-
log.Warn("starting attie")
24
24
+
slog.SetDefault(slog.New(slog.NewTextHandler(f, nil)))
25
25
+
slog.Info("starting attie")
29
26
30
27
query := ""
31
28
if len(os.Args) > 1 {
···
36
33
37
34
p := tea.NewProgram(app, tea.WithAltScreen())
38
35
if _, err := p.Run(); err != nil {
39
39
-
log.Fatal(err)
36
36
+
slog.Error("program error", "error", err)
40
37
}
41
38
}
+12
-23
ui/app.go
···
2
2
3
3
import (
4
4
"context"
5
5
-
6
6
-
log "github.com/sirupsen/logrus"
5
5
+
"log/slog"
7
6
8
7
comatproto "github.com/bluesky-social/indigo/api/atproto"
9
8
"github.com/bluesky-social/indigo/atproto/identity"
···
57
56
func (a *App) Init() tea.Cmd {
58
57
a.loading = true
59
58
if id, err := syntax.ParseAtIdentifier(a.query); err == nil {
60
60
-
log.Printf("Starting with query: %s", id.String())
59
59
+
slog.Info("Starting with query", "id", id.String())
61
60
return a.fetchRepo(id.String())
62
61
}
63
62
if uri, err := syntax.ParseATURI(a.query); err == nil {
···
72
71
return a.fetchRecords(uri.Collection().String(), id)
73
72
}
74
73
75
75
-
log.Printf("Starting with query: %s", uri.String())
74
74
+
slog.Info("Starting with query", "uri", uri.String())
76
75
return a.fetchRecord(uri.Collection().String(), uri.Authority().String(), uri.RecordKey().String())
77
76
}
78
77
···
142
141
// parse for handle/DID or a record URI
143
142
id, err := syntax.ParseAtIdentifier(msg.identifier.String())
144
143
if err != nil {
145
145
-
log.Fatalf("Failed to parse identifier, should have caught during submission: %s", err.Error())
144
144
+
slog.Error("Failed to parse identifier, should have caught during submission", "error", err)
146
145
return a, nil
147
146
}
148
147
if id.IsDID() || id.IsHandle() {
149
149
-
log.Printf("Repo identifier submitted: %s", id.String())
150
148
return a, a.fetchRepo(id.String())
151
149
}
152
150
···
163
161
return a, cmd
164
162
165
163
case selectCollectionMsg:
166
166
-
log.Printf("Collection selected: %s", msg.collection)
164
164
+
slog.Info("Collection selected", "collection", msg.collection)
167
165
a.actx.collection = msg.collection
168
166
return a, a.fetchRecords(msg.collection, a.repoView.repo.Handle)
169
167
···
208
206
209
207
func (a *App) fetchRepo(repoId string) tea.Cmd {
210
208
return func() tea.Msg {
209
209
+
slog.Info("Fetching repo", "repoId", repoId)
211
210
resp, err := a.client.GetRepo(context.Background(), repoId)
212
211
if err != nil {
213
213
-
log.Printf("Failed to get repo: %s", err.Error())
212
212
+
slog.Error("Failed to get repo", "error", err)
214
213
return repoErrorMsg{err: err}
215
214
}
216
216
-
log.WithFields(log.Fields{
217
217
-
"repo": resp.Repo.Handle,
218
218
-
}).Info("Repo loaded")
215
215
+
slog.Info("Repo loaded", "repo", resp.Repo.Handle)
219
216
return repoLoadedMsg{repo: resp}
220
217
}
221
218
}
···
224
221
return func() tea.Msg {
225
222
recs, err := a.client.ListRecords(context.Background(), collection, repo)
226
223
if err != nil {
227
227
-
log.Printf("Failed to list records: %s", err.Error())
224
224
+
slog.Error("Failed to list records", "error", err)
228
225
return repoErrorMsg{err: err}
229
226
}
230
230
-
log.WithFields(log.Fields{
231
231
-
"repo": repo,
232
232
-
"collection": collection,
233
233
-
"numRecords": len(recs.Records),
234
234
-
}).Info("Records loaded")
227
227
+
slog.Info("Records loaded", "repo", repo, "collection", collection, "numRecords", len(recs.Records))
235
228
return recordsLoadedMsg{records: recs}
236
229
}
237
230
}
···
240
233
return func() tea.Msg {
241
234
rec, err := a.client.GetRecord(context.Background(), collection, repo, rkey)
242
235
if err != nil {
243
243
-
log.Printf("Failed to get record: %s", err.Error())
236
236
+
slog.Error("Failed to get record", "error", err)
244
237
return repoErrorMsg{err: err}
245
238
}
246
246
-
log.WithFields(log.Fields{
247
247
-
"repo": repo,
248
248
-
"collection": collection,
249
249
-
"rkey": rkey,
250
250
-
}).Info("Record loaded")
239
239
+
slog.Info("Record loaded", "repo", repo, "collection", collection, "rkey", rkey)
251
240
return recordSelectedMsg{
252
241
record: rec,
253
242
}
-2
ui/collection.go
···
2
2
3
3
import (
4
4
"fmt"
5
5
-
log "github.com/sirupsen/logrus"
6
5
"strings"
7
6
8
7
"github.com/bluesky-social/indigo/atproto/syntax"
···
72
71
73
72
func (rl *RecordsList) SetRecords(records []*at.Record) tea.Cmd {
74
73
if records == nil {
75
75
-
log.Error("SetRecords called with nil")
76
74
return nil
77
75
}
78
76
rl.preview.SetRecord(nil)
+2
-3
ui/search.go
···
2
2
3
3
import (
4
4
"fmt"
5
5
-
6
6
-
log "github.com/sirupsen/logrus"
5
5
+
"log/slog"
7
6
8
7
"github.com/bluesky-social/indigo/atproto/syntax"
9
8
"github.com/charmbracelet/bubbles/spinner"
···
68
67
c.err = ""
69
68
c.loading = true
70
69
return c, func() tea.Msg {
71
71
-
log.Printf("Looking up identifier: %s", id.String())
70
70
+
slog.Info("Looking up identifier", "id", id.String())
72
71
return searchSubmitMsg{identifier: id}
73
72
}
74
73
}