GoAT Site is library that implements Standard.site in Go.
atprotocol standard-site atproto library
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(lexicon): helper to wrap record as recordjson

+18 -7
+4 -3
README.md
··· 13 13 go get -u tangled.org/anhgelus.world/goat-site 14 14 ``` 15 15 16 - Each Standard.site lexicon is implemented: 16 + Each [Standard.site lexicon](https://standard.site/#definitions) is implemented: 17 17 - `Publication` is for `site.standard.publication`; 18 18 - `Document` is for `site.standard.document`; 19 19 - `Subscription` is for `site.standard.graph.subscription`. ··· 51 51 } 52 52 ``` 53 53 54 - But, if you use `site.GetDocument` to retrieve one, it will return a simple `site.Document` without your custom content! 54 + But if you use `site.GetDocument` to retrieve one, it will return a simple `site.Document` without your custom content! 55 55 The `Document.Content` field is a `site.RecordJSON`, a wrapper. 56 56 You can get the type of the content with `RecordJSON.Type` and the raw bytes with `RecordJSON.Raw`. 57 57 You can also directly parse your `Content` with `RecordJSON.As`: ··· 92 92 mp["foo"] = "bar" 93 93 return mp, nil 94 94 } 95 - // the future call to site.MarshalToMap on *Content will return map[string]any{"foo":"bar"}. 95 + // the future call to site.MarshalToMap on *Content 96 + // will return map[string]any{"foo":"bar"}. 96 97 ```
+12 -2
lexicons.go
··· 55 55 ) 56 56 57 57 // RecordJSON is used to encode and to decode [Record] from JSON. 58 + // 59 + // If the [Record] is known by the library, it is decoded in [RecordJSON.Record]. 60 + // Else its type is filled in [RecordJSON.Type] and its raw bytes are placed in [RecordJSON.Raw]. 61 + // 62 + // See [AsJSON] to create a [RecordJSON] from a [Record]. 58 63 type RecordJSON struct { 59 64 // Record parsed. 60 65 // Nil if [Record] is unknown. ··· 65 70 // Raw returns bytes stored if [Record] is unknown. 66 71 // Set after [json.Unmarshal]. 67 72 Raw []byte 73 + } 74 + 75 + // AsJSON wraps a [Record] as a [RecordJSON]. 76 + func AsJSON(r Record) *RecordJSON { 77 + return &RecordJSON{Record: r} 68 78 } 69 79 70 80 // As unmarshals the [RecordJSON] as the provided [Record]. ··· 240 250 // 241 251 // Rkey can be nil. 242 252 func createRecord[T Record](ctx context.Context, client lexutil.LexClient, collection string, repo syntax.AtIdentifier, rkey *syntax.RecordKey, v T) (*Result, error) { 243 - mp, err := MarshalToMap(&RecordJSON{Record: v}) 253 + mp, err := MarshalToMap(AsJSON(v)) 244 254 if err != nil { 245 255 return nil, err 246 256 } ··· 266 276 // updateRecord T in a repo with the given rkey. 267 277 // Always tries to validate the [Document] against the lexicon saved. 268 278 func updateRecord[T Record](ctx context.Context, client lexutil.LexClient, collection string, repo syntax.AtIdentifier, rkey syntax.RecordKey, v T) (*Result, error) { 269 - mp, err := MarshalToMap(&RecordJSON{Record: v}) 279 + mp, err := MarshalToMap(AsJSON(v)) 270 280 if err != nil { 271 281 return nil, err 272 282 }
+2 -2
map.go
··· 45 45 return nil, nil 46 46 } 47 47 val := v.Interface() 48 - if conv, ok := val.(Record); ok { 49 - val = &RecordJSON{Record: conv} 48 + if r, ok := val.(Record); ok { 49 + val = AsJSON(r) 50 50 } 51 51 if conv, ok := val.(MarshalerMap); ok { 52 52 return conv.MarshalMap()