Skip to content
chengchuuPublic

About

A Go library for URL Manipulation and Validation

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

gurl

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.

Install

Go 1.19 or later is supported.

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

Usage

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

Run 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 an http or https scheme together with a host by using CheckValidHTTPURL.

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.

Documentation

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.

Development

Run package checks from the repository root:

gofmt -w .
go mod tidy
go test ./...
go test -race ./...
go vet ./...
go build ./...
go run ./examples/basic

Generate and validate the GitHub Pages artifact:

go run ./cmd/sitegen build
go run ./cmd/sitegen validate

Preview the production-like site at http://127.0.0.1:4173/gurl/:

go run ./cmd/sitegen preview

dist/pages is generated and ignored by Git. Update source configuration, GoDoc, templates, or assets and rebuild instead of editing generated Pages files.

License

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.

About

A Go library for URL Manipulation and Validation

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages