this repo has no description
1package main
2
3import (
4 "atproto-playground/api/regnault"
5 "context"
6 "os"
7 "strings"
8
9 "github.com/bluesky-social/indigo/api/atproto"
10 "github.com/bluesky-social/indigo/atproto/client"
11 "github.com/bluesky-social/indigo/atproto/identity"
12 "github.com/bluesky-social/indigo/atproto/syntax"
13 "github.com/bluesky-social/indigo/lex/util"
14)
15
16type LoginData struct {
17 handle string
18 password string
19}
20
21func getLoginData() LoginData {
22 return LoginData{
23 handle: os.Getenv("HANDLE"),
24 password: os.Getenv("PASSWORD"),
25 }
26}
27
28func (l LoginData) Login() (*client.APIClient, error) {
29
30 return client.LoginWithPassword(
31 context.Background(),
32 identity.DefaultDirectory(), syntax.AtIdentifier{Inner: syntax.Handle(l.handle)}, l.password, "", nil)
33
34}
35
36func main() {
37 client, err := getLoginData().Login()
38 if err != nil {
39 panic(err)
40 }
41
42 created := createRecord(client)
43 splitted := strings.Split(created.Uri, "/")
44 deleteRecord(client, splitted[len(splitted)-1])
45}
46
47func createRecord(client *client.APIClient) atproto.RepoCreateRecord_Output {
48 example := regnault.Example{
49 Test: "hellooo",
50 }
51 entry := atproto.RepoCreateRecord_Input{
52 Collection: "dev.regnault.example",
53 Repo: string(*client.AccountDID),
54 Record: &util.LexiconTypeDecoder{Val: &example},
55 }
56
57 a := atproto.RepoCreateRecord_Output{}
58
59 err := client.Post(context.Background(), "com.atproto.repo.createRecord", entry, &a)
60 if err != nil {
61 panic(err)
62 }
63
64 return a
65}
66
67func deleteRecord(client *client.APIClient, rkey string) {
68 entry := atproto.RepoDeleteRecord_Input{
69 Collection: "dev.regnault.example",
70 Repo: string(*client.AccountDID),
71 Rkey: rkey,
72 }
73
74 a := atproto.RepoDeleteRecord_Output{}
75
76 err := client.Post(context.Background(), "com.atproto.repo.deleteRecord", entry, &a)
77 if err != nil {
78 panic(err)
79 }
80}