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.

docs(info): missing usage about string field tag

+15 -3
+15 -3
README.md
··· 72 72 } 73 73 ``` 74 74 75 - But if you use `site.GetDocument` to retrieve one, it will return a simple `site.Document` without your custom content! 75 + But if you use `site.GetRecord[*site.Document]` to retrieve one, it will return a simple `site.Document` without your 76 + custom content! 76 77 The `Document.Content` field is a `site.RecordJSON`, a wrapper. 77 78 You can get the type of the content with `RecordJSON.Type` and the raw bytes with `RecordJSON.Raw`. 78 79 You can also directly parse your `Content` with `RecordJSON.As`: ··· 89 90 ### Marshal/Unmarshal 90 91 91 92 When your record is sent, it is firstly marshaled to a map. 92 - We provide `site.MarshalToMap` which works like the JSON API: 93 + We provide `site.MarshalToMap` which works like the standard `encoding/json`: 93 94 ```go 94 95 var c *Content 95 96 // mp is the map[string]any created ··· 103 104 ``` 104 105 105 106 It uses the `json` tag to determine how to marshal the content. 106 - It supports `omitempty`, `string` and embedded type. 107 + It supports `omitempty` and embedded type from the standard library. 108 + 109 + If you want to marshal your field into a string, you can set `string` in the field tag (with the key `map` here). 110 + It automatically calls the `String() string` method. 111 + ```go 112 + type Content struct { 113 + Hey *url.URL `json:"hey" map:"string"` 114 + } 115 + /* 116 + mp = map[string]any{"hey": "https://example.org/"} 117 + */ 118 + ``` 107 119 108 120 If you are using complexe types, you may have to implement `json.Unmarshaler` to unmarshal from JSON and 109 121 `site.MarshalerMap` to marshal to a map.