gurl is a Go library for inspecting, validating, and modifying URL components. It provides
focused helpers for query and fragment parameters, paths, hosts, protocols, file extensions, and
base URLs without performing network requests.
Go 1.19 or later is supported.
go get github.com/chengchuu/gurlimport "github.com/chengchuu/gurl"value, err := gurl.GetQueryParam("https://example.com/search?q=go&lang=en", "q")
if err != nil {
log.Fatal(err)
}
fmt.Println(value) // goRun the complete example with go run ./examples/basic.
The public API includes helpers to:
- get, set, and delete URL query parameters;
- get, set, and delete query-like parameters in URL fragments;
- read and replace paths, hosts, hostnames, and protocols;
- remove queries and fragments to obtain a base URL;
- read a file extension from a URL path; and
- check for a scheme and host with
CheckValid, or require anhttporhttpsscheme together with a host by usingCheckValidHTTPURL.
Functions that return an error pass through failures from Go's URL parser. URL setters serialize
their result with net/url; query serialization can normalize ordering and escaping.
- Public website
- Source-derived examples
- Generated API reference
- pkg.go.dev API documentation
- GitHub repository
- Basic example
The examples page renders examples/basic/main.go and example_test.go directly from checked-in Go
source. The API page extracts exported declarations and GoDoc from the module-root package.
Run package checks from the repository root:
gofmt -w .
go mod tidy
go test ./...
go test -race ./...
go vet ./...
go build ./...
go run ./examples/basicGenerate and validate the GitHub Pages artifact:
go run ./cmd/sitegen build
go run ./cmd/sitegen validatePreview the production-like site at http://127.0.0.1:4173/gurl/:
go run ./cmd/sitegen previewdist/pages is generated and ignored by Git. Update source configuration, GoDoc, templates, or
assets and rebuild instead of editing generated Pages files.
The Go package and project-authored website code are available under the MIT License. Vendored browser-asset notices are in guides/THIRD_PARTY_NOTICES.md.