@@ -15,7 +15,7 @@ var CodeBuilder = require('../../helpers/code-builder')
1515
1616module . exports = function ( source , options ) {
1717 // Let's Go!
18- var code = new CodeBuilder ( )
18+ var code = new CodeBuilder ( '\t' )
1919
2020 // Define Options
2121 var opts = util . _extend ( {
@@ -29,85 +29,87 @@ module.exports = function (source, options) {
2929 var errorCheck = function ( ) {
3030 if ( opts . checkErrors ) {
3131 code . push ( '\tif err != nil {' )
32- code . push ( '\t\tpanic(err)' )
33- code . push ( '\t}' )
32+ . push ( '\t\tpanic(err)' )
33+ . push ( '\t}' )
3434 }
3535 }
3636
3737 // Create boilerplate
3838 code . push ( 'package main\n' )
39- code . push ( 'import (' )
40- code . push ( '\t "fmt"')
39+ . push ( 'import (' )
40+ . push ( 1 , ' "fmt"')
4141
4242 if ( opts . timeout > 0 ) {
43- code . push ( '\t "time"')
43+ code . push ( 1 , ' "time"')
4444 }
4545
4646 if ( source . postData . text ) {
47- code . push ( '\t "strings"')
47+ code . push ( 1 , ' "strings"')
4848 }
4949
50- code . push ( '\t "net/http"')
50+ code . push ( 1 , ' "net/http"')
5151
5252 if ( opts . printBody ) {
53- code . push ( '\t "io/ioutil"')
53+ code . push ( 1 , ' "io/ioutil"')
5454 }
5555
5656 code . push ( ')\n' )
57-
58- code . push ( 'func main() {\n' )
57+ . push ( 'func main() {\n' )
5958
6059 // Create client
6160 var client
6261 if ( opts . timeout > 0 ) {
6362 client = 'client'
64- code . push ( '\tclient := http.Client{')
65- code . push ( util . format ( '\t\tTimeout : time.Duration(%s * time.Second),' , opts . timeout ) )
66- code . push ( '\t }\n')
63+ code . push ( 1 , 'client := http.Client{')
64+ . push ( 2 , util . format ( 'Timeout : time.Duration(%s * time.Second),' , opts . timeout ) )
65+ . push ( 1 , ' }\n')
6766 } else {
6867 client = 'http.DefaultClient'
6968 }
7069
71- code . push ( util . format ( '\turl := "%s"\n' , source . fullUrl ) )
70+ code . push ( 1 , util . format ( 'url := "%s"\n' , source . fullUrl ) )
7271
7372 // If we have body content or not create the var and reader or nil
7473 if ( source . postData . text ) {
75- code . push ( util . format ( '\tpayload := strings.NewReader(%s)\n' , JSON . stringify ( source . postData . text ) ) )
76- code . push ( util . format ( '\treq , %s := http.NewRequest("%s", url, payload)\n' , errorPlaceholder , source . method ) )
74+ code . push ( 1 , util . format ( 'payload := strings.NewReader(%s)\n' , JSON . stringify ( source . postData . text ) ) )
75+ . push ( 1 , util . format ( 'req , %s := http.NewRequest("%s", url, payload)\n' , errorPlaceholder , source . method ) )
7776 } else {
78- code . push ( util . format ( '\treq , %s := http.NewRequest("%s", url, nil)\n' , errorPlaceholder , source . method ) )
77+ code . push ( 1 , util . format ( 'req , %s := http.NewRequest("%s", url, nil)\n' , errorPlaceholder , source . method ) )
7978 }
8079
8180 errorCheck ( )
8281
8382 // Add headers
8483 if ( Object . keys ( source . allHeaders ) . length ) {
8584 Object . keys ( source . allHeaders ) . map ( function ( key ) {
86- code . push ( util . format ( '\treq .Header.Add("%s", "%s")' , key , source . allHeaders [ key ] ) )
85+ code . push ( 1 , util . format ( 'req .Header.Add("%s", "%s")' , key , source . allHeaders [ key ] ) )
8786 } )
88- code . push ( null )
87+ code . blank ( )
8988 }
9089
9190 // Make request
92- code . push ( util . format ( '\tres , %s := %s.Do(req)' , errorPlaceholder , client ) )
91+ code . push ( 1 , util . format ( 'res , %s := %s.Do(req)' , errorPlaceholder , client ) )
9392 errorCheck ( )
9493
9594 // Get Body
9695 if ( opts . printBody ) {
97- code . push ( '\n\tdefer res.Body.Close()' )
98- code . push ( util . format ( '\tbody, %s := ioutil.ReadAll(res.Body)' , errorPlaceholder ) )
96+ code . blank ( )
97+ . push ( 1 , 'defer res.Body.Close()' )
98+ . push ( 1 , util . format ( 'body, %s := ioutil.ReadAll(res.Body)' , errorPlaceholder ) )
9999 errorCheck ( )
100100 }
101101
102102 // Print it
103- code . push ( '\n\tfmt.Println(res)' )
103+ code . blank ( )
104+ . push ( 1 , 'fmt.Println(res)' )
104105
105106 if ( opts . printBody ) {
106- code . push ( '\tfmt .Println(string(body))')
107+ code . push ( 1 , 'fmt .Println(string(body))')
107108 }
108109
109110 // End main block
110- code . push ( '\n}' )
111+ code . blank ( )
112+ . push ( '}' )
111113
112114 return code . join ( )
113115}
0 commit comments