pathregex

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanPath

func CleanPath(p string) string

CleanPath is the URL version of path.Clean, it returns a canonical URL path for p, eliminating . and .. elements.

The following rules are applied iteratively until no further processing can be done:

  1. Replace multiple slashes with a single slash.
  2. Eliminate each . path name element (the current directory).
  3. Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
  4. Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path.

If the result of this process is an empty string, "/" is returned

func CompilePath

func CompilePath(path string, caseSensitive bool, end bool) (*regexp.Regexp, []string)

CompilePath compile usual HTTP endpoint path to a canonical regex based path for categorizing exact endpoint path, wildcard and path params. It output the canonical regular expression to match the path, and the path param names The following process are applied:

  1. Remove / ignore trailing / and /*

  2. Adding a leading / to ensure canonical path had leading /

  3. Remove all special meta character in the path (via regex QuoteMeta)

  4. Escape all / into \\/

  5. Extract all path param (ex: /path/:id => id is path param)

  6. Also extract if wildcards exist in path (ex: /path/*)

func ExtractPathParam

func ExtractPathParam(path string, pattern string) map[string]string

func MatchPath

func MatchPath(path string, pattern string) bool

MatchPath applies mathing between HTTP path and canonical path to check whether the pattern match / not.

It output the matching result (boolean), and the path param resolved values

Types

This section is empty.

Jump to

Keyboard shortcuts

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