clean up
This commit is contained in:
parent
fb32f3532e
commit
c594c93559
4 changed files with 183 additions and 173 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue