Go language portal --hello world

Go language source code file extension is .go.

Knowledge points:
1. Line 1 go language code must declare the package
go language code 2. entrance (the main function of the file containing the code) package must be main, or go run the program displays go run: can not run non- main Package Penalty for
3. Go language left brace ({) and his party alone can not account for, must and other code in a row.
4. Import go library need to use the import keyword
5. go language provisions, the first letter of the name of all exported functions must be capitalized. fmt.Printf ( "hello, go !! \ n")

Example: Console Print "the Hello, Go !!"
D: \ tmp \ hello.go

package main

import "fmt" 

func main() {
    fmt.Printf("hello, go!!\n")
}

 

Ordinal as运行Go
$ Go Run Hello.Go

Generate an executable file
go build when compiling begins, go search the current directory source. go build lib.go and main.go will find two files. After compiling both files, generate the current directory name of the executable file and placed in the current directory, where the executable is go build.
$ Go build hello.go

Guess you like

Origin www.cnblogs.com/linjiqin/p/12081284.html