url-parser

command module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

URL Parser

A simple command-line tool written in Go to extract specific components from a given URL. Especially useful in Bash scripts or automation workflows where URL processing is required.

Features

  • Extract various components of a URL, including:
    • Host
    • Domain
    • Subdomain
    • Top-level domain (TLD)
    • Port
    • Path
    • Fragment
    • Scheme (protocol)
    • Registered domain from a subdomain (domain.tld)
    • Query parameter values

Installation

Download the latest binary
wget

Use wget to download pre-compiled binaries:

For instance, VERSION=v1.0.0 and BINARY=url-parser-linux-amd64

Plain binary
wget https://github.com/singh-inder/url-parser/releases/download/${VERSION}/${BINARY} -O /usr/bin/url-parser &&\
    chmod +x /usr/bin/url-parser
Latest version
wget https://github.com/singh-inder/url-parser/releases/latest/download/url-parser-linux-amd64 -O /usr/bin/url-parser &&\
    chmod +x /usr/bin/url-parser

Usage

url-parser --url <URL> --get <component>
Required Flags
  • --url: The URL to parse. Example: https://example.com.
  • --get: The component to extract. Options:
    • host: url host (port number if present is included) (e.g., subdomain.example.com:1234)
    • hostWithoutPort: url host (port number removed) (eg., subdomain.example.com)
    • domain: Domain name (e.g., example)
    • subdomain: Subdomain (e.g., sub)
    • tld: Top-level domain (e.g., com)
    • port: Port (if specified, e.g., 8080)
    • path: URL path (e.g., /path/to/resource)
    • fragment: Fragment (e.g., section1)
    • scheme: URL scheme (e.g., https)
    • registeredDomain: Registered domain from a subdomain (e.g., example.com)
    • query.<paramName>: Value of a specific query parameter (e.g., query.user extracts the value of the user parameter).
Examples
Extract the domain from a URL:
url-parser --url "https://sub.example.com/path?user=123" --get domain
# Output: example
Get the value of a query parameter:
url-parser --url "https://example.com/path?user=123" --get query.user
# Output: 123
Extract the TLD:
url-parser --url "https://example.com" --get tld
# Output: com
Extract the scheme:
url-parser --url "https://example.com" --get scheme
# Output: https
Extract the full host:
url-parser --url "https://sub.example.com" --get host
# Output: sub.example.com
Extract the registered domain from a subdomain:
url-parser --url "https://sub.example.com" --get registeredDomain
# Output: example.com

Contributing

Feel free to submit issues or create pull requests to improve the project. Contributions are always welcome!

License

This project is licensed under the MIT License.

Acknowledgments

This cli uses go-tld package for extracting URL components.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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