Initial refactor of settings.
Signed-off-by: Odyssey <odyssey346@disroot.org>
This commit is contained in:
38
utils/checkconfig.go
Normal file
38
utils/checkconfig.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// Please ignore my terrible code :) It works
|
||||
package utils
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/ProjectSegfault/segfautils/config"
|
||||
)
|
||||
|
||||
func CheckConfig() {
|
||||
if config.Port() == "0" {
|
||||
log.Fatal("[Segfautils] ❌ You need to set the port you'd like to use in the config file. Check documentation for more information.")
|
||||
} else {
|
||||
log.Println("[Segfautils] ✅ segfautils.port is set to", config.Port())
|
||||
}
|
||||
if config.AuthToken() == "YOURAUTHTOKEN" || config.AuthToken() == "" {
|
||||
log.Fatal("[Segfautils] ❌ You need to set the authentication token you'd like to use in the config file. Check documentation for more information.")
|
||||
} else {
|
||||
log.Println("[Segfautils] ✅ segfautils.auth_token is set!")
|
||||
}
|
||||
if config.WebhookURL() == "YOURWEBHOOKURL" || config.WebhookURL() == "" {
|
||||
log.Fatal("[Segfautils] ❌ You need to set the Webhook URL you'd like to use in the config file. Check documentation for more information.")
|
||||
} else {
|
||||
log.Println("[Segfautils] ✅ segfautils.webhook_url is set!")
|
||||
}
|
||||
// Hcaptcha stuff
|
||||
if config.HCaptchaSecretKey() == "YOURSECRETKEY" || config.HCaptchaSecretKey() == "" {
|
||||
log.Fatal("[Segfautils] ❌ You need to set the HCaptcha secret you'd like to use in the config file. Check documentation for more information.")
|
||||
} else {
|
||||
log.Println("[Segfautils] ✅ segfautils.hcaptcha_secret is set!")
|
||||
}
|
||||
if config.HCaptchaSiteKey() == "YOURSITEKEY" || config.HCaptchaSiteKey() == "" {
|
||||
log.Println("[Segfautils] ⚠️ The HCaptcha site key isn't set. You don't have to, but the demo form will not work without it. Check documentation for more information.")
|
||||
} else {
|
||||
log.Println("[Segfautils] ✅ hcaptcha.site_key is set!")
|
||||
}
|
||||
log.Println("[Segfautils] ✅ All config checks passed!")
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
// Please ignore my terrible code :) It works
|
||||
package utils
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
unused string
|
||||
ok1 bool
|
||||
)
|
||||
|
||||
func CheckEnv() {
|
||||
unused, ok1 = os.LookupEnv("SEGFAUTILS_PORT")
|
||||
if ok1 {
|
||||
log.Println("[Segfautils] Environment variable SEGFAUTILS_PORT is set as " + unused)
|
||||
} else {
|
||||
log.Fatal("[Segfautils] Environment variable SEGFAUTILS_PORT is not set! Please set it to a number, for example 6893")
|
||||
}
|
||||
unused, ok1 = os.LookupEnv("HCAPTCHA_SITE_KEY")
|
||||
if !ok1 || unused == "YOURSITEKEY" {
|
||||
log.Println("[Segfautils] Environment variable HCAPTCHA_SITE_KEY is not not set. It isn't required to be set, but without it, the example form will not work.")
|
||||
} else {
|
||||
log.Println("[Segfautils] Environment variable HCAPTCHA_SITE_KEY is set as " + unused)
|
||||
}
|
||||
unused, ok1 = os.LookupEnv("HCAPTCHA_SECRET_KEY")
|
||||
if !ok1 || unused == "YOURSECRETKEY" {
|
||||
log.Fatal("[Segfautils] Environment variable HCAPTCHA_SECRET_KEY is not set! Please set it to the secret key you got from hCaptcha.")
|
||||
} else {
|
||||
log.Println("[Segfautils] Environment variable HCAPTCHA_SECRET_KEY is set!")
|
||||
}
|
||||
unused, ok1 = os.LookupEnv("SEGFAUTILS_WEBHOOK_URL")
|
||||
if !ok1 || unused == "YOURWEBHOOKURL" {
|
||||
log.Fatal("[Segfautils] Environment variable SEGFAUTILS_WEBHOOK_URL is not set! Please set it to your webhook URL. If that URL doesn't work, make an issue on GitHub!")
|
||||
} else {
|
||||
log.Println("[Segfautils] Environment variable SEGFAUTILS_WEBHOOK_URL is set!")
|
||||
}
|
||||
unused, ok1 = os.LookupEnv("SEGFAUTILS_AUTHTOKEN")
|
||||
if !ok1 || unused == "YOURAUTHTOKEN" {
|
||||
log.Fatal("[Segfautils] Environment variable SEGFAUTILS_AUTHTOKEN is not set! Please set it to a token you'd like to use for authorizing actions like announcements.")
|
||||
} else {
|
||||
log.Println("[Segfautils] Environment variable SEGFAUTILS_AUTHTOKEN is set!")
|
||||
}
|
||||
log.Println("[Segfautils] ✅ Passed the Environment Variables check")
|
||||
}
|
||||
Reference in New Issue
Block a user