weburl

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 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/demo/users
	Args     string     // jae
	WebQuery url.Values // help&a=b
	Query    url.Values // c=d
	File     string     // render.gno
}

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

func ParseGnoURL

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

ParseGnoURL parses a URL into a GnoURL structure, extracting and validating its components.

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) 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.

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 represents a pure path.

func (GnoURL) IsRealm

func (gnoURL GnoURL) IsRealm() bool

IsRealm checks if the URL path represents a realm path.

func (GnoURL) IsValid

func (gnoURL GnoURL) IsValid() bool

Jump to

Keyboard shortcuts

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