First knowledge of Go language

Source: Internet
Author: User
Tags php language
This is a creation in Article, where the information may have evolved or changed. 1:go Language Brief Introduction:
Go is a concurrency-specific, fast-compiling language designed for multi-core CPUs, with garbage collection.
Go is a static type of language, more lightweight than OOP (object-oriented language),
Therefore, users do not need to spend time on defining relationships between types.

2: When do I use the Go language?
For system, network, web programming, can replace C,python,java,ruby and PHP language.

3.Go language installation and use note:
A: Environment variable: add gopath path; path variable needs to be added to the Go program's Bin directory.
There are 3 directories in the B:gopath directory:
SRC directory (be sure to place the source go file);
Bin directory (can not, compiled main.go executable file, Windows is EXE)
Pkg directory (can not, compile the other go file, generate. a file)

External commands for 4:go languages:
The Go Build command is used primarily for test compilation. During the compilation of a package, the package associated with it is compiled, if necessary.
The Go Clean command is used to remove the generated files from the current source package.
Go FMT format normalized go language
Go get this command is used to dynamically obtain remote code packages, currently supported by BitBucket, GitHub, Google code and launchpad.
For example: Go get gopkg.in/mgo.v2 get the Go Connection pack for MongoDB database (GitHub client needs to be installed beforehand)
Go test executes this command and automatically reads the file named *_test.go under the source directory, generating and running the executable file for the test.
Go fix is used to fix old version of code to new version, such as Go1 before the old version of the code into GO1
Go version View the current release of Go
Go env View the current GO environment variables
Go list lists all currently installed package
Go run to compile and run the Go program

5:go Development Tools
Recommended use: Liteide (because it focuses on the IDE for Go)
Download Address: Http://www.golangtc.com/download/liteide

http://sourceforge.net/projects/liteide/files/

The

6:go program is organized through the package
      package <pkgName> (in our case, packages main) This line tells us which packet the current file belongs to. , and the package name, Main,
tells us that it is a standalone package that generates an executable file after it is compiled. In addition to the main package, other packages will eventually generate a *.a
(that is, the package file).
      The name of the folder in which the package name and package is located can be different, where <pkgName> is the package name, not the folder name, that is declared through the packages <pkgName>.
      But import introduces a folder directory

7: Define variable
    var variableName type  //define a variable
    var vname1, vname2, Vname3 Type//define multiple variables
     Define variables and initialize values:
         var variableName type = value
& nbsp        var vname1, vname2, Vname3 type= v1, v2, v3   or  var vname1, vname2, Vname3 = v1, v2, V3
        vname1, vname2, Vname3: = V1, v2, v3//In-function definition
        _ ( Underline) is a special variable name, and any value given to it will be discarded. In this example, we assign a value of 35 to B and discard it at the same time:
        _, B: =,
   i = p
Pi = 3.1415
prefix = "Go_"
)
var (
I int
pi float32
Prefix string
)

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.