|
@@ -13,12 +13,12 @@ type MessageStruct struct {
|
|
|
|
|
|
func hello(w http.ResponseWriter, r *http.Request) {
|
|
func hello(w http.ResponseWriter, r *http.Request) {
|
|
m := MessageStruct{"Hello, world"}
|
|
m := MessageStruct{"Hello, world"}
|
|
- j, _ := json.Marshal(m)
|
|
|
|
- fmt.Fprintf(w, string(j))
|
|
|
|
|
|
+ enc := json.NewEncoder(w)
|
|
|
|
+ enc.Encode(m)
|
|
}
|
|
}
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
http.HandleFunc("/json", hello)
|
|
http.HandleFunc("/json", hello)
|
|
http.ListenAndServe(":8080", nil)
|
|
http.ListenAndServe(":8080", nil)
|
|
-}
|
|
|
|
|
|
+}
|