urlparser

package module
v0.0.0-...-c97c8be Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: MIT Imports: 3 Imported by: 0

README

urlparser

Installation
$ go get github.com/51gn3d/urlparser
Usage
package main

import (
	"fmt"

	tld "github.com/51gn3d/urlparser"
)

func main() {
	urls := []string{
		"http://google.com",
		"http://blog.google",
		"https://www.medi-cal.ca.gov/",
		"https://ato.gov.au",
		"http://a.very.complex-domain.co.uk:8080/foo/bar",
	}
	for _, url := range urls {
		u, _ := tld.Parse(url)
		fmt.Printf("%50s = [ %s ] [ %s ] [ %s ] [ %s ] [ %s ]\n",
			u, u.Subdomain, u.Domain, u.TLD, u.Port, u.Path)
	}
}
$ go run main.go
                                 http://google.com = [  ] [ google ] [ com ] [  ] [  ]
                                http://blog.google = [  ] [ blog ] [ google ] [  ] [  ]
                      https://www.medi-cal.ca.gov/ = [ www.medi-cal ] [ ca ] [ gov ] [  ] [ / ]
                                https://ato.gov.au = [  ] [ ato ] [ gov.au ] [  ] [  ]
   http://a.very.complex-domain.co.uk:8080/foo/bar = [ a.very ] [ complex-domain ] [ co.uk ] [ 8080 ] [ /foo/bar ]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type URL

type URL struct {
	Subdomain, Domain, TLD, Port string
	*url.URL
}

URL embeds net/url and adds extra fields ontop

func Parse

func Parse(s string) (*URL, error)

Parse mirrors net/url.Parse except instead it returns a tld.URL, which contains extra fields.

Jump to

Keyboard shortcuts

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