Merge lp:~rvb/gwacl/add-debug into lp:gwacl

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: 37
Merged at revision: 42
Proposed branch: lp:~rvb/gwacl/add-debug
Merge into: lp:gwacl
Diff against target: 76 lines (+22/-1)
2 files modified
example/live_example_managementapi.go (+3/-1)
x509dispatcher.go (+19/-0)
To merge this branch: bzr merge lp:~rvb/gwacl/add-debug
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+154571@code.launchpad.net

Commit message

Add option to print debugging output.

Description of the change

A bit ugly to have a module-level boolean but it's much simpler compared to always having to pass around the value of the 'verbose' boolean.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

If you're going to mix log.Printf and log.Println, you might use log.Printf here as well:

+ log.Println("Request body: " + string(request.Payload))

(x509dispatcher.go ine 84 or so, in performX509CurlRequest)

review: Approve
lp:~rvb/gwacl/add-debug updated
37. By Raphaël Badin

Review change.

Revision history for this message
Raphaël Badin (rvb) wrote :

> If you're going to mix log.Printf and log.Println, you might use log.Printf
> here as well:
>
> + log.Println("Request body: " + string(request.Payload))
>
> (x509dispatcher.go ine 84 or so, in performX509CurlRequest)

Done!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'example/live_example_managementapi.go'
2--- example/live_example_managementapi.go 2013-03-21 00:09:06 +0000
3+++ example/live_example_managementapi.go 2013-03-21 02:43:24 +0000
4@@ -16,12 +16,13 @@
5 )
6
7 var certFile string
8-
9 var subscriptionID string
10+var verbose bool
11
12 func getParams() {
13 flag.StringVar(&certFile, "cert", "my-azure.pem", "Name of your management certificate file (in PEM format)")
14 flag.StringVar(&subscriptionID, "subscriptionid", "", "Your Azure subscription ID")
15+ flag.BoolVar(&verbose, "verbose", false, "Print debugging output")
16 flag.Parse()
17 }
18
19@@ -35,6 +36,7 @@
20 getParams()
21
22 api, err := gwacl.NewManagementAPI(subscriptionID, certFile)
23+ gwacl.SetVerbose(true)
24 checkError(err)
25
26 // Exercise the API.
27
28=== modified file 'x509dispatcher.go'
29--- x509dispatcher.go 2013-03-20 23:53:03 +0000
30+++ x509dispatcher.go 2013-03-21 02:43:24 +0000
31@@ -3,6 +3,7 @@
32 import (
33 "fmt"
34 curl "github.com/andelf/go-curl"
35+ "log"
36 )
37
38 type X509Request struct {
39@@ -13,6 +14,13 @@
40 ContentType string
41 }
42
43+// Print debugging output.
44+var verbose = false
45+
46+func SetVerbose(newVerbose bool) {
47+ verbose = newVerbose
48+}
49+
50 // baseAPIVersion is the default Azure API version to use.
51 const baseAPIVersion = "2012-03-01"
52
53@@ -69,6 +77,12 @@
54 }
55
56 func performX509CurlRequest(session *X509Session, request *X509Request) (*X509Response, error) {
57+ if verbose {
58+ log.Println("Performing request")
59+ log.Println("Request url: " + request.URL)
60+ log.Println("Request method: " + request.Method)
61+ log.Printf("Request body: %s\n", request.Payload)
62+ }
63 response := newX509Response()
64 ch := request.makeCurlRequest(session, response)
65 defer ch.Cleanup()
66@@ -86,6 +100,11 @@
67 return nil, err
68 }
69 response.StatusCode = status.(int)
70+ if verbose {
71+ log.Println("Got response")
72+ log.Printf("Response status: %d\n", response.StatusCode)
73+ log.Printf("Response body: %s\n", response.Body)
74+ }
75 return response, nil
76 }
77

Subscribers

People subscribed via source and target branches

to all changes: