mirror of
https://github.com/xlionjuan/searxng-mcp-go.git
synced 2026-11-17 04:17:51 +00:00
* 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]>
41 lines
952 B
Go
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
|
|
}
|