Skip to content

Instantly share code, notes, and snippets.

@ernestom
Created March 16, 2013 03:15
Show Gist options
  • Save ernestom/5174779 to your computer and use it in GitHub Desktop.
Save ernestom/5174779 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
)
type APIResponse struct {
Satus int `json:"status"`
Body *APIResponseBody `json:"body"`
}
type APIResponseBody struct {
Persons []*Person `json:"persons"`
}
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
}
func main() {
sutano := &Person{"Sutano", 21}
fulano := &Person{"Fulano", 22}
body := &APIResponseBody{}
body.Persons = append(body.Persons, sutano, fulano)
response := &APIResponse{200, body}
w, _ := json.Marshal(response)
fmt.Println(string(w))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment