You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
1.7 KiB

  1. <h1>Go</h1>
  2. <p>Below is an example of making an HTTP request to SITE_NAME from Go.</p>
  3. <div class="go highlight"><pre><span></span><code><span class="kn">package</span> <span class="nx">main</span>
  4. <span class="kn">import</span> <span class="s">&quot;fmt&quot;</span>
  5. <span class="kn">import</span> <span class="s">&quot;net/http&quot;</span>
  6. <span class="kn">import</span> <span class="s">&quot;time&quot;</span>
  7. <span class="kd">func</span> <span class="nx">main</span><span class="p">()</span> <span class="p">{</span>
  8. <span class="kd">var</span> <span class="nx">client</span> <span class="p">=</span> <span class="o">&amp;</span><span class="nx">http</span><span class="p">.</span><span class="nx">Client</span><span class="p">{</span>
  9. <span class="nx">Timeout</span><span class="p">:</span> <span class="mi">10</span> <span class="o">*</span> <span class="nx">time</span><span class="p">.</span><span class="nx">Second</span><span class="p">,</span>
  10. <span class="p">}</span>
  11. <span class="nx">_</span><span class="p">,</span> <span class="nx">err</span> <span class="o">:=</span> <span class="nx">client</span><span class="p">.</span><span class="nx">Head</span><span class="p">(</span><span class="s">&quot;PING_URL&quot;</span><span class="p">)</span>
  12. <span class="k">if</span> <span class="nx">err</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
  13. <span class="nx">fmt</span><span class="p">.</span><span class="nx">Printf</span><span class="p">(</span><span class="s">&quot;%s&quot;</span><span class="p">,</span> <span class="nx">err</span><span class="p">)</span>
  14. <span class="p">}</span>
  15. <span class="p">}</span>
  16. </code></pre></div>