package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" ) // index is a function that handles all requests to the main page // Note that there are two separate returns func index(w http.ResponseWriter, r *http.Request) { if r.Method == "POST" { body, err := ioutil.ReadAll(r.Body) if err != nil { fmt.Printf("Error: %s\n", err) } var bsOpt, mcOpt Option json.Unmarshal(body, &bsOpt) json.Unmarshal(body, &mcOpt) mcOpt.PriceMonteCarlo() options := make(map[string]Option) options["MonteCarlo"] = mcOpt options["ClosedForm"] = bsOpt w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(options) } else if r.Method == "GET" { fmt.Fprintf(w, "Hello go!") // To be updated } } func main() { http.HandleFunc("/", index) http.ListenAndServe(":8080", nil) }