func main() {
	//Profiling
	// go func() {
	// 	log.Println(http.ListenAndServe(":6060", nil))
	// }()

	var (
		config *app.Config
	)

	envParser := env_parser.NewEnvParser()
	envParser.Name(appName)
	envParser.Separator("_")
	envSrc := app.Envs{}
	envParseError := envParser.Map(&envSrc)
	app.Chk(envParseError)

	app.PrintWelcome()

	switch envSrc.Mode {
	case app.MODE_DEV:
		logr.Level = logrus.InfoLevel
	case app.MODE_PROD:
		logr.Level = logrus.WarnLevel
	case app.MODE_DEBUG:
		logr.Level = logrus.DebugLevel
	}

	config = app.NewConfig(envSrc.AssetsUrl, envSrc.UploadPath)

	logFile, fileError := os.OpenFile(envSrc.LogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0660)
	defer logFile.Close()
	if fileError == nil {
		logr.Out = logFile
	} else {
		fmt.Println("invalid log file; \n, Error : ", fileError, "\nopting standard output..")
	}

	redisService, reErr := services.NewRedis(envSrc.RedisUrl)
	reErr = reErr

	sqlConnectionStringFormat := "%s:%s@tcp(%s:%s)/%s"
	sqlConnectionString := fmt.Sprintf(sqlConnectionStringFormat, envSrc.MysqlUser, envSrc.MysqlPassword,
		envSrc.MysqlHost, envSrc.MysqlPort, envSrc.MysqlDbName)
	mySqlService := services.NewMySQL(sqlConnectionString, 10)

	//TODO check
	baseHandler := handlers.NewBaseHandler(logr, config)
	userHandler := handlers.NewUserHandler(baseHandler, redisService, mySqlService)
	reqHandler := handlers.NewRequestHandler(baseHandler, redisService, mySqlService)

	goji.Post("/register", baseHandler.Route(userHandler.DoRegistration))
	goji.Post("/login", baseHandler.Route(userHandler.DoLogin))
	goji.Get("/bloodReq", baseHandler.Route(reqHandler.RemoveBloodRequest))
	goji.Post("/bloodReq", baseHandler.Route(reqHandler.MakeBloodRequest))
	goji.Delete("/bloodReq", baseHandler.Route(reqHandler.RemoveBloodRequest))
	goji.NotFound(baseHandler.NotFound)

	goji.Serve()
}
func main() {
	envParser := env_parser.NewEnvParser()
	envParser.Name("EXAMPLE")
	envParser.Separator("_")
	envSrc := Envs{}
	envParseError := envParser.Map(&envSrc)

	fmt.Println(envParseError.Error())

}
Beispiel #3
0
func main() {
	fmt.Println("Wolfs are not Bees..")
	ep := env_parser.NewEnvParser()
	envs := models.Envs{}
	err := ep.Map(&envs)
	if err != nil {
		fmt.Println("Invalid environment variables : ", err)
		return
	}
	conn, err := client.NewConnection(envs.UserId, envs.ClientId, envs.Password, envs.Host)
	if err != nil {
		fmt.Println("Error in obtaining connection : ", err)
		return
	}
	topicGen, err := app.NewTopicGen(envs.TopicFile)
	if err != nil {
		fmt.Println("Topic generator obtaining error : ", err)
		return
	}
	publisher, err := client.NewPublisher(topicGen.GetNewTopics(50, models.QOS_LTE_ONE))
	if err != nil {
		fmt.Println("Publisher obtaining error : ", err)
		return
	}
	attacker := client.NewMsgCountBasedAttacker(100000, conn)
	report, err := attacker.LaunchAttack(time.Now().Add(time.Duration(time.Second*10)), publisher)
	if err != nil {
		fmt.Println("Attacking error : ", err)
		return
	}
	rep, err := report.FinalReport()
	if err != nil {
		fmt.Println("Report gathering error : ", err)
		return
	}
	fmt.Println("Final Report : ", string(rep))
}