Skip to content

Instantly share code, notes, and snippets.

@grapswiz
Last active December 15, 2015 16:19
Show Gist options
  • Select an option

  • Save grapswiz/5288792 to your computer and use it in GitHub Desktop.

Select an option

Save grapswiz/5288792 to your computer and use it in GitHub Desktop.
application: gogogrid
version: 1
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
package jsonSample
import (
"net/http"
"fmt"
"encoding/json"
)
func init() {
http.HandleFunc("/", handler)
}
type user struct {
Age int
Married bool
}
func handler(rw http.ResponseWriter, req *http.Request) {
src_json := []byte(`{"age":21,"married":true}`)
u := user{}
err := json.Unmarshal(src_json, &u)
if err != nil {
panic(err)
}
fmt.Fprintf(rw, "Age: %d\n", u.Age)
fmt.Fprintf(rw, "Married: %v\n", u.Married)
s_u := user{23, false}
b, err := json.Marshal(s_u)
if err != nil {
panic(err)
}
fmt.Fprintf(rw, "%s\n", b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment