path

package
v0.15.0-dev.26 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualLocation

func EqualLocation(a, b Location) bool

EqualLocation reports whether a and b encode the same path and query.

Types

type AnyModelAdapter added in v0.12.1

type AnyModelAdapter interface {
	EncodeAny(any) (Location, error, bool)
}

type Encoder added in v0.12.1

type Encoder interface {
	// Encode returns the location the model points to.
	Encode() (Location, error)
}

Encoder is implemented by models that build their own Location instead of describing their path with tags.

type HookMatch

type HookMatch struct {
	Instance string
	Hook     uint64
	Track    uint64
}

type Location

type Location struct {
	// Segments are the path segments, decoded and without the separating
	// slashes. Empty means the root path.
	Segments []string `json:"segments"`
	// Query holds the query parameters in decoded form. Empty means no query
	// string.
	Query url.Values `json:"query"`
}

Location is a URL path plus query string, held in decoded form.

func Encode added in v0.12.1

func Encode(m any) (Location, error)

Encode returns the Location for m.

m may be a Location, a value implementing Encoder, a path model struct, or a pointer to one. It returns an error if m is none of these, if its path tags are invalid, or if it does not encode to a complete path.

func NewLocationFromEscapedURI

func NewLocationFromEscapedURI(s string) Location

NewLocationFromEscapedURI parses s into a Location. If s is not a valid URL reference, it returns the zero Location.

func NewLocationFromURL

func NewLocationFromURL(u *url.URL) Location

NewLocationFromURL decodes u into a Location.

func (Location) Clone added in v0.12.10

func (l Location) Clone() Location

Clone returns a deep copy of l with independent Segments and Query.

func (Location) MarshalJSON added in v0.15.0

func (l Location) MarshalJSON() ([]byte, error)

MarshalJSON encodes nil Segments and Query as empty containers instead of null.

func (Location) Path

func (l Location) Path() string

Path returns the escaped path with a leading slash and without the query string.

func (Location) String

func (l Location) String() string

String returns the escaped path with a leading slash, followed by the encoded query string when Query is not empty.

type Match

type Match struct {
	// contains filtered or unexported fields
}

func (Match) Hook

func (m Match) Hook() (HookMatch, bool)

func (Match) Resource

func (m Match) Resource() (id string, ok bool)

func (Match) Sync

func (m Match) Sync() (instanceID string, ok bool)

func (Match) Undo

func (m Match) Undo() (UndoPath, bool)

type ModelAdapter added in v0.12.1

type ModelAdapter[M any] adapter

ModelAdapter decodes locations into path model M and encodes M back.

func GetModelAdapter added in v0.12.1

func GetModelAdapter[M any]() (ModelAdapter[M], error)

GetModelAdapter returns the ModelAdapter for path model M. It returns an error if M is not a struct or its path tags are missing or invalid.

func (ModelAdapter[M]) Decode added in v0.12.1

func (ma ModelAdapter[M]) Decode(l Location) (*M, bool)

Decode returns the model decoded from l, and false if l matches no path variant of M.

func (ModelAdapter[M]) Encode added in v0.12.1

func (ma ModelAdapter[M]) Encode(m *M) (Location, error)

Encode returns the location for m, or an error if m selects no path variant or leaves a path capture empty.

type PathMaker

type PathMaker struct {
	// contains filtered or unexported fields
}

func NewPathMaker

func NewPathMaker(prefix string, serverID string, serverIDCookieName string) PathMaker

func (PathMaker) Hook

func (pm PathMaker) Hook(instanceId string, hookId uint64, name string) string

func (PathMaker) ID

func (pm PathMaker) ID() string

func (PathMaker) IsSystem added in v0.13.13

func (pm PathMaker) IsSystem(r *http.Request) bool

func (PathMaker) Match

func (pm PathMaker) Match(r *http.Request) (Match, bool)

func (PathMaker) Prefix

func (pm PathMaker) Prefix() string

func (PathMaker) Resource

func (pm PathMaker) Resource(r *resources.Resource, name string) string

func (PathMaker) ServerIDCookieName added in v0.13.10

func (pm PathMaker) ServerIDCookieName() string

func (PathMaker) SessionCookie added in v0.12.1

func (pm PathMaker) SessionCookie() string

func (PathMaker) SetServerIDCookie added in v0.13.10

func (pm PathMaker) SetServerIDCookie() bool

type UndoPath

type UndoPath struct {
	Instance string
	Location Location
}

Jump to

Keyboard shortcuts

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