func (a *application) index(c *gin.Context) {
	parameters := gin.H{}
	parameters["title"] = "Web Analyser"
	parameters["stylesheet"] = "public/css/index.css"

	// If request method is of type GET, then return here.
	if c.Request.Method == http.MethodGet {
		c.HTML(http.StatusOK, "index.html", parameters)

		return
	}

	// Obtain the URL entered by user from the form.
	url := c.PostForm("url")
	if url == "" {
		parameters["warning"] = "Website URL must not be empty"
		c.HTML(http.StatusBadRequest, "index.html", parameters)

		return
	}

	parameters["url"] = url

	// Check if obtained URL is valid.
	if u, err := netURL.Parse(url); err != nil || u.Host == "" || u.Scheme == "" {
		parameters["warning"] = "The provided URL is not valid, please enter a valid host and scheme"
		c.HTML(http.StatusBadRequest, "index.html", parameters)

		return
	}

	log.Println("[INFO] Provided URL:", url)

	// Fetch HTML document from the provided URL.
	document, err := a.fetcher.Fetch(url)
	if err != nil {
		parameters["warning"] = "The provided URL does not exist/is not accessible at the moment: " + err.Error()
		c.HTML(http.StatusInternalServerError, "index.html", parameters)

		return
	}

	// Crawl the fetched document, and return the results identified.
	info := crawl(document, url)

	log.Println("[INFO] Crawled Output:", info)

	parameters["displayResult"] = true
	parameters["htmlVersion"] = info.htmlVersion
	parameters["pageTitle"] = info.pageTitle

	parameters["h1Count"] = info.headingCount.h1
	parameters["h2Count"] = info.headingCount.h2
	parameters["h3Count"] = info.headingCount.h3
	parameters["h4Count"] = info.headingCount.h4
	parameters["h5Count"] = info.headingCount.h5
	parameters["h6Count"] = info.headingCount.h6

	parameters["accessibleInternalLinkCount"] = info.accessibleInternalLinks.count
	parameters["accessibleInternalLinks"] = info.accessibleInternalLinks.links

	parameters["inaccessibleInternalLinkCount"] = info.inaccessibleInternalLinks.count
	parameters["inaccessibleInternalLinks"] = info.inaccessibleInternalLinks.links

	parameters["externalLinkCount"] = info.externalLinks.count
	parameters["externalLinks"] = info.externalLinks.links

	parameters["containsForm"] = info.containsForm

	log.Println("[INFO] Parameters Returned:", parameters)

	c.HTML(http.StatusOK, "index.html", parameters)
}
// index is the main route of the application,
// used to serve both GET and POST requests.
index is the main route of the application,
used to serve both GET and POST requests.
// index is the main route of the application // used to serve both GET and POST requests .
func (a *application) index(c *gin.Context) {
	parameters := gin.H{}
	parameters["title"] = "Web Analyser"
	parameters["stylesheet"] = "public/css/index.css"
	if c.Request.Method == http.MethodGet {
		c.HTML(http.StatusOK, "index.html", parameters)
		return
	}
	url := c.PostForm("url")
	if url == "" {
		parameters["warning"] = "Website URL must not be empty"
		c.HTML(http.StatusBadRequest, "index.html", parameters)
		return
	}
	parameters["url"] = url
	if u, err := netURL.Parse(url); err != nil || u.Host == "" || u.Scheme == "" {
		parameters["warning"] = "The provided URL is not valid, please enter a valid host and scheme"
		c.HTML(http.StatusBadRequest, "index.html", parameters)
		return
	}
	log.Println("[INFO] Provided URL:", url)
	document, err := a.fetcher.Fetch(url)
	if err != nil {
		parameters["warning"] = "The provided URL does not exist/is not accessible at the moment: " + err.Error()
		c.HTML(http.StatusInternalServerError, "index.html", parameters)
		return
	}
	info := crawl(document, url)
	log.Println("[INFO] Crawled Output:", info)
	parameters["displayResult"] = true
	parameters["htmlVersion"] = info.htmlVersion
	parameters["pageTitle"] = info.pageTitle
	parameters["h1Count"] = info.headingCount.h1
	parameters["h2Count"] = info.headingCount.h2
	parameters["h3Count"] = info.headingCount.h3
	parameters["h4Count"] = info.headingCount.h4
	parameters["h5Count"] = info.headingCount.h5
	parameters["h6Count"] = info.headingCount.h6
	parameters["accessibleInternalLinkCount"] = info.accessibleInternalLinks.count
	parameters["accessibleInternalLinks"] = info.accessibleInternalLinks.links
	parameters["inaccessibleInternalLinkCount"] = info.inaccessibleInternalLinks.count
	parameters["inaccessibleInternalLinks"] = info.inaccessibleInternalLinks.links
	parameters["externalLinkCount"] = info.externalLinks.count
	parameters["externalLinks"] = info.externalLinks.links
	parameters["containsForm"] = info.containsForm
	log.Println("[INFO] Parameters Returned:", parameters)
	c.HTML(http.StatusOK, "index.html", parameters)
}
func ( a * application ) index ( c * gin . Context ) { parameters := gin . H { } parameters [ " " ] = " " parameters [ " " ] = " " if c . Request . Method == http . MethodGet { c . HTML ( http . StatusOK , " " , parameters ) return } url := c . PostForm ( " " ) if url == " " { parameters [ " " ] = " " c . HTML ( http . StatusBadRequest , " " , parameters ) return } parameters [ " " ] = url if u , err := netURL . Parse ( url ) ; err != nil || u . Host == " " || u . Scheme == " " { parameters [ " " ] = " " c . HTML ( http . StatusBadRequest , " " , parameters ) return } log . Println ( " " , url ) document , err := a . fetcher . Fetch ( url ) if err != nil { parameters [ " " ] = " " + err . Error ( ) c . HTML ( http . StatusInternalServerError , " " , parameters ) return } info := crawl ( document , url ) log . Println ( " " , info ) parameters [ " " ] = true parameters [ " " ] = info . htmlVersion parameters [ " " ] = info . pageTitle parameters [ " " ] = info . headingCount . h1 parameters [ " " ] = info . headingCount . h2 parameters [ " " ] = info . headingCount . h3 parameters [ " " ] = info . headingCount . h4 parameters [ " " ] = info . headingCount . h5 parameters [ " " ] = info . headingCount . h6 parameters [ " " ] = info . accessibleInternalLinks . count parameters [ " " ] = info . accessibleInternalLinks . links parameters [ " " ] = info . inaccessibleInternalLinks . count parameters [ " " ] = info . inaccessibleInternalLinks . links parameters [ " " ] = info . externalLinks . count parameters [ " " ] = info . externalLinks . links parameters [ " " ] = info . containsForm log . Println ( " " , parameters ) c . HTML ( http . StatusOK , " " , parameters ) }
index is the main route of the application,
used to serve both GET and POST requests.
index is the main route of the application used to serve both GET and POST requests .
// If request method is of type GET, then return here. // Obtain the URL entered by user from the form. // Check if obtained URL is valid. // Fetch HTML document from the provided URL. // Crawl the fetched document, and return the results identified.