New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/hauntarl/sitemap

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/hauntarl/sitemap

  • v0.0.0-20210410211118-96ffd6a899ac
  • Source
  • Go
  • Socket score

Version published
Created
Source

Sitemap Builder

One way these can be built is by first visiting the root page of the website and making a list of every link on that page that goes to a page on the same domain. For instance, on calhoun.io you might find a link to calhoun.io/hire-me/ along with several other links.

Once you have created the list of links, you could then visit each and add any new links to your list. By repeating this step over and over you would eventually visit every page that on the domain that can be reached by following links from the root page.

Implementation of Sitemap Builder from gophercises, including the bonus section.

Gophercises by Jon Calhoun

Run Commands:

  • go run main.go --help (-h)
  • go run main.go
  • go run main.go --depth int (-depth=int)

Features:

  • performing http.Get request for given urls and parsing the documents
  • using bread-first traversal on child hrefs to generate a sitemap
  • encoding generated sitemap into xml format

Packages explored:

  • encoding/xml - to encode go data structure into xml format
  • flag - to get depth of search and root url
  • net/http - to perform GET request on urls
  • net/url - to access specific parts of a request url
  • os - to create new file and store encoded results into
  • strings - to check for prefixes in the parsed links
  • github.com/hauntarl/link-parser - to parse the HTML document and extract all hrefs from it

Output:

D:\gophercises\sitemap>go run main.go --help
Usage of C:\Users\hauntarl\AppData\Local\Temp\go-build3946356141\b001\exe\main.exe:
  -depth int
        the maximum depth of links to follow when building a sitemap (default 127)
  -url string
        the url that you want to build a sitemap for (default "https://gophercises.com")

D:\gophercises\sitemap>go run main.go -depth=2
gophercises.com.xml:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://gophercises.com</loc>
  </url>
  <url>
    <loc>https://gophercises.com/</loc>
  </url>
  <url>
    <loc>https://gophercises.com/demos/cyoa/</loc>
  </url>
  <url>
    <loc>https://gophercises.com/demos/cyoa/new-york</loc>
  </url>
  <url>
    <loc>https://gophercises.com/demos/cyoa/denver</loc>
  </url>
</urlset>

FAQs

Package last updated on 10 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc