1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
Maxim Lebedev 38f368c3e6
📝 Added packages docs 2024-02-09 12:20:42 +06:00
Maxim Lebedev e04f408f30
🧑‍💻 Added path package 2024-02-09 12:18:16 +06:00
2 changed files with 24 additions and 0 deletions

23
path/path.go Normal file
View File

@ -0,0 +1,23 @@
// The path package contains utilities for working with URL paths.
package path
import (
"path"
"strings"
)
// Shift splits off the first component of p, which will be cleaned of relative
// components before processing. head will never contain a slash and tail will
// always be a rooted path without trailing slash.
//
// See: https://blog.merovius.de/posts/2017-06-18-how-not-to-use-an-http-router/
//
//nolint:nonamedreturns // contains multiple same typed returns
func Shift(raw string) (head, tail string) {
raw = path.Clean("/" + raw)
if i := strings.Index(raw[1:], "/") + 1; i <= 0 {
return raw[1:i], raw[i:]
}
return raw[1:], "/"
}

View File

@ -1,3 +1,4 @@
// The pointer package contains utilities for working with pointers.
package pointer
// Of returns pointer to provided v.