-
Notifications
You must be signed in to change notification settings - Fork 18
/
go.html
41 lines (31 loc) · 882 Bytes
/
go.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<section name="go" class="go">
<p class="ioDesc">Request</p>
<pre class="incoming"><code class="language-go">package main
import (
<% if @body : %>
"bytes"
<% end %>
"fmt"
"io/ioutil"
"net/http"
)
func main() {
client := &http.Client{}
<% if @body : %>
body := []byte(<%= @helpers.escape @body %>)
<% end %>
req, _ := http.NewRequest("<%= @method %>", "<%= @apiUrl %><%= @url %>", <% if @body : %>bytes.NewBuffer(body)<% else : %>nil<% end %>)
<% if @helpers.isNotEmpty @headers: %>
<% for header, value of @headers : %>
req.Header.Add(<%= @helpers.escape header %>, <%= @helpers.escape value %>)<% end %>
<% end %>
resp, err := client.Do(req)
if err != nil {
fmt.Println("Errored when sending request to the server")
return
}
defer resp.Body.Close()
resp_body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(resp_body))
}</code></pre>
</section>