normalizer

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

(+)go-url-normalize[RFC 3986]

Normalize URL | Count unique normalized URL | Count unique normalized URL per TLD

Installation

Install the package by doing go get:

go get github.com/slimdestro/gourlnormalizer

Three exported methods that you can use in your modules are:

NormalizeURL(url string) 
CountUniqueNormalizedUrls(url []string)  
CountUniqueNormalizedUrlsPerTopLevelDomain(url []string)   

Example

package main 

import (
	"fmt"
	"github.com/slimdestro/gourlnormalizer"
)
func main() { 	 
	normalizedUrl,_ := normalizer.NormalizeURL("https://example.com?b=2&a=1")
	fmt.Println(normalizedUrl)
        // compare both url to see what has changed
 
	urls__ := []string{"https://example.com?a=1&b=2", "https://example.com?b=2&a=1"}
	fmt.Println(normalizer.CountUniqueNormalizedUrls(urls__))
	 
	urls___ := []string{"https://tempo.com", "https://example.com", "https://subdomain.example.com"}
	fmt.Println(normalizer.CountUniqueNormalizedUrlsPerTopLevelDomain(urls___))
}
 

Author

slimdestro(Mukul Mishra)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Ports = map[string]int{
		"http":  80,
		"https": 443,
		"ftp":   21,
	}
)

Functions

func CountUniqueNormalizedUrls

func CountUniqueNormalizedUrls(urls []string) int

@ CountUniqueNormalizedUrls counts unique normalized urls @ calls NormalizeURL() @ Ex: ["https://example.com?a=1&b=2", "https://example.com?b=2&a=1"] returns 1 @ As these 2 urls are same after they are normalized

func CountUniqueNormalizedUrlsPerTopLevelDomain

func CountUniqueNormalizedUrlsPerTopLevelDomain(urls []string) map[string]int

@ CountUniqueNormalizedUrls counts unique normalized url per TLD @ calls NormalizeURL() @ Ex: ["https://example.com", "https://subdomain.example.com"] returns map["example.com" => 2]

func NormalizeURL

func NormalizeURL(s string) (string, error)

@ NormalizeURL() returns RFC-3986 formatted string @ this method is also being used as helper: @ CountUniqueNormalizedUrlsPerTopLevelDomain && CountUniqueNormalizedUrls

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL