Exemple #1
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
}
Exemple #2
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")
		}
	}()
}