Documentation
¶
Index ¶
- Variables
- func EncodeValues(v url.Values, escape bool) string
- type EncodeFlag
- type GnoURL
- func (gnoURL GnoURL) Encode(encodeFlags EncodeFlag) string
- func (gnoURL GnoURL) EncodeArgs() string
- func (gnoURL GnoURL) EncodeURL() string
- func (gnoURL GnoURL) EncodeWebURL() string
- func (gnoURL GnoURL) IsDir() bool
- func (gnoURL GnoURL) IsFile() bool
- func (gnoURL GnoURL) IsPure() bool
- func (gnoURL GnoURL) IsRealm() bool
- func (gnoURL GnoURL) IsValid() bool
Constants ¶
This section is empty.
Variables ¶
var ErrURLInvalidPath = errors.New("invalid path")
Functions ¶
func EncodeValues ¶
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 ¶
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 ¶
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 ¶
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 ¶
EncodeWebURL encodes the path, package arguments, web query, and query into a string. This function provides the full representation of the URL.