@@ -44,54 +44,57 @@ module.exports = function (source, options) {
4444
4545 code . push ( ')\n' )
4646
47- code . push ( 'func main() {' )
47+ code . push ( 'func main() {\n ' )
4848
4949 // Create client
5050 if ( opts . timeout > 0 ) {
5151 code . push ( '\tclient := http.Client{' )
5252 code . push ( util . format ( '\t\tTimeout: time.Duration(%s * time.Second),' , opts . timeout ) )
53- code . push ( '\t}' )
53+ code . push ( '\t}\n ' )
5454 } else {
55- code . push ( '\tclient := &http.Client{}' )
55+ code . push ( '\tclient := &http.Client{}\n ' )
5656 }
5757
58- code . push ( util . format ( '\turl := "%s"' , source . fullUrl ) )
58+ code . push ( util . format ( '\turl := "%s"\n ' , source . fullUrl ) )
5959
6060 // If we have body content or not create the var and reader or nil
6161 if ( source . postData . text ) {
62- code . push ( util . format ( '\tpayload := strings.NewReader(%s)' , JSON . stringify ( source . postData . text ) ) )
63- code . push ( util . format ( '\treq, %s := http.NewRequest("%s", url, payload)' , errorPlaceholder , source . method ) )
62+ code . push ( util . format ( '\tpayload := strings.NewReader(%s)\n ' , JSON . stringify ( source . postData . text ) ) )
63+ code . push ( util . format ( '\treq, %s := http.NewRequest("%s", url, payload)\n ' , errorPlaceholder , source . method ) )
6464 } else {
65- code . push ( util . format ( '\treq, %s := http.NewRequest("%s", url, nil)' , errorPlaceholder , source . method ) )
65+ code . push ( util . format ( '\treq, %s := http.NewRequest("%s", url, nil)\n ' , errorPlaceholder , source . method ) )
6666 }
6767
6868 errorCheck ( )
6969
7070 // Add headers
71- Object . keys ( source . allHeaders ) . map ( function ( key ) {
72- code . push ( util . format ( '\treq.Header.Add("%s", "%s")' , key , source . allHeaders [ key ] ) )
73- } )
71+ if ( Object . keys ( source . allHeaders ) . length ) {
72+ Object . keys ( source . allHeaders ) . map ( function ( key ) {
73+ code . push ( util . format ( '\treq.Header.Add("%s", "%s")' , key , source . allHeaders [ key ] ) )
74+ } )
75+ code . push ( null )
76+ }
7477
7578 // Make request
7679 code . push ( util . format ( '\tres, %s := client.Do(req)' , errorPlaceholder ) )
7780 errorCheck ( )
7881
7982 // Get Body
8083 if ( opts . printBody ) {
81- code . push ( '\tdefer res.Body.Close()' )
84+ code . push ( '\n\ tdefer res.Body.Close()' )
8285 code . push ( util . format ( '\tbody, %s := ioutil.ReadAll(res.Body)' , errorPlaceholder ) )
8386 errorCheck ( )
8487 }
8588
8689 // Print it
87- code . push ( '\tfmt.Println(res)' )
90+ code . push ( '\n\ tfmt.Println(res)' )
8891
8992 if ( opts . printBody ) {
9093 code . push ( '\tfmt.Println(string(body))' )
9194 }
9295
9396 // End main block
94- code . push ( '}' )
97+ code . push ( '\n }' )
9598
9699 return code . join ( '\n' )
97100}
0 commit comments