add option to disable soft-crashing

This commit is contained in:
wish
2022-08-04 23:11:19 +10:00
parent 2f35823e1e
commit cdbc11c4b2
3 changed files with 12 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
{ {
"host_ip": "127.0.0.1", "host_ip": "127.0.0.1",
"bin_path": "bin", "bin_path": "bin",
"DisableSoftCrash": false,
"devmode": true, "devmode": true,
"devmodeoptions": { "devmodeoptions": {
"serverName" : "", "serverName" : "",

View File

@@ -9,9 +9,10 @@ import (
// Config holds the global server-wide config. // Config holds the global server-wide config.
type Config struct { type Config struct {
HostIP string `mapstructure:"host_ip"` HostIP string `mapstructure:"host_ip"`
BinPath string `mapstructure:"bin_path"` BinPath string `mapstructure:"bin_path"`
DevMode bool DisableSoftCrash bool
DevMode bool
DevModeOptions DevModeOptions DevModeOptions DevModeOptions
Discord Discord Discord Discord

View File

@@ -19,6 +19,8 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
var erupeConfig *config.Config
// Temporary DB auto clean on startup for quick development & testing. // Temporary DB auto clean on startup for quick development & testing.
func cleanDB(db *sqlx.DB) { func cleanDB(db *sqlx.DB) {
_ = db.MustExec("DELETE FROM guild_characters") _ = db.MustExec("DELETE FROM guild_characters")
@@ -29,6 +31,7 @@ func cleanDB(db *sqlx.DB) {
} }
func main() { func main() {
var err error
zapLogger, _ := zap.NewDevelopment() zapLogger, _ := zap.NewDevelopment()
defer zapLogger.Sync() defer zapLogger.Sync()
logger := zapLogger.Named("main") logger := zapLogger.Named("main")
@@ -36,7 +39,7 @@ func main() {
logger.Info("Starting Erupe") logger.Info("Starting Erupe")
// Load the configuration. // Load the configuration.
erupeConfig, err := config.LoadConfig() erupeConfig, err = config.LoadConfig()
if err != nil { if err != nil {
preventClose(fmt.Sprintf("Failed to load config: %s", err.Error())) preventClose(fmt.Sprintf("Failed to load config: %s", err.Error()))
} }
@@ -209,6 +212,9 @@ func wait() {
} }
func preventClose(text string) { func preventClose(text string) {
if erupeConfig.DisableSoftCrash {
os.Exit(0)
}
fmt.Println("\nFailed to start Erupe:\n" + text) fmt.Println("\nFailed to start Erupe:\n" + text)
go wait() go wait()
fmt.Println("\nPress Enter/Return to exit...") fmt.Println("\nPress Enter/Return to exit...")