mirror of
https://github.com/lukaszraczylo/mcp-readitall.git
synced 2026-10-16 01:07:59 +00:00
initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// jsQuote produces a JS-safe string literal from a CSS selector. We
|
||||
// assume selectors do not contain backslashes or newlines (which would
|
||||
// be invalid CSS) and just JSON-encode the value, which is a valid JS
|
||||
// double-quoted string.
|
||||
func jsQuote(s string) string {
|
||||
b, _ := json.Marshal(s)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// hostOf extracts the scheme-less host (with port) from a URL string.
|
||||
// It returns "unknown" for inputs that do not parse to a URL with a
|
||||
// host, rather than panicking. Case is preserved — url.Parse does not
|
||||
// normalise the host — so "Example.COM" stays "Example.COM".
|
||||
func hostOf(rawURL string) string {
|
||||
u, err := url.Parse(rawURL)
|
||||
if err != nil || u.Host == "" {
|
||||
return "unknown"
|
||||
}
|
||||
return u.Host
|
||||
}
|
||||
Reference in New Issue
Block a user