domainer

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 4 Imported by: 1

README

domainer

Go Reference

Simple Go library to split URLs into their domain parts.

Installation

go get github.com/boatware/domainer

Usage

package main

import (
    "fmt"

    "github.com/boatware/domainer"
)

func main() {
    url := "http://www.example.com:8080/path/to/file.html?query=string#fragment"

    d, _ := domainer.FromString(url)

    fmt.Println(d.Protocol) // http
    fmt.Println(d.Subdomain) // www
    fmt.Println(d.Domain) // example
    fmt.Println(d.TLD) // com
    fmt.Println(d.Port) // 8080
    fmt.Println(d.Path) // path/to/file.html
    fmt.Println(d.Query) // []Query{ Query{ Key: "query", Value: "string" } }
    fmt.Println(d.Fragment) // fragment
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Query

type Query struct {
	// Key is the key of the query.
	// Example: "q" in "https://example.com/search?q=hello+world"
	Key string `json:"key"`

	// Value is the value of the query.
	// Example: "hello+world" in "https://example.com/search?q=hello+world"
	Value string `json:"value"`
}

Query is a key-value pair used in a URL query string.

type URL

type URL struct {
	// FullURL represents the full domain name this struct has been created with.
	// Example: "https://www.example.com:443/search?q=hello+world#test"
	FullURL string `json:"full_url"`

	// Protocol represents the protocol used to access the domain.
	// Example: "https" in "https://www.example.com:443/search?q=hello+world#test"
	Protocol string `json:"protocol"`

	// Subdomain represents the subdomain of the domain.
	// Example: "www" in "https://www.example.com:443/search?q=hello+world#test"
	Subdomain string `json:"subdomain"`

	// Hostname represents the hostname of the domain.
	// Example: "example.com" in "https://www.example.com:443/search?q=hello+world#test"
	Hostname string `json:"hostname"`

	// Domain represents the domain name (or second level domain).
	// Example: "example" in "https://www.example.com:443/search?q=hello+world#test"
	Domain string `json:"domain"`

	// TLD represents the top level domain.
	// Example: "com" in "https://www.example.com:443/search?q=hello+world#test"
	TLD string `json:"tld"`

	// Port represents the port used to access the domain.
	// Example: 443 in "https://www.example.com:443/search?q=hello+world#test"
	Port int `json:"port"`

	// Path represents the path used to access the domain.
	// Example: "/search" in "https://www.example.com:443/search?q=hello+world#test"
	Path string `json:"path"`

	// Query represents the query used to access the domain.
	// Example: []Query{{"q", "hello+world"}} in "https://www.example.com:443/search?q=hello+world#test"
	Query []Query `json:"query"`

	// Fragment represents the fragment used to access the domain.
	// Example: "test" in "https://www.example.com:443/search?q=hello+world#test"
	Fragment string `json:"fragment"`

	// Username represents the username used to access the domain.
	// Example: "user" in "https://user:pass@example.com:443/search?q=hello+world#test"
	Username string `json:"username"`

	// Password represents the password used to access the domain.
	// Example: "pass" in "https://user:pass@example.com:443/search?q=hello+world#test"
	Password string `json:"password"`

	// IPAddress represents the IP address the domain resolves to.
	// Example: "127.0.0.1" (obviously not a real server IP address)
	IPAddress string `json:"ip_address"`
}

URL is a split of a given domain name.

func FromString

func FromString(url string) (*URL, error)

FromString parses a given domain name and returns a URL struct.

Jump to

Keyboard shortcuts

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