Example #1
0
func verifyLogPaths(lt constants.LogType) error {
	if err := util.CreateDirectory(constants.LogDirectory); err != nil {
		return err
	}
	if !util.FileExists(getLogPath(lt)) {
		if err := util.CreateEmptyFile(getLogPath(lt), false); err != nil {
			return fmt.Errorf("verifyLogPaths error: %s", err)
		}
	}
	return nil
}
Example #2
0
func verifyServerDbPath() error {
	if err := util.CreateDirectory(constants.DbDirectory); err != nil {
		logger.LogAppError(err)
		panic(fmt.Sprintf("Unable to create database directory %s: %s",
			constants.DbDirectory, err))
	}
	if err := createServerDBtable(constants.GetServerDBPath()); err != nil {
		logger.LogAppErrorf("Unable to verify database path: %s", err)
		panic("Unable to verify database path")
	}

	return nil
}
Example #3
0
func dumpServersToDisk(gamename string, sl *models.APIServerList) error {
	j, err := json.Marshal(sl)
	if err != nil {
		return logger.LogAppErrorf("Error marshaling json: %s", err)
	}
	t := time.Now()
	if err := util.CreateDirectory(constants.DumpDirectory); err != nil {
		return logger.LogAppErrorf("Couldn't create '%s' dir: %s\n",
			constants.DumpDirectory, err)
	}
	// Windows doesn't allow ":" in filename so use '-' separators for time
	err = util.CreateByteFile(j, constants.DumpFileFullPath(
		fmt.Sprintf("%s-servers-%d-%02d-%02d.%02d-%02d-%02d.json",
			gamename, t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())),
		true)
	if err != nil {
		return logger.LogAppErrorf("Error creating server dump file: %s", err)
	}
	return nil
}
Example #4
0
func init() {
	test.SetupEnvironment()
	testURLBase = fmt.Sprintf("http://:%d", config.Config.WebConfig.APIWebPort)
	db.InitDBs()

	// create dump server file
	err := util.CreateDirectory(constants.DumpDirectory)
	if err != nil {
		panic("Unable to create dump directory used in tests")
	}
	err = util.CreateByteFile(constants.TestServerDumpJSON, constants.DumpFileFullPath(
		config.Config.DebugConfig.ServerDumpFilename), true)
	if err != nil {
		panic(fmt.Sprintf("Test dump file creation error: %s", err))
	}

	// launch server
	go func() {
		r := mux.NewRouter().StrictSlash(true)
		for _, ar := range apiRoutes {
			var handler http.Handler
			handler = compressGzip(ar.handlerFunc, config.Config.WebConfig.CompressResponses)

			r.Methods(ar.method).
				MatcherFunc(pathQStrToLowerMatcherFunc(r, ar.path, ar.queryStrings,
					getRequiredQryStringCount(ar.queryStrings))).
				Name(ar.name).
				Handler(http.TimeoutHandler(handler,
					time.Duration(config.Config.WebConfig.APIWebTimeout)*time.Second,
					`{"error":"Timeout"}`))
		}
		err := http.ListenAndServe(fmt.Sprintf(":%d", config.Config.WebConfig.APIWebPort), r)
		if err != nil {
			panic("Unable to start web server")
		}
	}()
}