weburl

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrURLInvalidPath = errors.New("invalid path")

Functions

func EncodeValues

func EncodeValues(v url.Values, escape bool) string

EncodeValues generates a URL-encoded query string from the given url.Values. This function is a modified version of Go's `url.Values.Encode()`: https://pkg.go.dev/net/url#Values.Encode It takes an additional `escape` boolean argument that disables escaping on keys and values. Additionally, if an empty string value is passed, it omits the `=` sign, resulting in `?key` instead of `?key=` to enhance URL readability.

Types

type EncodeFlag

type EncodeFlag int

EncodeFlag is used to specify which URL components to encode.

const (
	EncodeDomain   EncodeFlag = 1 << iota // Encode the domain component
	EncodePath                            // Encode the path component
	EncodeArgs                            // Encode the arguments component
	EncodeWebQuery                        // Encode the web query component
	EncodeQuery                           // Encode the query component
	EncodeNoEscape                        // Disable escaping of arguments
)

func (EncodeFlag) Has

func (f EncodeFlag) Has(flags EncodeFlag) bool

Has checks if the EncodeFlag contains all the specified flags.

type GnoURL

type GnoURL struct {
	Domain   string     // gno.land
	Path     string     // /r/gnoland/users/v1
	Args     string     // jae
	WebQuery url.Values // help&a=b
	Query    url.Values // c=d
	File     string     // render.gno
	Origin   string     // https://gno.land
}

GnoURL decomposes the parts of an URL to query a realm.

func Parse

func Parse(u string) (gnourl *GnoURL, err error)

func ParseFromURL

func ParseFromURL(u *url.URL) (*GnoURL, error)

ParseFromURL parses a URL into a GnoURL structure, extracting and validating its components. Grammar: `<path>[:<args>][$<webargs>]`. The `$` split runs first so a literal `:` inside webargs (e.g. ObjectID `<hash>:<n>`) stays in the webargs and doesn't corrupt the path-args split.

func (GnoURL) Clone

func (gnoURL GnoURL) Clone() GnoURL

Clone returns a deep copy with independent WebQuery and Query maps, safe for mutation without aliasing the original. Slice values inside the maps are *not* deep-copied — fine for our usage where each value is a small `[]string` we treat as immutable.

func (GnoURL) Encode

func (gnoURL GnoURL) Encode(encodeFlags EncodeFlag) string

Encode constructs a URL string from the components of a GnoURL struct, encoding the specified components based on the provided EncodeFlag bitmask.

The function selectively encodes the URL's path, arguments, web query, and query parameters, depending on the flags set in encodeFlags.

Returns a string representing the encoded URL.

Example:

gnoURL := GnoURL{
    Domain: "gno.land",
    Path:   "/r/demo/users",
    Args:   "john",
    File:   "render.gno",
}

encodedURL := gnoURL.Encode(EncodePath | EncodeArgs)
fmt.Println(encodedURL) // Output: /r/demo/users/render.gno:john

URL components are encoded using url.PathEscape unless EncodeNoEscape is specified.

func (GnoURL) EncodeArgs

func (gnoURL GnoURL) EncodeArgs() string

EncodeArgs encodes the arguments and query parameters into a string. This function is intended to be passed as a realm `Render` argument.

func (GnoURL) EncodeFormURL

func (gnoURL GnoURL) EncodeFormURL() string

EncodeFormURL encodes the URL for form redirects. Slashes remain encoded (%2F) to prevent browser path normalization attacks.

func (GnoURL) EncodeURL

func (gnoURL GnoURL) EncodeURL() string

EncodeURL encodes the path, arguments, and query parameters into a string. This function provides the full representation of the URL without the web query.

func (GnoURL) EncodeWebURL

func (gnoURL GnoURL) EncodeWebURL() string

EncodeWebURL encodes the path, package arguments, web query, and query into a string. This function provides the full representation of the URL. Slashes in args are unescaped for readability.

func (GnoURL) Height

func (gnoURL GnoURL) Height() int64

Height returns the historical block height the URL is pinned to, reading from either WebQuery (gnoweb's native `$state&height=N` syntax) or the standard Query (browser GET form produces `?height=N`). WebQuery wins when both are set. Returns 0 when missing/invalid/non-positive — i.e. "latest height".

func (GnoURL) IsDir

func (gnoURL GnoURL) IsDir() bool

IsDir checks if the URL path represents a directory.

func (GnoURL) IsFile

func (gnoURL GnoURL) IsFile() bool

IsFile checks if the URL path represents a file.

func (GnoURL) IsPure

func (gnoURL GnoURL) IsPure() bool

IsPure checks if the URL path prefix represents a pure path.

func (GnoURL) IsRealm

func (gnoURL GnoURL) IsRealm() bool

IsRealm checks if the URL path prefix represents a realm path.

func (GnoURL) IsUser

func (gnoURL GnoURL) IsUser() bool

IsUser checks if the URL path prefix represents a user path.

func (GnoURL) IsValidPath

func (gnoURL GnoURL) IsValidPath() bool

IsValidPath checks that path is a valid Gno.land URL path. It just validates that the path format can match with Gno.land URL paths, but it doesn't validate semantics, like "/r/", "/p/", etc; Use `IsPure()`, `IsRealm()` or similar methods to check for specific URL path cases.

func (GnoURL) Namespace

func (gnoURL GnoURL) Namespace() string

Extract the package name from the Gno.land URL path (e.g., "/r/test/foo" -> "test")

func (GnoURL) Username

func (gnoURL GnoURL) Username() string

Extract the username from the path (e.g., "/u/alice" -> "alice")

func (GnoURL) WithHeight

func (gnoURL GnoURL) WithHeight(h int64) GnoURL

WithHeight returns a clone with the height parameter set in the WebQuery (gnoweb-native form). When `h <= 0`, equivalent to WithoutHeight (strips the parameter from both maps).

func (GnoURL) WithoutHeight

func (gnoURL GnoURL) WithoutHeight() GnoURL

WithoutHeight returns a clone with the height parameter stripped from both WebQuery and Query. Used to build the "go back to live" link when the page is pinned to a historical block.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL