Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
ErrMapMarshal is returned when it is not possible to marshal struct into a map.
ErrMapMarshal is returned when it is not possible to unmarshal map into a struct.
Functions ¶
func Marshal ¶
Marshal transforms a custom struct into string->string map.
Example ¶
type Person struct {
FirstName string `map:"first_name"`
LastName string `map:"last_name"`
}
p := Person{FirstName: "Tim", LastName: "Duncan"}
pMap, _ := Marshal(p)
fmt.Println(pMap["first_name"])
fmt.Println(pMap["last_name"])
Output: Tim Duncan
func Unmarshal ¶
Unmarshal transforms a string->string map into a custom struct.
Example ¶
type Person struct {
FirstName string `map:"first_name"`
LastName string `map:"last_name"`
}
pMap := map[string]string{
"first_name": "Shaquille",
"last_name": "O'Neal",
}
var p Person
Unmarshal(pMap, &p)
fmt.Println(p.FirstName)
fmt.Println(p.LastName)
Output: Shaquille O'Neal
Types ¶
This section is empty.
Source Files
¶
- marshal.go
- unmarshal.go
Click to show internal directories.
Click to hide internal directories.