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
=== modified file 'example/live_example_managementapi.go'
--- example/live_example_managementapi.go 2013-03-21 00:09:06 +0000
+++ example/live_example_managementapi.go 2013-03-21 02:43:24 +0000
@@ -16,12 +16,13 @@
16)16)
1717
18var certFile string18var certFile string
19
20var subscriptionID string19var subscriptionID string
20var verbose bool
2121
22func getParams() {22func getParams() {
23 flag.StringVar(&certFile, "cert", "my-azure.pem", "Name of your management certificate file (in PEM format)")23 flag.StringVar(&certFile, "cert", "my-azure.pem", "Name of your management certificate file (in PEM format)")
24 flag.StringVar(&subscriptionID, "subscriptionid", "", "Your Azure subscription ID")24 flag.StringVar(&subscriptionID, "subscriptionid", "", "Your Azure subscription ID")
25 flag.BoolVar(&verbose, "verbose", false, "Print debugging output")
25 flag.Parse()26 flag.Parse()
26}27}
2728
@@ -35,6 +36,7 @@
35 getParams()36 getParams()
3637
37 api, err := gwacl.NewManagementAPI(subscriptionID, certFile)38 api, err := gwacl.NewManagementAPI(subscriptionID, certFile)
39 gwacl.SetVerbose(true)
38 checkError(err)40 checkError(err)
3941
40 // Exercise the API.42 // Exercise the API.
4143
=== modified file 'x509dispatcher.go'
--- x509dispatcher.go 2013-03-20 23:53:03 +0000
+++ x509dispatcher.go 2013-03-21 02:43:24 +0000
@@ -3,6 +3,7 @@
3import (3import (
4 "fmt"4 "fmt"
5 curl "github.com/andelf/go-curl"5 curl "github.com/andelf/go-curl"
6 "log"
6)7)
78
8type X509Request struct {9type X509Request struct {
@@ -13,6 +14,13 @@
13 ContentType string14 ContentType string
14}15}
1516
17// Print debugging output.
18var verbose = false
19
20func SetVerbose(newVerbose bool) {
21 verbose = newVerbose
22}
23
16// baseAPIVersion is the default Azure API version to use.24// baseAPIVersion is the default Azure API version to use.
17const baseAPIVersion = "2012-03-01"25const baseAPIVersion = "2012-03-01"
1826
@@ -69,6 +77,12 @@
69}77}
7078
71func performX509CurlRequest(session *X509Session, request *X509Request) (*X509Response, error) {79func performX509CurlRequest(session *X509Session, request *X509Request) (*X509Response, error) {
80 if verbose {
81 log.Println("Performing request")
82 log.Println("Request url: " + request.URL)
83 log.Println("Request method: " + request.Method)
84 log.Printf("Request body: %s\n", request.Payload)
85 }
72 response := newX509Response()86 response := newX509Response()
73 ch := request.makeCurlRequest(session, response)87 ch := request.makeCurlRequest(session, response)
74 defer ch.Cleanup()88 defer ch.Cleanup()
@@ -86,6 +100,11 @@
86 return nil, err100 return nil, err
87 }101 }
88 response.StatusCode = status.(int)102 response.StatusCode = status.(int)
103 if verbose {
104 log.Println("Got response")
105 log.Printf("Response status: %d\n", response.StatusCode)
106 log.Printf("Response body: %s\n", response.Body)
107 }
89 return response, nil108 return response, nil
90}109}
91110

Subscribers

People subscribed via source and target branches

to all changes: