dont export types (golint)
This commit is contained in:
@@ -10,11 +10,11 @@ import "os"
|
||||
|
||||
// We'll use these two structs to demonstrate encoding and
|
||||
// decoding of custom types below.
|
||||
type Response1 struct {
|
||||
type response1 struct {
|
||||
Page int
|
||||
Fruits []string
|
||||
}
|
||||
type Response2 struct {
|
||||
type response2 struct {
|
||||
Page int `json:"page"`
|
||||
Fruits []string `json:"fruits"`
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func main() {
|
||||
// custom data types. It will only include exported
|
||||
// fields in the encoded output and will by default
|
||||
// use those names as the JSON keys.
|
||||
res1D := &Response1{
|
||||
res1D := &response1{
|
||||
Page: 1,
|
||||
Fruits: []string{"apple", "peach", "pear"}}
|
||||
res1B, _ := json.Marshal(res1D)
|
||||
@@ -60,7 +60,7 @@ func main() {
|
||||
// to customize the encoded JSON key names. Check the
|
||||
// definition of `Response2` above to see an example
|
||||
// of such tags.
|
||||
res2D := &Response2{
|
||||
res2D := &response2{
|
||||
Page: 1,
|
||||
Fruits: []string{"apple", "peach", "pear"}}
|
||||
res2B, _ := json.Marshal(res2D)
|
||||
@@ -103,7 +103,7 @@ func main() {
|
||||
// need for type assertions when accessing the decoded
|
||||
// data.
|
||||
str := `{"page": 1, "fruits": ["apple", "peach"]}`
|
||||
res := Response2{}
|
||||
res := response2{}
|
||||
json.Unmarshal([]byte(str), &res)
|
||||
fmt.Println(res)
|
||||
fmt.Println(res.Fruits[0])
|
||||
|
||||
Reference in New Issue
Block a user