Пример #1
0
Файл: conf.go Проект: jexm/wego
func configWatcher() {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		panic("Failed start app watcher: " + err.Error())
	}

	go func() {
		for {
			select {
			case event := <-watcher.Event:
				switch filepath.Ext(event.Name) {
				case ".ini":
					if checkEventTime(event.Name) {
						continue
					}
					log.Info(event)

					if err := Cfg.Reload(); err != nil {
						log.Error("Conf Reload: ", err)
					}

					if err := i18n.ReloadLangs(); err != nil {
						log.Error("Conf Reload: ", err)
					}

					reloadConfig()
					log.Info("Config Reloaded")

				case ".json":
					if checkEventTime(event.Name) {
						continue
					}
					if event.Name == CompressConfPath {
						settingCompress()
						log.Info("Compress Reloaded")
					}
				}
			}
		}
	}()

	if err := watcher.WatchFlags("conf", fsnotify.FSN_MODIFY); err != nil {
		log.Error(err)
	}

	if err := watcher.WatchFlags("conf/global", fsnotify.FSN_MODIFY); err != nil {
		log.Error(err)
	}
}
Пример #2
0
func InitApp() {
	initTemplates()
	initLocales()

	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		panic("Failed start app watcher: " + err.Error())
	}

	go func() {
		for {
			select {
			case event := <-watcher.Event:
				switch filepath.Ext(event.Name) {
				case ".ini":
					log.Info(event)

					if err := i18n.ReloadLangs(); err != nil {
						log.Error("Conf Reload: ", err)
					}

					log.Info("Config Reloaded")

				case ".json":
					if event.Name == CompressConfPath {
						log.Info("Beego Compress Reloaded")
					}
				}
			}
		}
	}()

	if err := watcher.WatchFlags("conf", fsnotify.FSN_MODIFY); err != nil {
		log.Error(err)
	}
}
Пример #3
0
func InitI18n(langs []string) error {
	for _, lang := range langs {
		i18n.SetMessage(lang, filepath.Join(*homeDir, fmt.Sprintf("langs/locale_%s.ini", strings.ToLower(lang))))
	}
	return i18n.ReloadLangs(langs...)
}