tld

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 4 Imported by: 1

README

tld v1.0

The tld package provides functionality to parse URLs and extract various components such as subdomain, domain, top-level domain (TLD), and port. It is particularly useful for scenarios where you need to analyze or manipulate URLs in your Go applications.

tld

Go Reference

A Go package for parsing URLs and extracting subdomain, domain, top-level domain (TLD), and port information.

Description

The tld package provides functionality to parse URLs and extract various components such as subdomain, domain, top-level domain (TLD), and port. It is particularly useful for scenarios where you need to analyze or manipulate URLs in your Go applications.

Features
  • Parse URLs and extract subdomain, domain, TLD, and port information.
  • Handles multiple subdomains extraction.
  • Handle edge cases gracefully.
  • Error handling for robustness.
  • Compatible with Go modules.

Installation

To use the tld package in your Go project, you can simply import it via Go modules:

go get github.com/zomasec/tld

Usage

Here's a basic example demonstrating how to use the tld package:

package main

import (
	"fmt"
	"github.com/zomasec/tld"
)

func main() {
	urlString := "https://subdomain1.subdomain2.example.com:8080/path/to/resource" // or you can use "subdomain1.subdomain2.subdomain3.example.com"
	parsedURL, err := tld.Parse(urlString)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	fmt.Println("Subdomains:", parsedURL.Subdomains)
	fmt.Println("Subdomain:", parsedURL.Subdomain)
	fmt.Println("Domain:", parsedURL.Domain)
	fmt.Println("TLD:", parsedURL.TLD)
	fmt.Println("Port:", parsedURL.Port)
}

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or create a pull request on GitHub.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type URL

type URL struct {
	*url.URL
	Subdomains []string
	Subdomain  string
	Domain     string
	TLD        string
	Port       string
}

URL embeds net/url.URL and adds additional fields for subdomains, domain, TLD, and port.

func Parse

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

Parse parses the input URL string or domain and returns a tld.URL, which contains extra fields for subdomains, domain, TLD, and port.

Jump to

Keyboard shortcuts

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