stupid proofing missing "http" in config file
This commit is contained in:
parent
75921ef7b5
commit
fb32f3532e
1 changed files with 20 additions and 7 deletions
|
@ -21,25 +21,38 @@ type URL struct {
|
||||||
Template string `xml:"template,attr"`
|
Template string `xml:"template,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// isLocalAddress checks if the domain is a local address
|
// 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 {
|
func isLocalAddress(domain string) bool {
|
||||||
return domain == "localhost" || strings.HasPrefix(domain, "127.") || strings.HasPrefix(domain, "192.168.") || strings.HasPrefix(domain, "10.")
|
return domain == "localhost" || strings.HasPrefix(domain, "127.") || strings.HasPrefix(domain, "192.168.") || strings.HasPrefix(domain, "10.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateOpenSearchXML(config Config) {
|
// Ensures that HTTP or HTTPS is befor the adress if needed
|
||||||
protocol := "https://"
|
func addProtocol(domain string) string {
|
||||||
if isLocalAddress(config.Domain) {
|
if hasProtocol(domain) {
|
||||||
protocol = "http://"
|
return domain
|
||||||
}
|
}
|
||||||
|
if isLocalAddress(domain) {
|
||||||
|
return "http://" + domain
|
||||||
|
}
|
||||||
|
return "https://" + domain
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateOpenSearchXML(config Config) {
|
||||||
|
baseURL := addProtocol(config.Domain)
|
||||||
|
|
||||||
opensearch := OpenSearchDescription{
|
opensearch := OpenSearchDescription{
|
||||||
Xmlns: "http://a9.com/-/spec/opensearch/1.1/",
|
Xmlns: "http://a9.com/-/spec/opensearch/1.1/",
|
||||||
ShortName: "Ocásek",
|
ShortName: "Search Engine",
|
||||||
Description: "Search engine",
|
Description: "Search engine",
|
||||||
Tags: "search, engine",
|
Tags: "search, engine",
|
||||||
URL: URL{
|
URL: URL{
|
||||||
Type: "text/html",
|
Type: "text/html",
|
||||||
Template: fmt.Sprintf("%s%s/search?q={searchTerms}", protocol, config.Domain),
|
Template: fmt.Sprintf("%s/search?q={searchTerms}", baseURL),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue