virtualpath

package
v2.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSegments = errors.New("invalid multi-segment virtual path")

ErrInvalidSegments reports a multi-segment virtual path that is not in its canonical form, or a segment that cannot be part of one.

Functions

func ContainsControlChar

func ContainsControlChar(s string) bool

ContainsControlChar checks if a string contains any control characters (0x00-0x1F, 0x7F) Returns true if control characters are found (invalid for URLs)

func CreateVirtualPath

func CreateVirtualPath(scheme, id, name string) string

CreateVirtualPath creates a properly encoded virtual path for media Example: "kodi-show", "123", "Some Hot/Cold" -> "kodi-show://123/Some%20Hot%2FCold" Both id and name are URL-encoded to ensure round-trip compatibility with ParseVirtualPathStr Note: Simple alphanumeric IDs like "123" or "monkey1" remain unchanged after encoding

func CreateVirtualPathSegments added in v2.19.0

func CreateVirtualPathSegments(scheme, id string, segments []string) (string, error)

CreateVirtualPathSegments builds scheme://id/seg/.../seg, escaping the ID and each segment on its own. The result is the canonical form that ParseVirtualPathSegments accepts.

func ExtractSchemeID

func ExtractSchemeID(virtualPath, expectedScheme string) (string, error)

ExtractSchemeID extracts the ID component from a scheme-based virtual path with proper URL decoding. Returns error if the path doesn't match the expected scheme. Example: ExtractSchemeID("steam://123/Game%20Name", "steam") -> "123", nil

func IsValidScheme

func IsValidScheme(scheme string) bool

IsValidScheme validates that a scheme follows RFC 3986 rules: - Must start with a letter - Can contain letters, digits, '+', '-', '.'

func ValidSegment added in v2.19.0

func ValidSegment(name string) bool

ValidSegment reports whether name can be one segment of a multi-segment virtual path: non-empty, not "." or "..", valid UTF-8, bounded, and free of control characters and path separators.

Types

type SegmentsResult added in v2.19.0

type SegmentsResult struct {
	Scheme   string
	ID       string
	Segments []string
}

SegmentsResult is a parsed multi-segment virtual path.

func ParseVirtualPathSegments added in v2.19.0

func ParseVirtualPathSegments(value string) (SegmentsResult, error)

ParseVirtualPathSegments splits a multi-segment virtual path into its scheme, ID and decoded segments. It accepts only the canonical form, so a value that parses is byte-identical to the one CreateVirtualPathSegments would make: two spellings of one media item cannot both be stored.

type URIComponents

type URIComponents struct {
	Scheme string
	Rest   string // Everything after ://
	Query  string
}

URIComponents holds parsed URI components

func ParseURIComponents

func ParseURIComponents(uri string) URIComponents

ParseURIComponents manually parses a URI into its components Note: Does not extract fragments - they remain part of name/query for custom schemes Returns empty result if URI contains control characters or has invalid scheme

type VirtualPathResult

type VirtualPathResult struct {
	Scheme string
	ID     string
	Name   string
}

VirtualPathResult holds parsed virtual path components

func ParseVirtualPathStr

func ParseVirtualPathStr(virtualPath string) (VirtualPathResult, error)

ParseVirtualPathStr parses a virtual path and returns its components with string ID Virtual path format: scheme://id/name (e.g., "steam://123/Game%20Name") Maps to URL structure: scheme://host/path where host=id, path=name Uses manual parsing to handle malformed URLs gracefully

Jump to

Keyboard shortcuts

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