Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/grongor/go-url-parser

Simple library/CLI utility for parsing URLs (who wants to mess with sed/awk/cut/...). Supports "template" formatting.
https://github.com/grongor/go-url-parser

cli go golang parser unix url url-parser

Last synced: 4 months ago
JSON representation

Simple library/CLI utility for parsing URLs (who wants to mess with sed/awk/cut/...). Supports "template" formatting.

Awesome Lists containing this project

README

        

url-parser
==========

```
url-parser
Parses given URLs and prints the desired parts of them.

Usage:
url-parser [url]...

Options:
-c, --component=COMPONENT

Prints single URL component from each. URL.

Valid values: scheme, authority, auth, user, password,
hostport, host, tld, port, path, query,
fragment, basePath, file, ext, relativeUrl

Additionally, some components may be further formatted:
host:x, host:x:y print only desired (sub)domains
hostport:x, hostport:x:y same as host:*, but also includes port
path:x, path:x:y print only desired parts of the path
query:NAME print only query parameter named NAME
fragment:NAME print only fragment part named NAME

x starting position; use -x to start from end
y count; how many parts of the component you want to print

-f, --format=FORMAT

Prints URLs formatted according to FORMAT.

FORMAT is an arbitrary string containing component placeholders
enclosed in curly brackets. Each {COMPONENT} will be replaced
as if url-parser was called with option -c COMPONENT

Examples:

reference URL: https://www.example.com/lorem/ipsum/dolor/sit.html?metus=lectus#at=nostra&unde=omnis

url-parser -c host:1 example.com
url-parser -c path:-0:2 /dolor/sit.html
url-parser -c path:-1 /lorem/ipsum/dolor
url-parser -c path:0:2 /lorem/ipsum
url-parser -c fragment:unde unde=omnis
url-parser -c relativeUrl /lorem/ipsum/dolor/sit.html?metus=lectus#at=nostra&unde=omnis
url-parser -f {scheme}://{host} https://www.example.com
```