func injectHostPortInBody()

in src/handlers/helpers.go [28:44]


func injectHostPortInBody(r *http.Request, tcpServerHost string, tcpServerPort string) (map[string]interface{}, error) {
	body := r.Body
	defer body.Close()

	jsonBody := make(map[string]interface{})
	err := json.NewDecoder(body).Decode(&jsonBody)
	// In case of a GET request, the body is empty and we have to initialize it manually
	if err == io.EOF {
		jsonBody = make(map[string]interface{})
	} else if err != nil {
		return nil, err
	}

	jsonBody["STREAM_HOST"] = tcpServerHost
	jsonBody["STREAM_PORT"] = tcpServerPort
	return jsonBody, nil
}