returning random json objects from problem

This commit is contained in:
sm
2013-05-08 23:11:03 -07:00
parent 60fc35e6c8
commit d3cbdfaf1f
2 changed files with 24 additions and 2 deletions
+21 -2
View File
@@ -1,13 +1,32 @@
package main
import (
"encoding/json"
"fmt"
"log"
"math/rand"
"net/http"
)
func attempt(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("hello"))
operation := "+"
if r := rand.Intn(2); r == 0 {
operation = "-"
}
r := map[string]string{
"operation": operation,
}
b, err := json.Marshal(r)
if err != nil {
log.Fatal("issue with json marshalling")
}
j := string(b)
fmt.Println(j)
fmt.Fprintf(w, j)
}
func problem(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("hello"))
fmt.Fprintf(w, "hello world")
}