Modify query parameters
Use SetQueryParam or DelQueryParam and check the serialized URL returned by the package.
Compiled, executable documentation
These examples come directly from checked-in Go source. Run them locally to exercise github.com/chengchuu/gurl; the website does not reimplement the package or send code to a remote execution service.
The generator reads this listing from examples/basic/main.go. It parses a query string with GetQueryParam and checks complete and incomplete HTTP URLs with CheckValidHTTPURL.
go run ./examples/basicExpected output
go
true
false// Command basic demonstrates query inspection with the public gurl package.
package main
import (
"fmt"
"log"
"github.com/chengchuu/gurl"
)
func main() {
value, err := gurl.GetQueryParam("https://example.com/search?q=go&lang=en", "q")
if err != nil {
log.Fatal(err)
}
fmt.Println(value)
fmt.Println(gurl.CheckValidHTTPURL("https://example.com"))
fmt.Println(gurl.CheckValidHTTPURL("https:"))
}
The source-derived ExampleGetQueryParam function is compiled, and go test ./... verifies its output comment. Use this pattern for documentation that must stay synchronized with runtime behavior.
go test ./...package gurl_test
import (
"fmt"
"github.com/chengchuu/gurl"
)
func ExampleGetQueryParam() {
value, err := gurl.GetQueryParam("https://example.com/search?q=go&lang=en", "q")
if err != nil {
panic(err)
}
fmt.Println(value)
// Output: go
}
func ExampleCheckValidHTTPURL() {
fmt.Println(gurl.CheckValidHTTPURL("https://example.com"))
fmt.Println(gurl.CheckValidHTTPURL("https:"))
// Output:
// true
// false
}
Use SetQueryParam or DelQueryParam and check the serialized URL returned by the package.
Use the hash-parameter helpers for fragments shaped like #route?key=value.
The generated API documentation lists every exported function and its current GoDoc.