The location of the Go Language import statement

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

The following excerpt from the Go programming Language:

The import declarations must follow the package declaration. After this, a program consists of the declarations of functions, variables, constants, and types (introduced by the key wo RDS Func, VAR, const, and type); For the most part, the order of declarations does not matter.

importStatements must be followed by package definitions. Take a look at the following example:

package mainvar str string = "Hello world!\n"import "fmt"func main(){    // your code goes     fmt.Println(str)}

Compile as follows:

./prog.go:5: syntax error: unexpected import

Adjust the position of the statement:

package mainimport "fmt"var str string = "Hello world!\n"func main(){    // your code goes     fmt.Println(str)}

Compile execution succeeded:

Hello world!

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.