Perform validation on YP instance URL value

This commit is contained in:
Gabe Kangas 2020-11-05 09:20:33 -08:00
parent 6f6971f482
commit 133745efd7

View File

@ -4,6 +4,7 @@ import (
"bytes"
"io/ioutil"
"net/http"
"net/url"
"os"
"time"
@ -66,6 +67,15 @@ func (yp *YP) Stop() {
func (yp *YP) ping() {
myInstanceURL := config.Config.YP.InstanceURL
isValidInstanceURL := isUrl(myInstanceURL)
if myInstanceURL == "" || !isValidInstanceURL {
if !_inErrorState {
log.Warnln("YP Error: unable to use", myInstanceURL, "as a public instance URL. Fix this value in your configuration.")
}
_inErrorState = true
return
}
key := yp.getSavedKey()
log.Traceln("Pinging YP as: ", config.Config.InstanceDetails.Name)
@ -142,3 +152,7 @@ func DisplayInstructions() {
text := "Your instance can be listed on the Owncast directory at http://directory.owncast.online by enabling YP in your config. Learn more at https://directory.owncast.online/get-listed."
log.Debugln(text)
}
func isUrl(str string) bool {
u, err := url.Parse(str)
return err == nil && u.Scheme != "" && u.Host != ""
}