Browse Source

json tests passing

Zane Kansil 10 years ago
parent
commit
76d8fd5840
1 changed files with 13 additions and 0 deletions
  1. 13 0
      frameworks/Go/goji/src/goji/server.go

+ 13 - 0
frameworks/Go/goji/src/goji/server.go

@@ -3,18 +3,31 @@ package main
 import (
 	"fmt"
 	"net/http"
+	"encoding/json"
 	"flag"
 
 	"github.com/zenazn/goji"
 	"github.com/zenazn/goji/web"
 )
 
+type Message struct {
+	Message string `json:"message"`
+}
+
+// Test 1: Json Serialization
+func serializeJson(c web.C, w http.ResponseWriter, r *http.Request) {
+	w.Header().Set("Content-Type", "application/json")
+    json.NewEncoder(w).Encode(&Message{"Hello, World!"})
+}
+
+// Test 6: Plaintext
 func plaintext(c web.C, w http.ResponseWriter, r *http.Request) {
 	fmt.Fprintf(w, "Hello, World!")
 }
 
 func main() {
 	flag.Set("bind", ":8080")
+	goji.Get("/json", serializeJson)
 	goji.Get("/plaintext", plaintext)
 	goji.Serve()
 }