Skip to content

Commit

Permalink
Rewrite serialization code to avoid JSON
Browse files Browse the repository at this point in the history
Breaking change: automereg will no longer respect `json:` tags on your
structs, instead it uses automerge: tags.

This also fixes a variety of bugs that would happen when certain types
were not the top-level type for automerge.As[]
  • Loading branch information
ConradIrwin committed Jul 5, 2023
1 parent e6d5194 commit 5caac83
Show file tree
Hide file tree
Showing 4 changed files with 426 additions and 61 deletions.
17 changes: 17 additions & 0 deletions automerge.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ assume the path is of the type you say it is:
When you do this, any errors caused by traversing the path will be returned from
methods called on the returned objects.
# Controling formatting of structs
By default automerge will convert your struct to a map. For each public field in the
struct (the name starts with an uppercase letter) automerge will add an entry to the
map with the name of the field and the fields value converted to an automerge value
recursively.
You can control this behaviour using struct tags:
struct Example {
Renamed bool `automerge:"newname"`
Private bool `automerge:"-"`
}
If the tag is present and equal to "-" the field will be ignored by automerge,
otherwise the fields name will be set to the value of the tag.
# Syncing and concurrency
You can access methods on [*Doc] from multiple goroutines and access is mediated
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ExampleAs() {
fmt.Println("foo-bar:", v)

type S struct {
IsValid bool `json:"isValid"`
IsValid bool `automerge:"isValid"`
}
s, err := automerge.As[*S](doc.Root())
if err != nil {
Expand Down
Loading

0 comments on commit 5caac83

Please sign in to comment.