URL helpers for Go

gurl

A Go library for inspecting, validating, and modifying URL components.

Install
go get github.com/chengchuu/gurl

Install the package

Use Go 1.19 or later. The public package lives at the module root, so the install and import paths are identical.

go get github.com/chengchuu/gurl
import "github.com/chengchuu/gurl"

Read a query parameter

Pass a URL and key to GetQueryParam. The helper parses the URL with Go's standard library and returns the first value for that key.

Open the complete basic example
value, err := gurl.GetQueryParam(
    "https://example.com/search?q=go&lang=en",
    "q",
)
if err != nil {
    log.Fatal(err)
}
fmt.Println(value) // go

Verified package capabilities

Each operation works on URL strings in memory; the package does not send network requests.

Query and fragment parameters

Get, set, or delete standard query parameters and query-like parameters inside URL fragments.

URL components

Read or replace paths, hosts, hostnames, and protocols while preserving other parsed components.

Inspection and validation

Check schemes and hosts, read path file extensions, or remove a URL's query and fragment.

API preview

The full reference is generated from exported Go declarations and GoDoc comments.

Requires Go 1.19 or later and is available under the MIT License. Read the package on pkg.go.dev.