go语言编程入门_Go编程入门

go语言编程入门

Go Programming language was designed by Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson with an aim for it to be “C for the 21

Google于2007年由Robert Griesemer,Rob Pike和Ken Thompson设计了Go编程语言,旨在使其成为“面向21世纪的C语言”

st century”. It is basically an open-source, general-purpose, statically-typed language and belongs to the C-family. So users who are familiar with C programming syntaxes might not find it difficult. The need for this new language was generated because C/C++ didn’t evolve corresponding with computing landscape. In past decade no other system language was introduced to fit the requirements to this evolving computing era. Hence, Go Programming language emerged as a low-level language which was equipped with higher concepts. It was presented as an efficient language with fast compilation, easy programming, and fast execution. Programs here are generated by means of packages for accurate management of dependencies. This language uses a traditional compile and link model for generation of executable binaries. 世纪”。 它基本上是一种开源的,通用的,静态类型的语言,属于C系列。 因此,熟悉C编程语法的用户可能会发现困难。 之所以产生这种新语言的需求,是因为C / C ++并未随着计算环境的发展而发展。 在过去的十年中,没有引入其他系统语言来满足这个不断发展的计算时代的要求。 因此,Go编程语言成为一种具有较高概念的低级语言。 它是一种高效的语言,具有快速编译,易于编程和快速执行的功能。 此处的程序是通过软件包生成的,用于精确管理依赖关系。 该语言使用传统的编译和链接模型来生成可执行二进制文件。

Traits of Go Programming

Go编程的特点

  • Go language supports the dynamic language-like environment adopting patterns for ease of programming. This language is type-safe and also memory-safe.

    Go语言支持采用动态语言的环境,采用易于编程的模式。 此语言是类型安全的,也是内存安全的。
  • Minimal amount of keywords are used concisely in order to reduce the complexity and clutter in coding. Design concepts also are less complex and being Orthogonal do not interrupt.

    简洁地使用最少的关键字,以减少编码的复杂性和混乱度。 设计概念也不太复杂,并且“正交”不会中断。
  • Like Java and C++, Go language is not object-oriented and is not integrated with concepts like inheritance and classes. But it supports concept of interfaces and hence some extent of polymorphism can be achieved.

    像Java和C ++一样,Go语言也不面向对象的 ,也不与继承和类之类的概念集成在一起。 但是它支持接口的概念,因此可以实现一定程度的
  • Despite of being embedded with expressive type-system, it is lightweight and does not represent hierarchy and thus it can be called as hybrid language.

    尽管已嵌入表达型系统,但它是轻量级的,并且不表示层次结构,因此可以称为
  • Go was conceptualized as systems programming language to be used in heavy web servers, networking systems, storage architectures, and similar fields and it surpassed as productive language.

    Go被概念化为系统编程语言,可用于重型Web服务器,网络系统,存储体系结构和类似领域,并且已超越了生产语言。
  • It can fit well for needs of game server development, complex event processing (CEP), text-processing problems, scripting-like applications, etc.

    它非常适合游戏服务器开发,复杂事件处理(CEP),文本处理问题,类似脚本的应用程序等需求。
  • Some of the features have been removed as well which include; no function operator, no implicit conversions, no classes or type inheritance, no dynamic code loading, no generics, no dynamic libraries, no exceptions, no assertions, no immutable variables, etc.

    某些功能也已删除,其中包括; 没有函数运算符,没有隐式转换,没有类或类型继承,没有动态代码加载,没有泛型,没有动态库,没有异常,没有断言,没有不可变变量,等等。

Installation for Distinct Platforms

不同平台的安装

Different compilers were developed for below mentioned Operating Systems:

针对以下提到的操作系统开发了不同的编译器:

  • Linux

    的Linux
  • FreeBSD

    FreeBSD
  • OS X

    OS X
  • FreeBSD 7+: amd64, 386

    FreeBSD 7+:amd64、386
  • Linux 2.6: amd64, 386, arm

    Linux 2.6:amd64、386,arm
  • OS X: amd64, 386

    OS X:amd64、386
  • Windows (2000 + later): amd64, 386

    Windows(2000以上版本):amd64、386

Step-wise Installation of Go on Windows System

在Windows系统上分步安装Go

Step 1: Perform Go Installation on Windows

步骤1在Windows上执行Go安装

Users can install the Go language program either by downloading: Zip Archive or MSI Installer. Separate files are available for Windows 32 bits and 64 bits Operating System architectures.

用户可以通过下载Zip ArchiveMSI Installer来安装Go语言程序 Windows 32位和64位操作系统体系结构可使用单独的文件。

Zip Archive:

压缩档案

  • Download the files according to the Architecture:

    根据架构下载文件:
step1.png
  • Extract the .zip file and extract to the directory (prefer C:\Go).

    解压缩.zip文件并解压缩到目录(首选C:\ Go)。
  • If you choose any other directory (not C:\Go), then you will have to set GOROOT environment variable.

    如果选择任何其他目录(不是C:\ Go),则必须设置GOROOT环境变量。
  • Add the bin subdirectory of Go root (C:\Go\bin) to Path available in Environment Variable option. (This can be done by editing the Path option in Environment Variable available in Computer>>Properties>>Advanced System Settings>> Advanced.)

    将“转到根目录”的bin子目录(C:\ Go \ bin)添加到“环境变量”选项中可用的路径中。 (这可以通过编辑“

MSI Installer:

MSI安装程序:

  • Download the MSI installer files as per Architecture:

    根据体系结构下载MSI安装程序文件:
step2.png
  • Double-click the MSI file and install it as per prompted.

    双击MSI文件并按照提示进行安装。
  • By default Go distribution will be saved to C:\Go.

    默认情况下,Go分发将保存到C:\ Go。
  • Put the C:\Go\bin directory in the PATH available in Environment Variable. 

    将C:\ Go \ bin目录放在环境变量中可用的PATH中。
system-properties.png

Step 2: Check the Installation is Successful or Not

步骤2检查安装成功与否

Once the installation is done, users can check whether it was installed successfully or not by running a basic program. Before that try to run some basic commands using Command Prompt.

安装完成后,用户可以通过运行基本程序来检查安装是否成功。 在此之前,请尝试使用命令提示符运行一些基本命令。

  • Check if Go folder is created in C drive or not.

    检查是否在C驱动器中创建了Go文件夹。
  • Start Command Prompt (cmd) and direct it to C:\Go and the run “Go version” command.

    启动命令提示符(
command.png
  • Type go and details about Go programming language will be displayed along with the commands.

    输入go,有关Go编程语言的详细信息将与命令一起显示。
command2.png

Step 3: Method to Create Directories

步骤3创建目录的方法

  • Create a new folder for saving the programs. Here we created a folder in C drive as “Go Projects”.

    创建一个新文件夹以保存程序。 在这里,我们在C驱动器中创建了一个文件夹“ Go Projects ”。
  • Direct to this newly created folder and make directories following the below mentioned mkdir commands.

    定向到此新创建的文件夹,并按照以下提到的
command3.png

Step 4: Get a Text Editor for Writing Programs

步骤4获取用于编写程序的文本编辑器

A Go program has to be written in text files with the extension “.go”. Any text editor can be used for writing programs. Here we have used Sublime Text2 Editor for creating programs in which the source code for program is written.

必须将Go程序编写为扩展名为“ .go”的文本文件。 任何文本编辑器均可用于编写程序。 在这里,我们使用Sublime Text2编辑器来创建程序,并在其中编写程序的源代码。

Note: You can take help of any Text Editor as per your convenience and OS available like; Windows Notepad, Epsilon, SciTE, OS Edit command, Brief, EMACS, Xcode3, KD Kate, BBEdit, JEdit, Notepad++, SlickEdit, NetBeans, and vim or vi.

注意 :您可以根据方便和可用的操作系统来使用任何文本编辑器; Windows记事本,Epsilon,SciTE,OS Edit命令,Brief,EMACS,Xcode3,KD Kate,BBEdit,JEdit,Notepad ++,SlickEdit,NetBeans和vim或vi。

Step 5: Check the Installation Via Simple Program

步骤5通过简单程序检查安装

  • Write a basic program which will give Output “Hello Windows” using Sublime Text Editor.

    编写一个基本程序,使用Sublime Text Editor提供输出“ Hello Windows”。
  • Copy the below mentioned source code:

    复制下面提到的源代码:
command4.png
  • The first line defines the package name where the program lies. This statement is a must as Go programs runs in packages. main package can be depicted as starting point for running the program.

    第一行定义程序所在的程序包名称。 该声明是必须的,因为
  • Next is import fmt which is preprocessor command pointing Go compiler to include files lying in package fmt.

    接下来是
  • Next is func main () where the execution starts.

    接下来是
  • If any comment is provided /*_*/, it will not be read by compiler.

    如果提供任何注释/ * _ * /,编译器将不会读取它。
  • Next is fmt.Println (…) is another function displaying the message “Hello Windows”. fmt package exports Println method for displaying this message.

    接下来是
  • The program in Sublime will appear as;

    Sublime中的程序将显示为;
command5.png
  • Save this text file as hello.go in the same folder which was created for Go programs i.e. Go Projects folder.

    将该文本文件另存为hello.go,位于为Go程序创建的文件夹中,即Go Projects文件夹。

Step 6: Execute the Program Using CMD

步骤6使用CMD执行程序

  • Run the hello.go in order to see the output.

    运行hello.go以查看输出。
  • Type below mentioned commands;

    输入以下提到的命令;
command6.png
  • Check the Output Results:

    检查输出结果:
command7.png
command8.png

In Conclusion:

结论:

So this is the basic guideline to try your hands on Go programming language. This will introduce you with the 21st century programming style. It is easy for installation which can be checked using the basic program stated above. Of course this is just a beginning and there is a way to go learning about Types and Variables used by Go, Collection Types, Strings, pointers, Procedural/O-O Programming, Concurrent Programming, File handling, Packages, Application in Go, etc. But this will help you to have a headstart for Go language.

因此,这是尝试使用Go编程语言的基本指南。 这将向您介绍与21 世纪的编程风格。 安装简便,可以使用上述基本程序进行检查。 当然,这仅仅是一个开始,有一种方法可以了解Go使用的类型和变量,集合类型,字符串,指针,过程/ OO编程,并发编程,文件处理,包,Go中的应用程序等。但是这将帮助您抢先体验Go语言。

翻译自: https://www.experts-exchange.com/articles/19940/Getting-Started-With-Go-Programming.html

go语言编程入门

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值