Go Language Learning Essays

Source: Internet
Author: User
Tags aliases

Go language download install under Windows

Recommended for download in Golang China http://www.golangtc.com/download

Installation....

Go environment variables and working directory
According to the Convention Gopath need to build 3 directories
Bin (holds compiled executable file)
Pkg (holds the package file generated after compilation. a)
SRC (store project source code such as:. Go. C. H. S etc.)
Use Go env to view the environment

Common commands
Go get: Get remote package (git or HG (Google Code))
Go run: Run the program directly
Go bulid: Test compilation
Go FMT: Format source code
Go install: (Compile the package file and compile the entire program)
Go test: Run the testing file (e.g. Aa_test.go)
Godoc: Viewing documents (CHM manual)
Godoc FMT Println
Build your local website
godoc-http=:8080

go built-in keywords
break  default   Func   interface       Select
case defer go map struct chan
ELSE Goto Package Switch const fallthrough
if Range type continue for import return
var

GO program is organized through the package (Python-like)

an executable program There is only one main package

Importing other non-main packages with the Import keyword
by const To make a definition of production
by using the Var keyword outside the body of the function To declare and assign a global variable

declaring a function with the Func keyword

Import of Packages
import "FMT"
import "OS"
import "IO"
or
Import (
"FMT"
"OS"
"IO"
)
After you import the package, you can use <PackageName>.<FuncName>
calling a function in a package
If a function or type is not called after the package is imported, a compilation error is reported
imported and not used: "IO"

Package aliases
When using a third-party package, the package name may be very close or identical,
At this point, you can use aliases to differentiate and invoke
Import (
FTD "FMT"
)
or import FTD "FMT"
Fmt. Println ("Hello word")

Omit call

Package Main Import  " FMT " Func Main () {        Println ("");}  

Aliases must be used with aliases

Visibility rules

In the go language, use case to determine the constant, variable, type
Whether the interface, struct, or function can be called by an external package
Private if the first letter is lowercase according to the Convention function name
The first letter capitalized is public

Importing multiple packages can be abbreviated
Declaring multiple variables, global variables, or generic types (non-interfaces, non-structs) can also

Package MainImport  "FMT"Const (PI=3.14KEY=123SEC=2) Var (a="HK"b="BBC") Type (name string age int sex int) func main () {FMT. Println ("Hello world! "+a+"\ r \ n"+b);}

Go Language Learning Essays

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.