(1) Go Lang--recognize and install

Source: Internet
Author: User
Tags install go uppercase letter mercurial gocode
This is a creation in Article, where the information may have evolved or changed.

Introduced:

The Go programming language is an open source project that makes programmers more efficient. Go is expressive, concise, clear, and efficient. Its parallel mechanism makes it easy to write multicore and Web applications, while the novelty type system allows for the building of resilient modular programs. Go compiles to machine code very quickly, with convenient garbage collection and powerful runtime reflection. It is a fast, statically typed compilation language, but it feels like a dynamic type, interpreted language.

Linux Installation

1. Install the C language tool

The tools chain of Go is written in C and the following development tools are required to build:

    • Gcc
    • C Language standard library,
    • The parser generator Bison,
    • Make
    • awk, and
    • Ed (editor).

For OS X Systems, the above tools are part of Xcode.

For the Ubuntu/debian system, run the Install command:

sudo apt-get install bison ed gawk gcc Libc6-dev make

2. Installing mercurial

You need to install the mercurial version management system before doing the following operations (you can output HG noun detection for installation). Enter the following command to install:
Apt-get Install Python-setuptools Python-dev build-essential

3. Get the Code

The following command creates a go directory. Switch to the appropriate directory and make sure the Go directory does not exist at the current location, run the command:
HG Clone-r Release Https://go.googlecode.com/hg/go

4. Install Go

CD  Go/src./all.bash

5. Configure Environment variables
The go compiler requires three required environment variables and an optional environment variable. Environment variables are set in . BASHRC or other configuration files.
It should be noted that the $goarch and $goos environment variables represent the target Code runtime environment, which is irrelevant to the platform currently in use. This is convenient for cross-compiling.

in Goroot to find the location of these tools such as 8g,8l, go1.0.3 version of the installation will be based on the version of the system you use, automatically generate/pkg/tool/directory, if my is OSX 64-bit system will produce $GOROOT/pkg/tool/ Linux_386 A directory like this

Export Goroot=/go    //go install package root directory export goarch=386   //cpu type export goos=linux  //target Code operating system export gobin=$ Goroot/bin  //Optional export path=.: $PATH: $GOBIN export path=.: $PATH: $GOROOT/pkg/tool/linux_386


Check to see if it works:

SOURCE ~/.BASHRCCD ~8g-v


Windows installation

1. Download Go-1 http://code.google.com/p/go/downloads/list?q=OpSys-Windows+Type%3DArchive
2. Unzip to the C: \ Disk 3. Make sure the content is C:\Go. Note: When extracting the zip file, this directory will be created; 4. Configure Environment Variables Goroot-C:\GO PATH inside add%goroot%\bin;%goroot%\pkg\tool\windows_386
Of course you can put it in any directory.


at this point, GO environment to build success, the following can write programs oh.

Programming Program:

$ cat >hello.go <<eofpackage mainimport "FMT" Func Main () {            //parentheses must follow the FMT behind this line        . Printf ("Hello, world\n")}eof$ 8g hello.go           //compile $8l hello.8           //Connect $./8.out              //execute Hello, world          //output

Gccgo compiling
Gccgo Hello.go./hello.out



Program Description:

Each go source file has a "package" declaration statement at the beginning, indicating the packages where the source files are located. At the same time, we can choose to import the specific features of the package according to the specific needs. In this example, we use the printf function we are familiar with by importing the "FMT" package. In the go language, however, the printf function starts with an uppercase letter and is prefixed with the FMT package name: FMT. Printf.

The keyword "func" is used to define a function. After all initialization is complete, the program executes from the main function in the main package.

A constant string can contain Unicode characters, which are encoded with UTF-8. In fact, all the go language source files are UTF-8 encoded.

Code comments are similar to C + +:


Version update for Go:

$ cd go/src$ Hg pull$ HG update release$./all.bash



GO Lang Development tools:


1. Liteide


Project homepage: 
http://code.google.com/p/golangide/ 
Project Download: 
Http://code.google.com/p/golangide/downloads/list 

Operating system support:  
WIN32 LINUX


2. Eclipse-based Goeclipse

Goclipse is an Eclipse plugin for adding IDE functionality to the Go programming language in the Eclipse development platform. The features offered include:

  • Syntax Light display
  • Create a default structure for a new go project and a new go source file
  • Run Configuration support
  • Implementing error Reporting in Eclipse
  • Content assistance via Gocode (Https://github.com/nsf/gocode)


Environmental requirements:

    • Eclipse 3.7
    • Go
    • Environment variables Set (Gopath, Goroot, Goarch, GOOS)

Detailed installation:

First, in Eclipse's install update, enter Goclipse's online update address: http://goclipse.googlecode.com/svn/trunk/goclipse-update-site/

After installing the Goclipse plug-in, configure the development parameters for the Go project in the Go under window, Preference. Goroot is the directory of the Go language installation on the computer, such as C:\Go (Windows) or/usr/local/go (Linux), Goarch is the model of the CPU, my 386;goos is the operating system, my windows Gobin is the location of the bin file for the go language on your computer; Gopath and Goroot. Among them, Goarch and goos These two goclipse should be will automatically help you match good. In addition, if you want to have the automatic code completion function, you can download Gocode and configure the Gocode address in the Gocode column.

The above is the configuration of the development parameters, next, we create a go Project.

In a Go project directory, there are three folders: Bin, pkg, SRC, where we only need to focus on the Bin folder and the Src folder. The bin folder is where the compiled source files are placed, that is, where the executable files are located, and SRC is the source file directory. Note that it is useless to create a file directly under SRC, because it will not compile, which is the biggest reason I have been unable to run successfully. We need to create a cmd folder under the SRC folder, then we can create a go file such as Hello.go, then the package with main, we can type the following code:

Package Main

Import "FMT"

Func Main () {

Fmt. Printf ("Hello world!")

}

Then save, we can see an. exe file automatically appears under the Bin folder, which means that Goclipse is automatically compiled from the source file.

Then we run this project and we can see the output of the Hello world! results on the console.



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.