Bee Source Code Analysis

Source: Internet
Author: User
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.

  1. With this command, to enter the current package, check the directory ./conf/app.conf file, get appname .
  2. 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.
  3. 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.
  4. 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()
  5. 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)     } }
  6. 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:

  1. 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"     } }
  2. 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.