Ben Chuanlong Du's Blog

It is never too late to learn.

Hands on the Standard Library HTTP in Golang

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

In [2]:
import "io/ioutil"
import "io"
import "net/http"
import "strings"
import "os"
import "log"
In [10]:
resp, err := http.Get("https://www.apache.org/dyn/closer.lua/spark/spark-3.3.0/spark-3.3.0-bin-hadoop3.tgz")
In [11]:
if err != nil {
    log.Fatal(err)
}
In [12]:
resp
Out[12]:
&{200 OK 200 HTTP/2.0 2 0 map[Accept-Ranges:[bytes] Cache-Control:[private, max-age=3600] Content-Type:[text/html] Date:[Sun, 26 Jun 2022 20:38:53 GMT] Expires:[Sun, 26 Jun 2022 21:38:53 GMT] Server:[Apache] Vary:[Accept-Encoding] Via:[1.1 varnish, 1.1 varnish] X-Cache:[MISS, MISS] X-Cache-Hits:[0, 0] X-Served-By:[cache-hel1410025-HEL, cache-bfi-krnt7300035-BFI] X-Timer:[S1656275934.713944,VS0,VE165]] 0xc0001744b0 -1 [] false true map[] 0xc000296000 0xc0000ea370}
In [13]:
body, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
In [16]:
resp.StatusCode
Out[16]:
200
In [17]:
if err != nil {
    log.Fatal(err)
}
In [20]:
html := string(body)
html
Out[20]:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Home page of The Apache Software Foundation">
  <base href="https://www.apache.org/dyn/closer.cgi" />
  <link rel="apple-touch-icon" sizes="57x57" href="/favicons/apple-touch-icon-57x57.png">
  <link rel="apple-touch-icon" sizes="60x60" href="/favicons/apple-touch-icon-60x60.png">
  <link rel="apple-touch-icon" sizes="72x72" href="/favicons/apple-touch-icon-72x72.png">
  <link rel="apple-touch-icon" sizes="76x76" href="/favicons/apple-touch-icon-76x76.png">
  <link rel="apple-touch-icon" sizes="114x114" href="/favicons/apple-touch-icon-114x114.png">
  <link rel="apple-touch-icon" sizes="120x120" href="/favicons/apple-touch-icon-120x120.png">
  <link rel="apple-touch-icon" sizes="144x144" href="/favicons/apple-touch-icon-144x144.png">
  <link rel="apple-touch-icon" sizes="152x152" href="/favicons/apple-touch-icon-152x152.png">
  <link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon-180x180.png">
  <link rel="icon" type="image/png" href="/favicons/favicon-32x32.png" sizes="32x32">
  <link rel="icon" type="image/png" href="/favicons/favicon-194x194.png" sizes="194x194">
  <link rel="icon" type="image/png" href="/favicons/favicon-96x96.png" sizes="96x96">
  <link rel="icon" type="image/png" href="/favicons/android-chrome-192x192.png" sizes="192x192">
  <link rel="icon" type="image/png" href="/favicons/favicon-16x16.png" sizes="16x16">
  <link rel="manifest" href="/favicons/manifest.json">
  <link rel="shortcut icon" href="/favicons/favicon.ico">
  <meta name="msapplication-TileColor" content="#603cba">
  <meta name="msapplication-TileImage" content="/favicons/mstile-144x144.png">
  <meta name="msapplication-config" content="/favicons/browserconfig.xml">
  <meta name="theme-color" content="#282661">

  <title>Apache Downloads</title>
  <link href="https://fonts.googleapis.com/css?family=Montserrat:300,600" rel="stylesheet">
  <link href="/css/min.bootstrap.css" rel="stylesheet">
  <link href="/css/styles.css" rel="stylesheet">
  

  <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file to you under the Apache License, Version 2.0 (the &quot;License&quot;); you may not use this file except in compliance with the License.  You may obtain a copy of the License at . http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License. -->

</head>

<body>
  <!-- Navigation -->
  <header>
	<div id="skiptocontent">
		<a href="#maincontent">Skip to Main Content</a>
	</div>
    <nav class="navbar navbar-inverse navbar-fixed-top mainmenu">
      <div class="container">
        <div class="navbar-header">
          <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#mainnav-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
        </div>
        <div class="collapse navbar-collapse" id="mainnav-collapse">
          <ul class="nav navbar-nav navbar-justified">
            <li>
              <form class="visible-xs">
                <div class="input-group" style="width: 100%;">
                  <script>
                    (function() {
                    var cx = '005703438322411770421:5mgshgrgx2u';
                    var gcse = document.createElement('script');
                    gcse.type = 'text/javascript';
                    gcse.async = true;
                    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
                    '//cse.google.com/cse.js?cx=' + cx;
                    var s = document.getElementsByTagName('script')[0];
                    s.parentNode.insertBefore(gcse, s);
                    })();
                  </script>
                  <gcse:searchbox-only></gcse:searchbox-only>
                </div>
              </form>
            </li>
            <li><a href="/index.html#news">News</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">About&nbsp;<span class="caret"></span></a>
              <ul class="dropdown-menu" role="menu">
                <li><a href="/foundation">Overview</a></li>
                <li><a href="/foundation/how-it-works.html">Process</a></li>
                <li><a href="/foundation/governance/">Governance</a></li>
                <li><a href="/theapacheway/index.html">The Apache Way</a></li>
                <li><a href="/foundation/governance/members.html">Membership</a></li>
                <li><a href="https://community.apache.org/">Community</a></li>
                <li><a href="https://diversity.apache.org/">Diversity & Inclusion</a></li>
                <li><a href="/foundation/policies/conduct">Code of Conduct</a></li>
                <li><a href="/foundation/glossary.html">Glossary</a></li>
				  <li><a href="/apache-name">About Our Name</a></li>
                <li><a href="/foundation/preFAQ.html">FAQ</a></li>
                <li><a href="/foundation/contributing.html">Support Apache</a></li>
                <li><a href="/press/">Media/Analysts</a></li>
                <li><a href="/foundation/contact.html">Contact</a></li>
              </ul>
            </li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">Make a Donation&nbsp;<span class="caret"></span></a>
              <ul class="dropdown-menu" role="menu">
                <li><a href="/foundation/contributing.html">Donate Now</a></li>
                <li><a href="https://donate.apache.org/">&nbsp;&nbsp;Via Credit Card</a></li>
                <li><a href="https://donate.apache.org/">&nbsp;&nbsp;Via ACH</a></li>
                <li><a href="https://donate.apache.org/">&nbsp;&nbsp;Via PayPal</a></li>
                <li><a href="https://www.redbubble.com/people/comdev">Buy Swag</a></li>
                <li><a href="https://smile.amazon.com/gp/chpf/homepage/ref=smi_se_scyc_srch_stsr?q=apache+software+foundation&orig=%2F">Shop smile.amazon.com</a></li>
                <li><a href="/foundation/sponsorship.html">ASF Sponsorship</a></li>
                <li><a href="/foundation/thanks#targeted-sponsors">Targeted Sponsorship</a></li>
                <li><a href="/foundation/contributing.html#CorporateGiving">Corporate Giving</a></li>
              </ul>
            </li>
            <li class="dropdown">
              <a href="#" class="dropdopwn-toggle" data-toggle="dropdown">The Apache Way&nbsp;<span class="caret"></span></a>
              <ul class="dropdown-menu" role="menu">
                <li><a href="/theapacheway/index.html">The Apache Way</a></li>
                <li><a href="https://s.apache.org/GhnI">Sustainable Open Source</a></li>
                <li><a href="/foundation/how-it-works.html">How it Works</a></li>
                <li><a href="/foundation/how-it-works.html#meritocracy">Merit</a></li>
                <li><a href="https://blogs.apache.org/foundation/category/SuccessAtApache">Success at Apache</a></li>
              </ul>
            </li>
            <li class="dropdown">
              <a href="#" class="dropdopwn-toggle" data-toggle="dropdown">Join Us&nbsp;<span class="caret"></span></a>
              <ul class="dropdown-menu" role="menu">
                <li><a href="https://community.apache.org/gettingStarted/101.html">Getting Started</a></li>
                <li><a href="https://helpwanted.apache.org/">Help Wanted</a></li>
                <li><a href="https://www.apachecon.com/">ApacheCon</a></li>
                <li><a href="http://community.apache.org/calendars/">Community Events</a></li>
                <li><a href="/travel/">Travel Assistance</a></li>
                <li><a href="https://community.apache.org/gsoc.html">Summer of Code</a></li>
                <li><a href="/foundation/policies/conduct">Code of Conduct</a></li>
                <li><a href="https://community.apache.org/contributors/etiquette">Etiquette</a></li>
                <li class="dropdown dropdown-submenu visible-xs">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">Projects&nbsp;<span class="caret"></span></a>
                  <ul class="dropdown-menu" role="menu">
                    <li><a href="/index.html#projects-list">Project List</a></li>
                    <li><a href="/foundation/how-it-works.html#management">How they work</a></li>
                    <li><a href="https://community.apache.org/projectIndependence.html">Independence</a></li>
                    <li><a href="https://projects.apache.org/committees.html?date">Date Founded</a></li>
                    <li><a href="https://projects.apache.org/projects.html?name">Names</a></li>
                    <li><a href="https://projects.apache.org/projects.html?category">Categories</a></li>
                    <li><a href="https://projects.apache.org/projects.html?language">Languages</a></li>
                    <li><a href="https://projects.apache.org/statistics.html">Statistics</a></li>
                    <li><a href="https://incubator.apache.org/">Apache Incubator</a></li>
                    <li><a href="https://helpwanted.apache.org/">Help Wanted</a></li>
                    <li><a href="/foundation/marks/">Brand Management</a></li>
                  </ul>
                </li>
                <li class="drowpdown dropdown-submenu visible-xs">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">People&nbsp;<span class="caret"></span></a>
                  <ul class="dropdown-menu" role="menu">
                    <li><a href="/foundation/how-it-works.html#roles">Roles</a></li>
                    <li><a href="/foundation/members.html">Members</a></li>
                    <li><a href="https://community.apache.org/contributors/">Committers</a></li>
                    <li><a href="/foundation/#who-runs-the-asf">Board of Directors</a></li>
                    <li><a href="/foundation/#who-runs-the-asf">Officers  &amp; Project VPs</a></li>
                    <li><a href="https://community.zones.apache.org/map.html">Location Map</a></li>
                    <li><a href="/foundation/policies/conduct">Code of Conduct</a></li>
                    <li><a href="https://people.apache.org/">Committer Directory</a></li>
                  </ul>
                </li>
                <li class="drowpdown dropdown-submenu visible-xs">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">Community&nbsp;<span class="caret"></span></a>
                  <ul class="dropdown-menu" role="menu">
                    <li><a href="https://community.apache.org/about/">Community Development</a></li>
                    <li><a href="/foundation/policies/conduct">Code of Conduct</a></li>
                    <li><a href="https://community.apache.org/">Get Involved</a></li>
                    <li><a href="https://community.apache.org/mentoringprogramme.html">Mentoring</a></li>
                    <li><a href="https://helpwanted.apache.org/">Help Wanted</a></li>
                    <li><a href="https://community.apache.org/calendars/">Community Events</a></li>
                    <li><a href="https://community.apache.org/newbiefaq.html">FAQ</a></li>
                    <li><a href="https://community.apache.org/lists.html">Mailing Lists</a></li>
                  </ul>
                </li>
                <li class="drowpdown dropdown-submenu visible-xs">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">License&nbsp;<span class="caret"></span></a>
                  <ul class="dropdown-menu" role="menu">
                    <li><a href="/licenses/LICENSE-2.0">Apache License 2.0</a></li>
                    <li><a href="/foundation/license-faq.html">Licensing FAQ</a></li>
                    <li><a href="/licenses/contributor-agreements.html">Contributor License Agreements</a></li>
                    <li><a href="/licenses/contributor-agreements.html#grants">Software Grants</a></li>
                    <li><a href="/foundation/marks/list/">Trademarks</a></li>
                    <li><a href="/licenses/exports/">Exports</a></li>
                  </ul>
                </li>
                <li class="drowpdown dropdown-submenu visible-xs">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">Sponsors&nbsp;<span class="caret"></span></a>
                  <ul class="dropdown-menu" role="menu">
                    <li><a href="/foundation/sponsorship.html">Sponsor the ASF</a></li>
                    <li><a href="/foundation/thanks">Sponsor Thanks</a></li>
                    <li><a href="/foundation/contributing.html#CorporateGiving">Corporate Giving</a></li>
                    <li><a href="/foundation/contributing.html">Individual Donations</a></li>
                    <li><a href="https://www.redbubble.com/people/comdev/">Buy Stuff</a></li>
                  </ul>
                </li>
              </ul>
            </li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">Downloads&nbsp;<span class="caret"></span></a>
              <ul class="dropdown-menu" role="menu">
                <li><a href="https://downloads.apache.org/">Distribution</a></li>
                <li><a href="https://projects.apache.org/releases.html">Releases</a></li>
                <li><a href="https://status.apache.org/">Infrastructure Status</a></li>
                <li><a href="/uptime/">Infrastructure Statistics</a></li>
              </ul>
            </li>
            <li class="dropdown hidden-xs">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"><span class="glyphicon glyphicon-search"
                  aria-hidden="true"></span><span class="sr-only">Search</span></a>
              <ul class="dropdown-menu search-form" role="search">
                <li>
                  <div class="input-group" style="width: 100%; padding: 0 5px;">
                    <script async src="https://cse.google.com/cse.js?cx=cb41d2753d228d8b7"></script>
                    <div class="gcse-search"></div>
                  </div>
                </li>
              </ul>
            </li>
          </ul>
        </div>
      </div>
    </nav>
  </header>
  <!-- / Navigation -->
  <header id="main-header" class="container">
    <div class="sideImg">
      <a class="visible-home" href="http://apachecon.com/"><img class="img-responsive" src="/img/ApacheCon-PROMO-2019.gif" alt="ApacheCon is Coming 9-12 Sept. 2019 - Las Vegas"></a>
      <a class="hidden-home" href="/"><img class="img-responsive" src="/img/asf-estd-1999-logo.jpg" alt="The Apache Software Foundation"></a>
    </div>
    <div class="main">
      <img class="img-responsive center-block visible-home" src="/img/asf-estd-1999-logo.jpg" alt="Apache 20th Anniversary Logo">
      <h2 class="text-center">Community-led development "The&nbsp;Apache&nbsp;Way"</h2>
      <ul class="nav navbar-nav navbar-justified">
        <li class="drowpdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">Projects&nbsp;<span class="caret hidden-sm"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="/index.html#projects-list">Project List</a></li>
            <li><a href="/foundation/how-it-works.html#management">How they work</a></li>
            <li><a href="https://community.apache.org/projectIndependence.html">Independence</a></li>
            <li><a href="https://projects.apache.org/committees.html?date">Date Founded</a></li>
            <li><a href="https://projects.apache.org/projects.html?name">Names</a></li>
            <li><a href="https://projects.apache.org/projects.html?category">Categories</a></li>
            <li><a href="https://projects.apache.org/projects.html?language">Languages</a></li>
            <li><a href="https://projects.apache.org/statistics.html">Statistics</a></li>
            <li><a href="https://incubator.apache.org/">Apache Incubator</a></li>
            <li><a href="https://helpwanted.apache.org/">Help Wanted</a></li>
            <li><a href="/foundation/marks/">Brand Management</a></li>
            <li><a href="/foundation/glossary.html">Glossary of Terms</a></li>
          </ul>
        </li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">People&nbsp;<span class="caret hidden-sm"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="/foundation/how-it-works.html#roles">Roles</a></li>
            <li><a href="/foundation/members.html">Members</a></li>
            <li><a href="https://community.apache.org/contributors/">Committers</a></li>
            <li><a href="/foundation/#who-runs-the-asf">Board of Directors</a></li>
            <li><a href="/foundation/#who-runs-the-asf">Officers &amp; Project VPs</a></li>
            <li><a href="https://diversity.apache.org/">Diversity & Inclusion</a></li>
            <li><a href="/foundation/policies/conduct">Code of Conduct</a></li>
            <li><a href="https://people.apache.org/">Committer Directory</a></li>
            <li><a href="https://community.zones.apache.org/map.html">Heat Map</a></li>
          </ul>
        </li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">Community&nbsp;<span class="caret hidden-sm"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="https://community.apache.org/about/">Community Development</a></li>
            <li><a href="/foundation/policies/conduct">Code of Conduct</a></li>
            <li><a href="https://community.apache.org/">Get Involved</a></li>
            <li><a href="https://community.apache.org/mentoringprogramme.html">Mentoring</a></li>
            <li><a href="https://helpwanted.apache.org/">Help Wanted</a></li>
            <li><a href="https://community.apache.org/calendars/">Community Events</a></li>
            <li><a href="https://community.apache.org/newbiefaq.html">FAQ</a></li>
            <li><a href="https://community.apache.org/lists.html">Mailing Lists</a></li>
          </ul>
        </li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">License&nbsp;<span class="caret hidden-sm"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="/licenses/LICENSE-2.0">Apache License 2.0</a></li>
            <li><a href="/foundation/license-faq.html">Licensing FAQ</a></li>
            <li><a href="/licenses/contributor-agreements.html">Contributor License Agreements</a></li>
            <li><a href="/licenses/contributor-agreements.html#grants">Software Grants</a></li>
            <li><a href="/foundation/marks/list/">Trademarks</a></li>
			<li><a href="/licenses/exports/">Exports</a></li>
          </ul>
        </li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">Sponsors&nbsp;<span class="caret hidden-sm"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="/foundation/sponsorship.html">Sponsor the ASF</a></li>
            <li><a href="/foundation/thanks">Sponsor Thanks</a></li>
            <li><a href="/foundation/contributing.html#CorporateGiving">Corporate Giving</a></li>
            <li><a href="/foundation/contributing.html">Individual Donations</a></li>
            <li><a href="https://www.redbubble.com/people/comdev/">Buy Stuff</a></li>
          </ul>
        </li>
      </ul>
    </div>
    <div class="sideImg">
      <a href="/foundation/contributing.html"><img class="img-responsive" src="/img/support-apache.jpg" alt="Apache Support Logo" /></a>
    </div>
  </header>
	<main id="maincontent">
  <div class="container"><style type="text/css">
/* The following code is added by mdx_elementid.py
   It was originally lifted from http://subversion.apache.org/style/site.css */
/*
 * Hide class="elementid-permalink", except when an enclosing heading
 * has the :hover property.
 */
.headerlink, .elementid-permalink {
  visibility: hidden;
}
h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
<p> We suggest the following
site for your download:</p>
<p><a href="https://dlcdn.apache.org/spark/spark-3.3.0/spark-3.3.0-bin-hadoop3.tgz"><strong>https://dlcdn.apache.org/spark/spark-3.3.0/spark-3.3.0-bin-hadoop3.tgz</strong></a> </p>
<p>Alternate download locations are suggested below.</p>
<p>It is essential that you <a href="#verify">verify the integrity</a> of the downloaded file using
the PGP signature (<code>.asc</code> file) or a hash (<code>.md5</code> or <code>.sha*</code> file).</p>
<p></p>
<h1 id="http">HTTP<a class="headerlink" href="#http" title="Permanent link">&para;</a></h1>
<p> <a href="https://dlcdn.apache.org/spark/spark-3.3.0/spark-3.3.0-bin-hadoop3.tgz"><strong>https://dlcdn.apache.org/spark/spark-3.3.0/spark-3.3.0-bin-hadoop3.tgz</strong></a> <br></br></p>
<p></p>
<p></p>
<h1 id="backup">Backup Site<a class="headerlink" href="#backup" title="Permanent link">&para;</a></h1>
<p> <a href="https://dlcdn.apache.org/spark/spark-3.3.0/spark-3.3.0-bin-hadoop3.tgz"><strong>https://dlcdn.apache.org/spark/spark-3.3.0/spark-3.3.0-bin-hadoop3.tgz</strong></a> <br></br></p>
<h1 id="verify">Verify the integrity of the files<a class="headerlink" href="#verify" title="Permanent link">&para;</a></h1>
<p>It is essential that you verify the integrity of the downloaded file using
the PGP signature (<code>.asc</code> file) or a hash (<code>.md5</code> or <code>.sha*</code> file). Please read <a href="/info/verification.html">Verifying Apache Software
Foundation Releases</a> for more information on why
you should verify our releases.</p>
<p>The PGP signature can be verified using PGP or GPG. First download the
<code>KEYS</code> as well as the <code>asc</code> signature file for the relevant distribution.
</p>
<div class="codehilite"><pre><span class="c">% gpg --import KEYS</span>
<span class="c">% gpg --verify downloaded_file.asc downloaded_file</span>
</pre></div>


<p><em>or</em></p>
<div class="codehilite"><pre><span class="c">% pgpk -a KEYS</span>
<span class="c">% pgpv downloaded_file.asc</span>
</pre></div>


<p><em>or</em></p>
<div class="codehilite"><pre><span class="c">% pgp -ka KEYS</span>
<span class="c">% pgp downloaded_file.asc</span>
</pre></div>


<p>Alternatively, you can verify the hash on the file.</p>
<p>Hashes can be calculated using GPG:</p>
<div class="codehilite"><pre><span class="c">% gpg --print-md SHA256 downloaded_file</span>
</pre></div>


<p>The output should be compared with the contents of the SHA256 file.
Similarly for other hashes (SHA512, SHA1, MD5 etc) which may be provided.</p>
<p>Windows 7 and later systems should all now have certUtil:</p>
<div class="codehilite"><pre><span class="c">% certUtil -hashfile pathToFileToCheck </span>
</pre></div>


<p>HashAlgorithm choices: MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512</p>
<p>Unix-like systems (and macOS) will have a utility called
md5, md5sum or shasum</p></div>
  </main>
  <!-- Footer -->
  
  <footer class="bg-primary">
    <div class="container">
      <div class="row">
        <br />
        <div class="col-sm-1">

        </div>
        <div class="col-sm-2">
          <h5 class="white">Community</h5>
          <ul class="list-unstyled white" role="menu">
            <li><a href="http://community.apache.org/">Overview</a></li>
            <li><a href="/foundation/conferences.html">Conferences</a></li>
            <li><a href="http://community.apache.org/gsoc.html">Summer of Code</a></li>
            <li><a href="http://community.apache.org/newcomers/">Getting Started</a></li>
            <li><a href="/foundation/how-it-works.html">The Apache Way</a></li>
            <li><a href="/travel/">Travel Assistance</a></li>
            <li><a href="/foundation/getinvolved.html">Get Involved</a></li>
            <li><a href="/foundation/policies/conduct.html">Code of Conduct</a></li>
            <li><a href="http://community.apache.org/newbiefaq.html">Community FAQ</a></li>
            <li><a href="/memorials/">Memorials</a></li>
          </ul>
        </div>

        <div class="col-sm-2">
          <h5 class="white">Innovation</h5>
          <ul class="list-unstyled white" role="menu">
            <li><a href="http://incubator.apache.org/">Incubator</a></li>
            <li><a href="http://labs.apache.org/">Labs</a></li>
            <li><a href="/licenses/">Licensing</a></li>
            <li><a href="/foundation/license-faq.html">Licensing FAQ</a></li>
            <li><a href="/foundation/marks/">Trademark Policy</a></li>
            <li><a href="/foundation/contact.html">Contacts</a></li>
          </ul>
        </div>

        <div class="col-sm-2">
          <h5 class="white">Tech Operations</h5>
          <ul class="list-unstyled white" role="menu">
            <li><a href="/dev/">Developer Information</a></li>
            <li><a href="/dev/infrastructure.html">Infrastructure</a></li>
            <li><a href="/security/">Security</a></li>
            <li><a href="http://status.apache.org">Status</a></li>
            <li><a href="/foundation/contact.html">Contacts</a></li>
          </ul>
        </div>

        <div class="col-sm-2">
          <h5 class="white">Press</h5>
          <ul class="list-unstyled white" role="menu">
            <li><a href="/press/">Overview</a></li>
            <li><a href="https://blogs.apache.org/">ASF News</a></li>
            <li><a href="https://blogs.apache.org/foundation/">Announcements</a></li>
            <li><a href="https://twitter.com/TheASF">Twitter Feed</a></li>
            <li><a href="/press/#contact">Contacts</a></li>
          </ul>
        </div>

        <div class="col-sm-2">
          <h5 class="white">Legal</h5>
          <ul class="list-unstyled white" role="menu">
            <li><a href="/legal/">Legal Affairs</a></li>
            <li><a href="/legal/dmca.html">DMCA</a></li>
            <li><a href="/licenses/">Licensing</a></li>
            <li><a href="/foundation/marks/">Trademark Policy</a></li>
            <li><a href="/foundation/records/">Public Records</a></li>
            <li><a href="/foundation/policies/privacy.html">Privacy Policy</a></li>
            <li><a href="/licenses/exports/">Export Information</a></li>
            <li><a href="/foundation/license-faq.html">Licensing FAQ</a></li>
            <li><a href="/foundation/contact.html">Contacts</a></li>
          </ul>
        </div>

        <div class="col-sm-1">
        </div>

      </div>
      <hr class="col-lg-12 hr-white" />
      <div class="row">
        <div class="col-lg-12">
          <p class="text-center">Copyright &#169; 2022 The Apache Software Foundation, Licensed under the <a class="white" href="/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
          <p class="text-center">Apache and the Apache feather logo are trademarks of The Apache Software Foundation. </p>
        </div>
      </div>
    </div>

  </footer>

  <!-- / Footer -->

  <script src="/js/jquery-2.1.1.min.js"></script>
  <script src="/js/bootstrap.js"></script>
  <script>
    (function($){
    $(document).ready(function(){
    <!-- N.B. the spaces around the value in square brackets are required to ensure EZT does not process it -->
    $('ul.dropdown-menu [ data-toggle=dropdown ]').on('click', function(event) {
    event.preventDefault();
    event.stopPropagation();
    $(this).parent().siblings().removeClass('open');
    $(this).parent().toggleClass('open');
    console.log('WOrked');
    });
    });
    })(jQuery);
  </script>
</body>
</html>
<!-- backup -->
In [27]:
strings.Index(html, "<strong>")
Out[27]:
21399
In [28]:
strings.Index(html, "</strong>")
Out[28]:
21477
In [30]:
html[21399:21477]
Out[30]:
<strong>https://dlcdn.apache.org/spark/spark-3.3.0/spark-3.3.0-bin-hadoop3.tgz
In [35]:
url := html[21399+8:21477]
url
Out[35]:
https://dlcdn.apache.org/spark/spark-3.3.0/spark-3.3.0-bin-hadoop3.tgz
In [6]:
func httpGetAsString(url string) string {
	resp, err := http.Get(url)
	if err != nil {
		log.Fatal(err)
	}
	body, err := ioutil.ReadAll(resp.Body)
	resp.Body.Close()
	if err != nil {
		log.Fatal(err)
	}
	if resp.StatusCode > 399 {
		log.Fatal("HTTP request got an error response with the status code ", resp.StatusCode)
	}
    return string(body)
}
In [7]:
url := "https://api.github.com/repos/legendu-net/icon/releases/tags/v0.6.0"
httpGetAsString(url)
Out[7]:
{"url":"https://api.github.com/repos/legendu-net/icon/releases/72107224","assets_url":"https://api.github.com/repos/legendu-net/icon/releases/72107224/assets","upload_url":"https://uploads.github.com/repos/legendu-net/icon/releases/72107224/assets{?name,label}","html_url":"https://github.com/legendu-net/icon/releases/tag/v0.6.0","id":72107224,"author":{"login":"dclong","id":824507,"node_id":"MDQ6VXNlcjgyNDUwNw==","avatar_url":"https://avatars.githubusercontent.com/u/824507?v=4","gravatar_id":"","url":"https://api.github.com/users/dclong","html_url":"https://github.com/dclong","followers_url":"https://api.github.com/users/dclong/followers","following_url":"https://api.github.com/users/dclong/following{/other_user}","gists_url":"https://api.github.com/users/dclong/gists{/gist_id}","starred_url":"https://api.github.com/users/dclong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dclong/subscriptions","organizations_url":"https://api.github.com/users/dclong/orgs","repos_url":"https://api.github.com/users/dclong/repos","events_url":"https://api.github.com/users/dclong/events{/privacy}","received_events_url":"https://api.github.com/users/dclong/received_events","type":"User","site_admin":false},"node_id":"RE_kwDOHkKAZc4ETETY","tag_name":"v0.6.0","target_commitish":"main","name":"icon v0.6.0","draft":false,"prerelease":false,"created_at":"2022-07-15T16:17:03Z","published_at":"2022-07-15T16:17:30Z","assets":[{"url":"https://api.github.com/repos/legendu-net/icon/releases/assets/71690405","id":71690405,"node_id":"RA_kwDOHkKAZc4EReil","name":"icon-v0.6.0-darwin-amd64.tar.gz","label":"","uploader":{"login":"github-actions[bot]","id":41898282,"node_id":"MDM6Qm90NDE4OTgyODI=","avatar_url":"https://avatars.githubusercontent.com/in/15368?v=4","gravatar_id":"","url":"https://api.github.com/users/github-actions%5Bbot%5D","html_url":"https://github.com/apps/github-actions","followers_url":"https://api.github.com/users/github-actions%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-actions%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-actions%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-actions%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-actions%5Bbot%5D/received_events","type":"Bot","site_admin":false},"content_type":"application/gzip","state":"uploaded","size":4991511,"download_count":1,"created_at":"2022-07-15T16:18:13Z","updated_at":"2022-07-15T16:18:13Z","browser_download_url":"https://github.com/legendu-net/icon/releases/download/v0.6.0/icon-v0.6.0-darwin-amd64.tar.gz"},{"url":"https://api.github.com/repos/legendu-net/icon/releases/assets/71690408","id":71690408,"node_id":"RA_kwDOHkKAZc4EReio","name":"icon-v0.6.0-darwin-amd64.tar.gz.md5","label":"","uploader":{"login":"github-actions[bot]","id":41898282,"node_id":"MDM6Qm90NDE4OTgyODI=","avatar_url":"https://avatars.githubusercontent.com/in/15368?v=4","gravatar_id":"","url":"https://api.github.com/users/github-actions%5Bbot%5D","html_url":"https://github.com/apps/github-actions","followers_url":"https://api.github.com/users/github-actions%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-actions%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-actions%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-actions%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-actions%5Bbot%5D/received_events","type":"Bot","site_admin":false},"content_type":"text/plain","state":"uploaded","size":33,"download_count":0,"created_at":"2022-07-15T16:18:14Z","updated_at":"2022-07-15T16:18:14Z","browser_download_url":"https://github.com/legendu-net/icon/releases/download/v0.6.0/icon-v0.6.0-darwin-amd64.tar.gz.md5"},{"url":"https://api.github.com/repos/legendu-net/icon/releases/assets/71690400","id":71690400,"node_id":"RA_kwDOHkKAZc4EReig","name":"icon-v0.6.0-darwin-arm64.tar.gz","label":"","uploader":{"login":"github-actions[bot]","id":41898282,"node_id":"MDM6Qm90NDE4OTgyODI=","avatar_url":"https://avatars.githubusercontent.com/in/15368?v=4","gravatar_id":"","url":"https://api.github.com/users/github-actions%5Bbot%5D","html_url":"https://github.com/apps/github-actions","followers_url":"https://api.github.com/users/github-actions%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-actions%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-actions%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-actions%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-actions%5Bbot%5D/received_events","type":"Bot","site_admin":false},"content_type":"application/gzip","state":"uploaded","size":4811713,"download_count":1,"created_at":"2022-07-15T16:18:11Z","updated_at":"2022-07-15T16:18:11Z","browser_download_url":"https://github.com/legendu-net/icon/releases/download/v0.6.0/icon-v0.6.0-darwin-arm64.tar.gz"},{"url":"https://api.github.com/repos/legendu-net/icon/releases/assets/71690403","id":71690403,"node_id":"RA_kwDOHkKAZc4EReij","name":"icon-v0.6.0-darwin-arm64.tar.gz.md5","label":"","uploader":{"login":"github-actions[bot]","id":41898282,"node_id":"MDM6Qm90NDE4OTgyODI=","avatar_url":"https://avatars.githubusercontent.com/in/15368?v=4","gravatar_id":"","url":"https://api.github.com/users/github-actions%5Bbot%5D","html_url":"https://github.com/apps/github-actions","followers_url":"https://api.github.com/users/github-actions%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-actions%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-actions%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-actions%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-actions%5Bbot%5D/received_events","type":"Bot","site_admin":false},"content_type":"text/plain","state":"uploaded","size":33,"download_count":0,"created_at":"2022-07-15T16:18:12Z","updated_at":"2022-07-15T16:18:12Z","browser_download_url":"https://github.com/legendu-net/icon/releases/download/v0.6.0/icon-v0.6.0-darwin-arm64.tar.gz.md5"},{"url":"https://api.github.com/repos/legendu-net/icon/releases/assets/71690355","id":71690355,"node_id":"RA_kwDOHkKAZc4ERehz","name":"icon-v0.6.0-linux-amd64.tar.gz","label":"","uploader":{"login":"github-actions[bot]","id":41898282,"node_id":"MDM6Qm90NDE4OTgyODI=","avatar_url":"https://avatars.githubusercontent.com/in/15368?v=4","gravatar_id":"","url":"https://api.github.com/users/github-actions%5Bbot%5D","html_url":"https://github.com/apps/github-actions","followers_url":"https://api.github.com/users/github-actions%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-actions%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-actions%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-actions%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-actions%5Bbot%5D/received_events","type":"Bot","site_admin":false},"content_type":"application/gzip","state":"uploaded","size":5186711,"download_count":8,"created_at":"2022-07-15T16:18:05Z","updated_at":"2022-07-15T16:18:05Z","browser_download_url":"https://github.com/legendu-net/icon/releases/download/v0.6.0/icon-v0.6.0-linux-amd64.tar.gz"},{"url":"https://api.github.com/repos/legendu-net/icon/releases/assets/71690359","id":71690359,"node_id":"RA_kwDOHkKAZc4EReh3","name":"icon-v0.6.0-linux-amd64.tar.gz.md5","label":"","uploader":{"login":"github-actions[bot]","id":41898282,"node_id":"MDM6Qm90NDE4OTgyODI=","avatar_url":"https://avatars.githubusercontent.com/in/15368?v=4","gravatar_id":"","url":"https://api.github.com/users/github-actions%5Bbot%5D","html_url":"https://github.com/apps/github-actions","followers_url":"https://api.github.com/users/github-actions%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-actions%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-actions%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-actions%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-actions%5Bbot%5D/received_events","type":"Bot","site_admin":false},"content_type":"text/plain","state":"uploaded","size":33,"download_count":0,"created_at":"2022-07-15T16:18:06Z","updated_at":"2022-07-15T16:18:06Z","browser_download_url":"https://github.com/legendu-net/icon/releases/download/v0.6.0/icon-v0.6.0-linux-amd64.tar.gz.md5"},{"url":"https://api.github.com/repos/legendu-net/icon/releases/assets/71690414","id":71690414,"node_id":"RA_kwDOHkKAZc4EReiu","name":"icon-v0.6.0-linux-arm64.tar.gz","label":"","uploader":{"login":"github-actions[bot]","id":41898282,"node_id":"MDM6Qm90NDE4OTgyODI=","avatar_url":"https://avatars.githubusercontent.com/in/15368?v=4","gravatar_id":"","url":"https://api.github.com/users/github-actions%5Bbot%5D","html_url":"https://github.com/apps/github-actions","followers_url":"https://api.github.com/users/github-actions%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-actions%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-actions%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-actions%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-actions%5Bbot%5D/received_events","type":"Bot","site_admin":false},"content_type":"application/gzip","state":"uploaded","size":4843937,"download_count":0,"created_at":"2022-07-15T16:18:22Z","updated_at":"2022-07-15T16:18:23Z","browser_download_url":"https://github.com/legendu-net/icon/releases/download/v0.6.0/icon-v0.6.0-linux-arm64.tar.gz"}],"tarball_url":"https://api.github.com/repos/legendu-net/icon/tarball/v0.6.0","zipball_url":"https://api.github.com/repos/legendu-net/icon/zipball/v0.6.0","body":""}

Download Files Using "net/http"

In [45]:
resp, err := http.Get(url)
if err != nil {
    log.Fatal(err)
}
In [46]:
// Create the file
out, err := os.Create("spark.tgz")
if err != nil {
    log.Fatal(err)
}
In [47]:
// Write the body to file
_, err = io.Copy(out, resp.Body)
err
In [ ]:
 

Comments