beego(Go应用程序框架)如果配置文件发生更改,将如何重新加载应用程序?

huangapple go评论89阅读模式
英文:

How beego(Go App Framework) will reload the application if there is any change in the conf file?

问题

我使用Golang Beego框架(http://beego.me/)开发了这个应用程序,并且它正在生产环境中运行。

假设我编辑了配置文件conf/app.conf,如何在不重新启动/重建应用程序的情况下重新加载我的应用程序?

我尝试使用'bee run'命令运行应用程序,但自动重新加载仍然没有成功。

英文:

I have developed the application using Golang Beego framework(http://beego.me/) and it is running in the production.

Suppose I edit the configuration file which is conf/app.conf, how can my app will be reloaded with restarting/rebuilding the application?

I tried to run the application using 'bee run' command but still no success in automatic reload.

答案1

得分: 1

你可以使用命令bee run来运行该应用程序,并且它支持像这样的配置文件。
bee命令默认通过文件扩展名来监视文件更改。你可以从源代码中看到var watchExts = []string{".go"}。这意味着bee将监视扩展名为.go的文件,所以如果.go文件发生更改,它将自动重新启动。

如果你想让bee命令监视conf/app.conf文件,你需要在你的应用程序目录下创建一个名为bee.json的文件,并且内容应该像这样:

{
    "version": 0,
    "gopm": {
        "enable": false,
        "install": false
    },
    "go_install": false,
    "watch_ext": [".conf"],
    "dir_structure": {
        "watch_all": false,
        "controllers": "",
        "models": "",
        "others": []
    },
    "cmd_args": [],
    "envs": [],
    "database": {
        "driver": "mysql"
    }
}
英文:

You run the application with command bee run and it supports config file like this.
bee command watch file change default by file extension. You can see from the source code
var watchExts = []string{".go"}
. It means bee will watch the file with extension .go, so if .go file change it will auto restarting.

If you want bee command to watch the conf/app.conf file, you need to make a file bee.json at your app directory and the content should like this:

{
	"version": 0,
	"gopm": {
		"enable": false,
		"install": false
	},
	"go_install": false,
	"watch_ext": [.conf],
	"dir_structure": {
		"watch_all": false,
		"controllers": "",
		"models": "",
		"others": []
	},
	"cmd_args": [],
	"envs": [],
	"database": {
		"driver": "mysql"
	}
}

答案2

得分: 0

你可以使用gin,它非常容易设置:

gin是一个简单的命令行实用程序,用于实时重新加载Go Web应用程序。只需在应用程序目录中运行gin,你的Web应用程序将通过gin作为代理进行服务。当gin检测到更改时,它将自动重新编译你的代码。下次收到HTTP请求时,你的应用程序将重新启动。

英文:

You can use gin, it's really easy to set up:

> gin is a simple command line utility for live-reloading Go web applications. Just run gin in your app directory and your web app will be served with gin as a proxy. gin will automatically recompile your code when it detects a change. Your app will be restarted the next time it receives an HTTP request.

huangapple
  • 本文由 发表于 2016年3月18日 15:30:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/36078560.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定