Ejemplo n.º 1
0
func getConnection() *RabbitConnection {

	cp := logger.ConsoleProvider{}

	log := logger.NewLogger()
	log.RegisterProvider(cp)

	log.AddLogProvider(cp.GetID())
	log.AddErrorProvider(cp.GetID())
	log.AddFatalProvider(cp.GetID())
	log.AddDebugProvider(cp.GetID())

	rabbitMQ := NewRabbitCluster(log)
	url := "amqp://*****:*****@127.0.0.1:5672/"
	conn := rabbitMQ.NewConnection("connectionId", url)

	return conn
}
Ejemplo n.º 2
0
func init() {

	// Init config
	{
		cfg, err := config.NewConfig()
		if err == nil {
			err = cfg.ReadConfig()
		}

		if err != nil {
			panic(err.Error())
		} else {
			CFG = cfg
		}
	}

	// Init logger
	{
		cp := logger.ConsoleProvider{}

		LOGGER = logger.NewLogger()
		LOGGER.RegisterProvider(cp)

		LOGGER.AddLogProvider(cp.GetID())
		LOGGER.AddErrorProvider(cp.GetID())
		LOGGER.AddFatalProvider(cp.GetID())
		LOGGER.AddDebugProvider(cp.GetID())
	}

	// Init application
	templates := template.New("template")
	filepath.Walk("templates", func(pathToFile string, info os.FileInfo, err error) error {

		if path.Ext(pathToFile) == ".html" {
			templates.ParseFiles(pathToFile)
		}
		return nil
	})

	app = App{}
	app.router = Router{make(Routes)}
	app.definitions = Definitions{
		Handlers: make(map[string][]MiddlewareInterface),
	}
	app.templates = templates
	app.staticDir = "public"
	app.defaultLang = "en-US"

	if len(CFG.Str("defaultLang")) > 0 {
		app.defaultLang = CFG.Str("defaultLang")
	}

	app.workDir, _ = os.Getwd()
	app.langDir = path.Join(app.workDir, "i18n")
	app.tmpDir = path.Join(app.workDir, "tmp")
	app.maxBodyLength = 131072

	_, err := os.Stat(app.tmpDir)
	if os.IsNotExist(err) {
		err = os.Mkdir(app.tmpDir, os.ModePerm)
		if err != nil {
			LOGGER.Fatal(err)
		}
	}

	_, err = os.Stat(fmt.Sprint(app.langDir))
	if os.IsNotExist(err) {
		err = os.Mkdir(app.langDir, os.ModePerm)
		if err != nil {
			LOGGER.Fatal(err)
		}
	}

	filepath.Walk("i18n", func(pathToFile string, info os.FileInfo, err error) error {
		if path.Ext(pathToFile) == ".json" {
			err := i18n.LoadTranslationFile(pathToFile)
			if err != nil {
				LOGGER.Error(err)
			}
		}
		return nil
	})
}