use errx and splinter packages

This commit is contained in:
juancwu 2026-04-25 20:41:52 +00:00
commit 75a4590f18
7 changed files with 95 additions and 26 deletions

View file

@ -1,6 +1,12 @@
package router
import "strings"
import (
"strings"
"git.juancwu.dev/juancwu/errx"
)
const groupOp = "router.Group"
func splitPattern(pattern string) (method, host, path string) {
rest := pattern
@ -22,10 +28,10 @@ func validateGroupPrefix(p string) {
return
}
if strings.ContainsAny(p, " \t") {
panic("lightmux: group prefix must not contain whitespace (no method or host allowed): " + p)
panic(errx.Newf(groupOp, "prefix must not contain whitespace (no method or host allowed): %q", p))
}
if !strings.HasPrefix(p, "/") {
panic("lightmux: group prefix must start with '/': " + p)
panic(errx.Newf(groupOp, "prefix must start with '/': %q", p))
}
}
@ -53,7 +59,7 @@ func joinPath(prefix, sub string) string {
return prefix + "/"
}
if !strings.HasPrefix(sub, "/") {
panic("lightmux: route path must start with '/': " + sub)
panic(errx.Newf(groupOp, "route path must start with '/': %q", sub))
}
return prefix + sub
}