From 83de776b48c95bc9b4b82b0ef6992b64b76a6e35 Mon Sep 17 00:00:00 2001 From: Brendan Melville Date: Tue, 17 Nov 2015 13:54:11 -0800 Subject: [PATCH] Cleaning up some comments and better callHttp interface. --- dm/dm.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dm/dm.go b/dm/dm.go index 214d555e6..a22989c23 100644 --- a/dm/dm.go +++ b/dm/dm.go @@ -175,10 +175,10 @@ func main() { func callService(path, method, action string, reader io.ReadCloser) { u := fmt.Sprintf("%s/%s", *service, path) - callAndPrintHttp(u, method, action, reader) + fmt.Println(callHttp(u, method, action, reader)) } -func callAndPrintHttp(path, method, action string, reader io.ReadCloser) { +func callHttp(path, method, action string, reader io.ReadCloser) string { request, err := http.NewRequest(method, path, reader) request.Header.Add("Content-Type", "application/json") response, err := http.DefaultClient.Do(request) @@ -198,11 +198,12 @@ func callAndPrintHttp(path, method, action string, reader io.ReadCloser) { log.Fatalf("cannot %s: %s\n", action, message) } - fmt.Println(string(body)) + return string(body) } -// describeType prints the schema for a type specified by either a -// template URL or a fully qualified registry type name. +// describeType prints the schema for a type specified by either a +// template URL or a fully qualified registry type name (e.g., +// :) func describeType(args []string) { if len(args) != 2 { fmt.Fprintln(os.Stderr, "No type name or URL supplied") @@ -230,7 +231,7 @@ func describeType(args []string) { } schemaUrl := tUrl + ".schema" - callAndPrintHttp(schemaUrl, "GET", "get schema for type ("+tUrl+")", nil) + fmt.Println(callHttp(schemaUrl, "GET", "get schema for type ("+tUrl+")", nil)) } func loadTemplate(args []string) *expander.Template {