go-pingbot/main.go

73 lines
1.3 KiB
Go
Raw Normal View History

2021-07-11 21:19:37 +00:00
package main
import (
2021-08-14 21:43:30 +00:00
"os"
"sync"
"time"
2021-07-29 18:51:15 +00:00
2021-08-12 19:26:54 +00:00
"github.com/MedzikUser/go-utils/common"
2021-08-14 21:43:30 +00:00
"github.com/MedzikUser/go-utils/updater"
2021-07-11 21:19:37 +00:00
"gitlab.com/gaming0skar123/go/pingbot/backend"
"gitlab.com/gaming0skar123/go/pingbot/config"
2021-07-29 18:51:15 +00:00
"gitlab.com/gaming0skar123/go/pingbot/database/mongo"
2021-07-11 21:19:37 +00:00
"gitlab.com/gaming0skar123/go/pingbot/website"
)
var log = common.Log
func main() {
log.Info("You're using verion: ", config.Version)
var wg sync.WaitGroup
2021-07-29 18:51:15 +00:00
mongo.Connect()
if config.Toml.AutoUpdate.Enabled {
wg.Add(1)
2021-08-14 21:43:30 +00:00
client := updater.Client{
2021-08-18 16:51:32 +00:00
GitHub: config.GH_Repo,
GitHubToken: config.GH_Token,
2021-08-18 16:51:32 +00:00
Version: config.Version,
Binary: "pingbot.out",
2021-08-22 10:04:12 +00:00
CheckEvery: config.Toml.AutoUpdate.Check * time.Minute,
2021-08-14 21:43:30 +00:00
AfterUpdate: func() {
log.Info("Updated!")
2021-08-29 10:14:35 +00:00
if !config.Toml.Options.Stop_After_Ping {
os.Exit(0)
}
2021-08-14 21:43:30 +00:00
},
2021-08-22 10:04:12 +00:00
Major: false,
2021-08-14 21:43:30 +00:00
}
go client.AutoUpdater()
2021-07-29 18:51:15 +00:00
} else {
log.Warn("Auto Update -> Disabled")
}
2021-07-11 21:19:37 +00:00
2021-08-29 10:14:35 +00:00
if config.Toml.Options.Stop_After_Ping {
backend.StopAfterPing()
2021-08-29 10:14:35 +00:00
os.Exit(0)
}
if config.Toml.HTTP.Enabled {
wg.Add(1)
go website.Server()
} else {
log.Warn("HTTP Server -> Disabled")
}
if config.Toml.Backend.Enabled {
wg.Add(1)
go backend.Ticker()
} else {
log.Warn("Backend -> Disabled")
}
config.StartTime = time.Now()
wg.Wait()
2021-07-11 21:19:37 +00:00
}