Golang encoding: Difference between revisions
From wikinotes
No edit summary |
No edit summary |
||
Line 22: | Line 22: | ||
</blockquote><!-- Interface --> | </blockquote><!-- Interface --> | ||
= Libraries = | |||
<blockquote> | |||
== Builtin == | == Builtin == | ||
<blockquote> | <blockquote> | ||
Line 34: | Line 36: | ||
|} | |} | ||
</blockquote><!-- Builtin --> | </blockquote><!-- Builtin --> | ||
</blockquote><!-- Libraries --> |
Revision as of 22:21, 25 June 2022
Interface
The encoding libraries share a common interface, making it easy to swap between serialization formats.
Simply swap out the library (herejson
) for your desired output format.serialize
type User struct { Id: int Name: string } user := User{1, "will"} bytes, err := json.Marshall(&user)deserialize
var mapping map[string]int var serialized := []byte(`{"a": 1}`) json.Unmarshall(serialized, &mapping)
Libraries
Builtin
golang encoding/json golang encoding/xml golang encoding/csv