This repository was archived by the owner on Jan 30, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
39 lines (34 loc) · 1.42 KB
/
utils.go
File metadata and controls
39 lines (34 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package pathmatch
import (
"github.com/tsdkv/pathmatch/internal/utils"
)
// Split splits a path string into its segments.
// It handles leading/trailing slashes and multiple slashes between segments.
// For example, Split("/users//alice/") returns ["users", "alice"].
// An empty path or a path consisting only of slashes results in an empty slice.
func Split(path string) []string {
return utils.Split(path)
}
// Join combines path segments into a single path string.
// It ensures segments are joined by a single slash and prepends a leading slash.
// If no segments are provided, it returns "/".
// Example: Join("users", "alice", "profile") returns "/users/alice/profile".
func Join(segments ...string) string {
return utils.Join(segments...)
}
// Clean normalizes a path string by removing redundant slashes and
// any trailing slash (unless it's the root path "/").
// For example, Clean("/users//alice///") returns "/users/alice".
// Clean("/") returns "/".
func Clean(path string) string {
return utils.Clean(path)
}
// CompileAndMatch parses the templatePattern string and then matches it against the given path.
// It's a convenience wrapper around ParseTemplate and Match.
func CompileAndMatch(templatePattern string, path string, opts ...MatchOption) (matched bool, vars map[string]string, err error) {
tmpl, err := ParseTemplate(templatePattern)
if err != nil {
return false, nil, err
}
return Match(tmpl, path, opts...)
}