Go Language Tutorial 01 Getting Started Instructions

Please indicate the source " Old Boy IT Education "

Go language is an open source programming language that makes it easy to construct simple, reliable and efficient software. But learning any language cannot relax because of its simplicity. All languages ​​need to be studied hard by themselves. Today’s hard work will reflect the results of tomorrow. Let’s start learning Go language together! !

The first article: Getting started

##1.1, programming and programming language

As the beginning of any programming language, the first thing we need to understand is: What is the purpose of programming? What is a programming language? What is programming?

###1.1.1、The purpose of programming

The invention of the computer was to liberate manpower with machines and eventually completely replace manpower. The purpose of programming is to transfer human thinking logic to the computer in a certain expression that can be recognized by the computer, so that the computer can work like a human.

###1.1.2 What is a programming language

The above-mentioned expression that can be recognized by the computer is the programming language. The language is the medium of communication, and the programming language is the medium for the programmer to communicate with the computer. In the world of programming, computers are more like human slaves. Humans use programming languages ​​to enslave the computer and let the computer complete the tasks assigned to it by the master.

###1.1.3、What is programming

Programming is that programmers write their own thinking logic according to the language format of a certain programming language according to their needs, and the result is a bunch of files, and there are a bunch of characters in the files.

##1.2, the classification of programming languages

###1.2.1 Classified according to the language itself:

1. Machine language:

From the perspective of a computer (slave), to speak a language that the computer can understand is to program directly in binary and directly manipulate the hardware. (The operation of computer hardware is based on current. Current pulses are divided into strengths and weaknesses. People use different combinations of strengths and weaknesses to achieve information transfer between hardware. Binary programming is born, and it only has 0 and 1, 0 represents weak pulse , 1 means strong pulse)

2. Assembly language:

From the perspective of the computer (slave), the abbreviated English identifier replaces the binary system to write programs, and the essence is still to directly manipulate the hardware.

(The machine language purely composed of 01 is very complicated and inconvenient to read and modify, so the abbreviated English identifier is used instead of 01, but its essence is still to directly operate the hardware)

such as:

Operation: transfer the contents of the register AX to AX

1000100111011000 Machine Instructions

mov ax, bx assembly instructions

3. High-level language:

From the perspective of people (slave owners), speaking human words means using human characters to write programs, shielding hardware operations

The high-level language is closer to the human language, which has caused it: it must be translated into a computer that can read the binary before it can be executed.

###1.2.2 Classified according to translation method:

**1. Compiled language (need a compiler, equivalent to Google Translate): ** Such as C, fast execution speed, troublesome debugging

**2. Interpreted language (an interpreter is required, equivalent to simultaneous interpretation): ** Such as python, slow execution speed and convenient debugging

###1.2.3 Summary:

1. Machine language:

Advantages: the lowest level, the fastest execution speed

Disadvantages: the most complex, the lowest development efficiency

2. Assembly language:

Advantages: relatively low-level, the fastest execution speed

Disadvantages: The disadvantages are complex and the development efficiency is the lowest

3. High-level language:

Compiled language has fast execution speed, does not rely on language environment to run, and is poor across platforms

Interpreted cross-platform is good, one code can be used everywhere, the disadvantage is that the execution speed is slow and it depends on the interpreter

##1.3, go language introduction

Go language is also called Golong language, which is launched by Google Goggle.

The main developers are: Ken Thompson, Rob Pike and Robert Griesemer.

According to the Go language developer's self-report, in the past 10 years, from the C language in the stand-alone era to the Java in the Internet era, there is no satisfactory development language. C++ often gives people the feeling that it takes 100% of the experience, but The development efficiency is only 60%, the output ratio is too low, and the philosophy of Java and C# comes from C++. Moreover, with the continuous upgrading of hardware, these languages ​​cannot make full use of the hardware and CPU. Therefore, an efficient, concise, and open source language was born.

Go language is a very potential language because its application scenarios are currently very popular in the Internet, such as blockchain development, large-scale game server development, and distributed/cloud computing development. Internet companies like Goggle, Alibaba, and JD.com have all started to develop their products in the Go language.

Some projects that were originally developed using go language:

1. Docker project

Website: https://github.com/docker/docker

介绍:Docker是一种操作系统层面的虚拟化技术,可以在操作系统和应用程序之间进行隔离,也可以称之为容器。Docker可以在一台物理服务器上快速运行一个或多个实例。例如,启动一个CentOS操作系统,并在其内部命令行执行指令后结束,整个过程就像自己在操作系统一样高效。

2、golang项目

网址:https://github.com/golang/go

介绍:Go语言的早期源码使用C语言和汇编语言写成。从Go1.5版本自举后,完成使用Go语言自身进行编写。Go语言的源码对了解Go语言的底层调度有极大的参考意义,建议希望对Go语言有深入了解的读者读一读。

3、Kubernetes项目

网址:https://github.com/kubernetes/kubernetes

介绍:Google公司开发的构建于Docker之上的容器调度服务,用户可以通过Kubernetes集群进行云端容器集群管理。

4、etcd项目

网址:https://github.com/coreos/etcd

介绍:一款分布式、可靠的KV存储系统,可以快速进行云配置。

5、beego项目

网址:https://gitchub.com/astaxie/beego

介绍:beego是一个类似Python的Tornado框架,采用了RESTFul的设计思路,使用Go语言编写的一个极轻量级、高可伸缩性和高性能的Web应用框架。

6、martini项目

网址:https://github.com/go-martini/martini

介绍:一款快速构建模块化的Web应用的Web框架

7、codis项目

网址:https://github.com/CodisLabs/codis

介绍:国产的优秀分布式Redis解决方案

8、delve项目

网址:https://github.com/derekpaker/delve

介绍:Go语言强大的调试器,被很多集成环境和编辑器整合

##1.4安装go开发包及集成开发环境

###1.4.1、安装go开发包

要学习Go语言,首先得学会Go语言开发包的安装和使用

1、下载开发包

建议去go语言中文网下载,网址:https://studygolang.com/dl

下图是下载页面及包介绍

2、Windows版安装

一路next就OK,建议安装在C盘

在cmd命令行窗口输入“go version”可以查看当前Go版本,用以检测是否安装成功

2、Linux版安装

a、将go1.11.linux-amd64.tar.gz解压到/user/local/go下,可以用下列命令来完成:

tar -C /user/local -xzf go1.11.linux-amd64.tar.gz

b、将/user/local/go/bin目录添加到PATH环境变量中,可以使用以下命令来完成:

export PATH=$PATH:/user/local/go/bin

c、使用go env指令来查看Go压缩包是否安装成功

###1.4.2、搭建集成开发环境

集成开发环境可以大大的提高程序员的开发效率。这里推荐使用由Jetbrains公司开发的goland

1、下载及安装

土豪请支持正版,到官方网站上下载:https://www.jetbrains.com/go/

非土豪自行百度goland破解,相关资料很多很详细。

安装过程依旧很简单,一路next即可

2、设置GOROOT

goland的正常运行依赖于go语言开发包,GOROOT就是用来指定GO开发包的,需要设置为Go语言的安装路径。goland正常情况下会自动识别,但如果编译错误,就需要手动设置GOROOT,步骤如下:

3、设置GOPATH(后面章节会进行讲解)

GOPATH是需要指定一个或者多个工作区目录(文件夹)的路径。工作区是我们自定义的工作空间,我们编写的代码和编译后产生的可执行文件(windows中以.exe结尾的文件)都会被放在这个目录中,即工作空间

步骤:

1、手动在D盘中建立文件夹GoWorks(这个名称可以自定义),并在Goworks下建立三个子文件夹,分别命名为src,bin,pkg

2、在file–setting–Go–GOPATH中找到Progect GOPATH,然后点击右边的“+”号,添加自己的工作空间D:\GoWorks

工作空间可以放在你喜欢的任意位置,便于你记忆和查找就行,但建议和go开发包的安装路径分开。


Guess you like

Origin blog.51cto.com/15064427/2665741