Пример #1
0
/*beego 初始化*/
func init() {
	var config_file string
	flag.StringVar(&config_file, "conf", "", "the path of the config file")
	flag.Parse()
	if config_file != "" {
		beego.AppConfigPath, _ = filepath.Abs(config_file)
		beego.ParseConfig()
	} else {
		if config_file = os.Getenv("BEEGO_APP_CONFIG_FILE"); config_file != "" {
			beego.AppConfigPath, _ = filepath.Abs(config_file)
			beego.ParseConfig()
		}
	}
}
Пример #2
0
func init() {
	//orm.RegisterDataBase("default", "mysql", "root@/gotalk?charset=utf8", 30)
	beego.AppConfigPath = "../conf/app.conf"
	beego.ParseConfig()
	setting.ReadConfig()
	orm.RunSyncdb("default", true, false)
}
Пример #3
0
func init() {
	var config_file string
	flag.StringVar(&config_file, "conf", "", "the path of the config file")
	flag.Parse()
	if config_file != "" {
		beego.AppConfigPath, _ = filepath.Abs(config_file)
		beego.ParseConfig()
	} else {
		if config_file = os.Getenv("BEEGO_APP_CONFIG_FILE"); config_file != "" {
			beego.AppConfigPath, _ = filepath.Abs(config_file)
			beego.ParseConfig()
		}
	}

	util.Factory.Set("cache", func() (interface{}, error) {
		mc := util.NewLruCache(1000)
		return mc, nil
	})

	models.Init()
}
Пример #4
0
func init() {
	loadArchiveNames()
	loadRecommendBlogs()

	// Watch changes.
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		beego.Error("NewWatcher:", err)
		return
	}

	go func() {
		for {
			select {
			case e := <-watcher.Event:

				// Skip TMP files for Sublime Text.
				if checkTMPFile(e.Name) {
					continue
				}

				mt := getFileModTime(e.Name)
				if t := eventTime[e.Name]; mt == t {
					continue
				}

				eventTime[e.Name] = mt
				beego.Info("Changes detected")
				beego.ParseConfig()
				loadArchiveNames()
				loadRecommendBlogs()
			case err := <-watcher.Error:
				beego.Error("Watcher error:", err)
			}
		}
	}()

	err = watcher.Watch("content")
	if err != nil {
		beego.Error("Watch path:", err)
		return
	}
	err = watcher.Watch("work")
	if err != nil {
		beego.Error("Watch path:", err)
		return
	}
	err = watcher.Watch("conf")
	if err != nil {
		beego.Error("Watch path:", err)
		return
	}
}
Пример #5
0
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 ".conf":
					if checkEventTime(event.Name) {
						continue
					}

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

					beego.Info("Config Reloaded")
					//todo:extend this functionality
				case ".json":
					if checkEventTime(event.Name) {
						continue
					}
					if event.Name == CompressConfPath {
						settingCompress()
						beego.Info("Beego Compress Reloaded")
					}
				}
			}
		}
	}()

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

	if err := watcher.WatchFlags("conf/", fsnotify.FSN_MODIFY); err != nil {
		beego.Error(err)
	}
}
Пример #6
0
func init() {
	runtime.GOMAXPROCS(Workers)
	beego.AppConfigPath = "../conf/app.conf"
	beego.ParseConfig()
	setting.ReadConfig()
	DiscuzDb = beego.AppConfig.String("importer::discuzdb")
	AvatarPath = beego.AppConfig.String("importer::avatarpath")
	if err := orm.RegisterDataBase("discuz", "mysql", fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8", setting.MySQLUser, setting.MySQLPassword, setting.MySQLHost, DiscuzDb)+"&loc=Asia%2FShanghai", 30); err != nil {
		fmt.Println("MySQL error:", err.Error())
		return
	}
	OrmGotalk = orm.NewOrm()
	if db, err := orm.GetDB("discuz"); err == nil {
		Orm, err = orm.NewOrmWithDB("mysql", "discuz", db)
		if err != nil {
			fmt.Println("MySQL error:", err.Error())
			return
		}
	} else {
		fmt.Println("MySQL error:", err.Error())
		return
	}
	orm.RunSyncdb("default", true, false)
}
Пример #7
0
func initconfig() {
	beego.AppPath = utils.AppRoot
	beego.AppConfigPath = path.Join(beego.AppPath, "conf", "app.conf")
	beego.ParseConfig()
	beego.ViewsPath = utils.MergePath(beego.ViewsPath)
}
Пример #8
0
func init() {
	beego.AppConfigPath = "/Users/zhanglida/go_path/src/beego_study/conf/app.conf"
	beego.ParseConfig()
	beego.Error("apppath", beego.AppConfigPath)
}