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!