boatware / domainer

Go library to split a URL into its parts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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
}

About

Go library to split a URL into its parts

License:MIT License


Languages

Language:Go 100.0%