searxng-mcp-go/internal/searxng/urlcheck.go
xlion-bot-renovate[bot] 6e4c553a9e
chore(deps): update dependency go to v1.27.1 (#588)
* chore(deps): update dependency go to v1.27.1

* Fixed all lints; just verify passes.

Co-authored-by: xlionjuan <[email protected]>

* Fixed `.golangci.yml` paths→path; `just verify` passes.

Co-authored-by: xlionjuan <[email protected]>

* Parallelized golden & error-path tests; verify passes.

Co-authored-by: xlionjuan <[email protected]>

* Verify passes; HTTPClient/Logger nil set; exhaustruct covers Config.

Co-authored-by: xlionjuan <[email protected]>

---------

Co-authored-by: xlion-bot-renovate[bot] <218815870+xlion-bot-renovate[bot]@users.noreply.github.com>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: xlionjuan <[email protected]>
2026-09-06 23:14:09 +08:00

41 lines
952 B
Go

package searxng
import (
"errors"
"fmt"
"net/url"
)
var (
errBaseURLEmpty = errors.New("baseurl cannot be empty")
errInvalidURL = errors.New("invalid URL")
errUnsupportedURLScheme = errors.New("url must use http or https scheme")
errURLMissingHost = errors.New("url must include a host (e.g., search.example.com)")
errURLHasUserInfo = errors.New("url must not contain userinfo (user:password@host)")
)
// validateBaseURL checks that the baseURL is valid and returns an error if not.
func validateBaseURL(baseURL string) error {
if baseURL == "" {
return errBaseURLEmpty
}
parsed, err := url.Parse(baseURL)
if err != nil {
return fmt.Errorf("%w: %w", errInvalidURL, err)
}
if parsed.Scheme != schemeHTTP && parsed.Scheme != schemeHTTPS {
return errUnsupportedURLScheme
}
if parsed.Host == "" {
return errURLMissingHost
}
if parsed.User != nil {
return errURLHasUserInfo
}
return nil
}