Added basic webserver support.

This commit is contained in:
Adrian Gallagher
2015-11-28 19:07:23 +11:00
parent ecfbfd932f
commit 178b59ef71
7 changed files with 133 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"log"
"strconv"
"time"
)
@@ -25,8 +26,17 @@ var (
WarningSMSGlobalDefaultOrEmptyValues = "WARNING -- SMS Support disabled due to default or empty Username/Password values."
WarningSSMSGlobalSMSContactDefaultOrEmptyValues = "WARNING -- SMS contact #%d Name/Number disabled due to default or empty values."
WarningSSMSGlobalSMSNoContacts = "WARNING -- SMS Support disabled due to no enabled contacts."
WarningWebserverCredentialValuesEmpty = "WARNING -- Webserver support disabled due to empty Username/Password values."
WarningWebserverListenAddressInvalid = "WARNING -- Webserver support disabled due to invalid listen address."
)
type Webserver struct {
Enabled bool
AdminUsername string
AdminPassword string
ListenAddress string
}
type SMSGlobal struct {
Enabled bool
Username string
@@ -42,6 +52,7 @@ type Config struct {
Name string
Cryptocurrencies string
SMS SMSGlobal `json:"SMSGlobal"`
Webserver Webserver `json:"Webserver"`
Exchanges []Exchanges
}
@@ -156,6 +167,27 @@ func CheckExchangeConfigValues() error {
return nil
}
func CheckWebserverValues() error {
if bot.config.Webserver.AdminUsername == "" || bot.config.Webserver.AdminPassword == "" {
return errors.New(WarningWebserverCredentialValuesEmpty)
}
if !StringContains(bot.config.Webserver.ListenAddress, ":") {
return errors.New(WarningWebserverListenAddressInvalid)
}
portStr := SplitStrings(bot.config.Webserver.ListenAddress, ":")[1]
port, err := strconv.Atoi(portStr)
if err != nil {
return errors.New(WarningWebserverListenAddressInvalid)
}
if port < 0 || port > 65355 {
return errors.New(WarningWebserverListenAddressInvalid)
}
return nil
}
func ReadConfig() (Config, error) {
file, err := ioutil.ReadFile(CONFIG_FILE)