This is a creation in
Article, where the information may have evolved or changed.
April 9 that day, out of an online bug, home analysis for half a day, the subjective reasons do not say, the objective reason is that Beego provides the compilation package tool Bee does not support the configuration file check ... Study a half-day, about the configuration file pre-compile check, I have no idea, but looked at the source of bee, or understand a lot, record a bit.
Say it around the bee run command.
- With this command, to enter the current package, check the directory
./conf/app.conf file, get appname .
- Compile.
go install controllers, compile and build the static link library under the Pkg folder. This command can also be compiled to execute files under the Bin folder.
- Build the executable file
go build -o Cyeam main.go and compile the executable file Cyeam. The name of the executable file is the first step to get the Appnane.
-
Launch the app.
appname = "./" + appname cmd = exec.Command(appname) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Args = append([]string{appname}, conf.CmdArgs...) cmd.Env = append(os.Environ(), conf.Envs...) go cmd.Run()
-
Close the app. Both startup and shutdown are performed using the exec package, creating the process and shutting down the process.
defer func() { if e := recover(); e != nil { fmt.Println("Kill.recover -> ", e) } }() if cmd != nil && cmd.Process != nil { err := cmd.Process.Kill() if err != nil { fmt.Println("Kill -> ", err) } }
- File modification monitoring. Bee command also has a more powerful feature, that is, whenever a file changes, can be automatically compiled. Here it uses the Open source package
github.com/howeyc/fsnotify , which is an open source file notification system.
Finally, add something else:
-
The Bee command can also have a configuration file, the name is bee.json . If you want to reference your own package, for example github.com/mnhkahn/maodou , you can create a new Bee.json file in the Beego directory, as in the following. In addition, Bee also supports a lot of orders, I'm just a point here, we can study on their own. Spit The Groove, Bee command of the document is really few, want to know more about or to see the code.
{ "Version": 0, "GOPM": { "Enable": false, "Install": false }, "Go_install": false, "Watch_ext": [], "Dir_structure": { "Watch_all": false, "Controllers": "", "Models": "", "Others": ["$GOPATH/src/github.com/mnhkahn/maodou"] }, "Cmd_args": [], "Envs": [], "Database": { "Driver": "MySQL" } }
-
There is also a problem, bee command old give people an illusion. If you copy the project to the /tmp/ directory and execute Bee run, the project can still be started, but the project is actually compiled under Gopath. Compile Gopath The following code is also understandable, because this is Golang rules, but can compile and execute smoothly, this is not very good. Often I want to test in the/tmp directory, and then measured half a day to find something to change the effect. I think it should be detected no longer Gopath directory should be decisive to notify the user directory is wrong.
Original link: Bee source analysis, reproduced please specify the source!