28 lines
431 B
Go
28 lines
431 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
type SafePathable string
|
|
|
|
var ErrorInvalidRequest = errors.New("invalid request")
|
|
|
|
func (s SafePathable) Validate() error {
|
|
if strings.HasPrefix(string(s), "/") {
|
|
return ErrorInvalidRequest
|
|
}
|
|
if strings.HasPrefix(string(s), "internal/") {
|
|
return ErrorInvalidRequest
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s SafePathable) Path() *url.URL {
|
|
return &url.URL{
|
|
Path: string(s),
|
|
}
|
|
}
|