func sctFeedbackFromString(t *testing.T, s string) SCTFeedback {
	json := json.NewDecoder(strings.NewReader(s))
	var f SCTFeedback
	if err := json.Decode(&f); err != nil {
		t.Fatalf("Failed to parse JSON: %v", err)
	}
	return f
}
func sthPollinationFromString(t *testing.T, s string) STHPollination {
	json := json.NewDecoder(strings.NewReader(s))
	var f STHPollination
	if err := json.Decode(&f); err != nil {
		t.Fatalf("Failed to parse JSON: %v", err)
	}
	return f
}
// Decode a json response from the server..
func readJson(http *http.Response) (*getScopesResponse, error) {
	var scopes getScopesResponse

	json := json.NewDecoder(http.Body)
	err := json.Decode(&scopes)

	if err != nil {
		return nil, err
	}
	return &scopes, nil
}
예제 #4
0
// parseMetadataUUID reads JSON from OpenStack metadata server and parses
// instance ID out of it.
func parseMetadata(r io.Reader) (*Metadata, error) {
	var metadata Metadata
	json := json.NewDecoder(r)
	if err := json.Decode(&metadata); err != nil {
		return nil, err
	}

	if metadata.Uuid == "" {
		return nil, ErrBadMetadata
	}

	return &metadata, nil
}
예제 #5
0
		}))

	})

	AfterEach(func() {

		defer server.Close()

	})

	It("should allow us to produce json output", func() {

		f = func(req pelau.Request) {

			json := &mime.JSONRequest{req}
			json.Decode("application/json", &result)
			Expect(result["success"]).To(Equal(true))

		}

		client := &http.Client{}
		toSend, _ := json.Marshal(data)
		creq, _ := http.NewRequest("POST", server.URL, bytes.NewReader(toSend))
		creq.Header.Add("Content-Type", "application/json")
		resp, _ := client.Do(creq)
		defer resp.Body.Close()
	})

})