parse host as FQDN or IP

This commit is contained in:
wish
2022-08-04 23:52:13 +10:00
parent a7ec76f865
commit e9cc5cc3e2
6 changed files with 23 additions and 9 deletions

14
main.go
View File

@@ -3,6 +3,7 @@ package main
import (
"fmt"
"math/rand"
"net"
"os"
"os/signal"
"syscall"
@@ -48,6 +49,19 @@ func main() {
preventClose("Database password is blank")
}
if net.ParseIP(erupeConfig.Host) == nil {
ips, _ := net.LookupIP(erupeConfig.Host)
for _, ip := range ips {
if ip != nil {
erupeConfig.Host = ip.String()
break
}
}
if net.ParseIP(erupeConfig.Host) == nil {
preventClose("Invalid host address")
}
}
// Discord bot
var discordBot *discordbot.DiscordBot = nil