func forwardUserRequest(dispatcherHost string, m *piazza.Message) (*piazza.Message, error) { log.Printf("forwarding user request") buf, err := m.ToBytes() var buff = bytes.NewBuffer(buf) if err != nil { return nil, err } resp, err := http.Post(dispatcherHost, "application/json", buff) if err != nil { return nil, err } defer resp.Body.Close() // resp has a message of type CreateJobResponsePayload, with the id filled in buff = new(bytes.Buffer) buff.ReadFrom(resp.Body) m2, err := piazza.NewMessageFromBytes(buff.Bytes()) if err != nil { return nil, err } log.Printf("returning request response") return m2, nil }
func readUserRequest(r *http.Request) (*piazza.Message, error) { log.Printf("reading user request") body, err := ioutil.ReadAll(r.Body) if err != nil { log.Print(err, string(body)) return nil, err } m, err := piazza.NewMessageFromBytes(body) if err != nil { return nil, err } log.Printf("returning request response") return m, nil }