Golang Getting Started environment configuration and basic syntax

Source: Internet
Author: User
Tags sublime text
This is a creation in Article, where the information may have evolved or changed.

Golang, a pro-son of Google, is now increasingly concerned about Android, which is said to be using Golang instead of Java development, because Google has been sued by Oracle, the annual compensation of $ A billion of ....

The advantage of span style= "White-space:pre" > Go is concurrency, , good grammar, excellent function Library and fast compiler

Our project team's online customer service system is developed in the go language, and after the touch of go, it feels that its innovation is really attractive.

The following record "enough waves" of the introductory learning notes, environment configuration oneself is also in the Internet to find a lot of information, got a long time to get it, so record it is an experience it.

First, the Environment configuration

1. System: Linux (Ubuntu, CentOS ... )

Golangs is Google's Daniel in Linux under the development of the compiled language, under the Linux development is the most suitable, do not engage in windows, wasting time, compiling code is very prone to problems, I stepped on the pit

2, Go language environment configuration: Download Go source installation package, and then configure the PATH environment

3. development Tool (Editor): Sublime text 2 or Sublime text 3

4. version management: Git

I am configuring the environment under CentOS6.5, take this as an example, the steps are as follows:

a . Go to install the configuration , in turn, enter the following command in the terminal

Wget-c http://www.golangtc.com/static/go/go1.3.linux-386.tar.gz   #下载32位Linux的够源码包tar-zxvf  go1.1.linux-386.tar.gz      #下载文件后解压缩cp-R go//usr/local/go      #移动到指定文件路径vi/etc/profile      #配置环境变量      join at the end of the file:      Export goroot=/usr/local/go      export gobin= $GOROOT/bin      export Gopath=/root/gocode      # The path is to put the development of the project file path, can not be consistent with the goroot, under the path to build three folders "src", "pkg", "bin", their own development projects placed under the SRC.      export path= $PATH: $GOBIN: $GOPATH      Press "ESC" and enter: QW           #命令保存退出source/etc/profile    #使配置文件立刻生效go env    #查看环境变量, the result output proves the configuration was successful


B. Installation configuration Sublime Text 2
Download the corresponding version of the installation package online;

Install Gosublime plug-in;
Open the configuration preference>packages seetting>go sublime>setting User
The input settings are as follows:
"env": {

"PATH": "/usr/local/go"
},

C. Install git

Yum Install git

D. Shell basic commands to run the Go Project project

Go get "open Source Library"      #下载go语言开源库 go build  *.go         #在项目路径下编译所有go文件  go build-o [filename] *go  #编译所有go文件, Generates the execution file for the specified file name./"File name"     




Second, basic grammar

Direct reference to Links

Go community : http://studygolang.com/

Go Getting Started grammar guide: HTTP://TOUR.STUDYGOLANG.COM/WELCOME/1

basic syntax not much to say, look at the innovative features of Go

     Goroutines & Channels

It is difficult to write concurrency code, and it is more difficult to write code that accesses the network concurrently. The problem is that traditional threads do not scale well, and once the threads are running, it is difficult to control them. The goroutine of the Go language solves this problem. Essentially, Goroutines is a lightweight concurrency mechanism that interacts between threads by using a pipeline called channels. They are very easy to use.

<span style= "FONT-SIZE:18PX;" >go func (x, y)//Can invoke the method asynchronously func</span>
<span style= "FONT-SIZE:18PX;" >channel is a type of pipe var ch chan int = make (chan int)//Create Pipe CH <-1//1 into pipe CHV: = <-ch//received from CH and assigned to V</SPAN> ;



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.