Go project directory

Source: Internet
Author: User

|--bin|--pkg|--src

Where the bin holds the compiled executable file, the PKG holds the compiled package file, and SRC holds the project source file. Generally, the bin and pkg directories can be created without the GO command being created automatically (like go install), just create the SRC directory.
For the PKG directory, the files in the pkg are generated by go compilation, rather than manually put in. (General file suffix. a)
For the SRC directory, the source files are stored in the go, and the source files are organized in the form of packages. In general, creating a new package creates a new folder in the SRC directory.

test|--install '--src    |--config    |   '--config.go    '--Test        '--main.go

Note that the package name in Config.go must be the best match for the directory config, and the file name can be random. Main.go represents the main package, and the file name is suggested as Main.go.

(Note: when inconsistent, the resulting. A file name and directory name are the same, so that when you import, it should be the directory name, and the package name is required when the package is referenced.) For example, if the directory is myconfig and the package name is config, then the production static package file is: MYCONFIG.A, referencing the package: import "Myconfig", using the package Member: CONFIG. Loadconfig ())

The code for CONFIG.GO and Main.go is as follows:
Config.go Code

Package Configfunc Loadconfig () {}

Main.go Code

Package Mainimport ("config" "FMT") func main () {config. Loadconfig () fmt. Println ("Hello, go!")}

Next, execute the./install in the project root directory.

The directory structure at this time is:

test|--bin|   '--test|--install|--pkg|   '--linux_amd64|       '--config.a '--src    |--config    |   '--config.go    '--Test        '--main.go (linux_amd64 means I use the operating system and architecture, you may not be the same)

Where CONFIG.A is generated after the package config is compiled; bin/test is a binary file that is generated

This time can be carried out: Bin/test. Will output: Hello, go!

Go project directory

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.