Go-Path, directory name, package name, file name

Source: Internet
Author: User

Let's look at an example:

1. Directory structure

Bin

Pkg

Src

Pk1

Pk2

Function1.go

Function2.go

Index.go

2. function1.go File Contents:

Package Pk3func Function_test3 ()  {println ("Function_test3")}

3. function2.go File Contents:

Package Pk3func Function_test4 ()  {println ("Function_test4")}

4. index.go File Contents

Package Mainimport "Pk1/pk2" Func Main () {pk3. Function_test4 ()}

5, run Index.go, output:

Function_test4

The following conclusions are drawn:

1. Import imported parameters are paths , not package names .

2, although the habit of the package name and directory name to ensure consistency, but this is not mandatory provisions;

3. When referencing a package member in code, use the package name rather than the directory name ;

4, in the same directory, all source files must use the same package name (because the import uses absolute path, so under the search path, the package must have a unique path, but not necessarily a unique name);

Go-Path, directory name, package name, file name

Related Article

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.