This commit is contained in:
partisan 2024-08-08 16:49:30 +02:00
parent fb32f3532e
commit c594c93559
4 changed files with 183 additions and 173 deletions

View file

@ -4,7 +4,6 @@ import (
"encoding/xml"
"fmt"
"os"
"strings"
)
type OpenSearchDescription struct {
@ -21,27 +20,6 @@ type URL struct {
Template string `xml:"template,attr"`
}
// Checks if the URL already includes a protocol
func hasProtocol(url string) bool {
return strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://")
}
// Checks if the domain is a local address
func isLocalAddress(domain string) bool {
return domain == "localhost" || strings.HasPrefix(domain, "127.") || strings.HasPrefix(domain, "192.168.") || strings.HasPrefix(domain, "10.")
}
// Ensures that HTTP or HTTPS is befor the adress if needed
func addProtocol(domain string) string {
if hasProtocol(domain) {
return domain
}
if isLocalAddress(domain) {
return "http://" + domain
}
return "https://" + domain
}
func generateOpenSearchXML(config Config) {
baseURL := addProtocol(config.Domain)