imtoken钱包官方下载
数字资产服务平台

imtoken钱包官方下载是全球著名的数字资产交易平台之一,主要面向全球用户提供比特币、莱特币、以太币等数字资产的币币和衍生品交易服务。

imtoken钱包网站|golang语言

时间:2024-03-16 22:58:22

Go 语言教程 | 菜鸟教程

Go 语言教程 | 菜鸟教程

菜鸟教程 -- 学的不仅是技术,更是梦想!

首页

HTML

CSS

JavaScript

Vue

Bootstrap

NodeJS

Python3

Python2

Java

C

C++

C#

Go

SQL

Linux

jQuery

本地书签

首页

HTML

CSS

JS

本地书签

Search

Python3 教程

Python2 教程

Vue3 教程

vue2 教程

Bootstrap3 教程

Bootstrap4 教程

Bootstrap5 教程

Bootstrap2 教程

Go 语言教程

Go 语言教程

Go 语言环境安装

Go 语言结构

Go 语言基础语法

Go 语言数据类型

Go 语言变量

Go 语言常量

Go 语言运算符

Go 语言条件语句

Go 语言循环语句

Go 语言函数

Go 语言变量作用域

Go 语言数组

Go 语言指针

Go 语言结构体

Go 语言切片(Slice)

Go 语言范围(Range)

Go 语言 Map(集合)

Go 语言递归函数

Go 语言类型转换

Go 语言接口

Go 错误处理

Go 并发

Go 语言开发工具

Go 语言环境安装

Go 语言教程

Go 是一个开源的编程语言,它能让构造简单、可靠且高效的软件变得容易。

Go是从2007年末由Robert Griesemer, Rob Pike, Ken Thompson主持开发,后来还加入了Ian Lance Taylor, Russ Cox等人,并最终于2009年11月开源,在2012年早些时候发布了Go 1稳定版本。现在Go的开发已经是完全开放的,并且拥有一个活跃的社区。

Go 语言特色

简洁、快速、安全

并行、有趣、开源

内存管理、数组安全、编译迅速

Go 语言用途

Go 语言被设计成一门应用于搭载 Web 服务器,存储集群或类似用途的巨型中央服务器的系统编程语言。对于高性能分布式系统领域而言,Go 语言无疑比大多数其它语言有着更高的开发效率。它提供了海量并行的支持,这对于游戏服务端的开发而言是再好不过了。

第一个 Go 程序

接下来我们来编写第一个 Go 程序 hello.go(Go 语言源文件的扩展是 .go),代码如下:

hello.go 文件

package main

import "fmt"

func main() {

    fmt.Println("Hello, World!")

}

运行实例 »

要执行 Go 语言代码可以使用 go run 命令。

执行以上代码输出:

$ go run hello.go

Hello, World!

此外我们还可以使用 go build 命令来生成二进制文件:

$ go build hello.go

$ ls

hello    hello.go

$ ./hello

Hello, World!

Go 语言环境安装

1 篇笔记

写笔记

#0   LeonWilliam  257***8572@qq.com 2575计算机软件经历了数十年的发展,形成了多种学术流派,有面向过程编程、面向对象编程、函数式编程、面向消息编程等,这些思想究竟孰优孰劣,众说纷纭。

除了OOP外,近年出现了一些小众的编程哲学,Go语言对这些思想亦有所吸收。例如,Go语言接受了函数式编程的一些想法,支持匿名函数与闭包。再如,Go语言接受了以Erlang语言为代表的面向消息编程思想,支持goroutine和通道,并推荐使用消息而不是共享内存来进行并发编程。总体来说,Go语言是一个非常现代化的语言,精小但非常强大。

Go 语言最主要的特性:

自动垃圾回收

更丰富的内置类型

函数多返回值

错误处理

匿名函数和闭包

类型和接口

并发编程

反射

语言交互性LeonWilliam   LeonWilliam  257***8572@qq.com6年前 (2018-03-27)

点我分享笔记

取消

分享笔记

昵称昵称 (必填)

邮箱邮箱 (必填)

引用地址引用地址

分类导航

HTML / CSSHTML 教程HTML5 教程CSS 教程CSS3 教程Bootstrap3 教程Bootstrap4 教程Bootstrap5 教程Font Awesome 教程Foundation 教程 JavaScriptJavaScript 教程HTML DOM 教程jQuery 教程AngularJS 教程AngularJS2 教程Vue.js 教程Vue3 教程React 教程TypeScript 教程jQuery UI 教程jQuery EasyUI 教程Node.js 教程AJAX 教程JSON 教程Echarts 教程Chart.js 教程Highcharts 教程Google 地图 教程 服务端Python 教程Python2.x 教程Linux 教程Docker 教程Ruby 教程Java 教程C 教程C++ 教程Perl 教程Servlet 教程JSP 教程Lua 教程Rust 教程Scala 教程Go 教程PHP 教程数据结构与算法Django 教程FastAPI 教程Zookeeper 教程设计模式正则表达式Maven 教程Verilog 教程ASP 教程AppML 教程VBScript 教程 数据库SQL 教程MySQL 教程PostgreSQL 教程SQLite 教程MongoDB 教程Redis 教程Memcached 教程 数据分析Python 教程NumPy 教程Pandas 教程Matplotlib 教程Scipy 教程R 教程Julia 教程 移动端Android 教程Swift 教程jQuery Mobile 教程ionic 教程Kotlin 教程 XML 教程XML 教程DTD 教程XML DOM 教程XSLT 教程XPath 教程XQuery 教程XLink 教程XPointer 教程XML Schema 教程XSL-FO 教程SVG 教程 ASP.NETASP.NET 教程C# 教程Web Pages 教程Razor 教程MVC 教程Web Forms 教程 Web ServiceWeb Service 教程WSDL 教程SOAP 教程RSS 教程RDF 教程 开发工具Eclipse 教程Git 教程Svn 教程Markdown 教程 网站建设HTTP 教程网站建设指南浏览器信息网站主机教程TCP/IP 教程W3C 教程网站品质

Advertisement

反馈/建议

在线实例

·HTML 实例

·CSS 实例

·JavaScript 实例

·Ajax 实例

·jQuery 实例

·XML 实例

·Java 实例

字符集&工具

· HTML 字符集设置

· HTML ASCII 字符集

· JS 混淆/加密

· PNG/JPEG 图片压缩

· HTML 拾色器

· JSON 格式化工具

· 随机数生成器

最新更新

·

Rust 宏

·

Seaborn 教程

·

Pandas 相关性分析

·

31.2k star, 免...

·

Dev Home —...

·

免费开源的 AI ...

·

11.2k star, 免...

站点信息

·

意见反馈

·

免责声明

·

关于我们

·

文章归档

关注微信

Copyright © 2013-2024 菜鸟教程 

runoob.com All Rights Reserved. 备案号:闽ICP备15012807号-1

微信关注

The Go Programming Language

The Go Programming Language

Skip to Main Content

Why Go arrow_drop_down

Press Enter to activate/deactivate dropdown

Case Studies

Common problems companies solve with Go

Use Cases

Stories about how and why companies use Go

Security

How Go can help keep you secure by default

Learn

Press Enter to activate/deactivate dropdown

Docs arrow_drop_down

Press Enter to activate/deactivate dropdown

Effective Go

Tips for writing clear, performant, and idiomatic Go code

Go User Manual

A complete introduction to building software with Go

Standard library

Reference documentation for Go's standard library

Release Notes

Learn what's new in each Go release

Packages

Press Enter to activate/deactivate dropdown

Community arrow_drop_down

Press Enter to activate/deactivate dropdown

Recorded Talks

Videos from prior events

Meetups

open_in_new

Meet other local Go developers

Conferences

open_in_new

Learn and network with Go developers from around the world

Go blog

The Go project's official blog.

Go project

Get help and stay informed from Go

Get connected

Why Go navigate_next

navigate_beforeWhy Go

Case Studies

Use Cases

Security

Learn

Docs navigate_next

navigate_beforeDocs

Effective Go

Go User Manual

Standard library

Release Notes

Packages

Community navigate_next

navigate_beforeCommunity

Recorded Talks

Meetups

open_in_new

Conferences

open_in_new

Go blog

Go project

Get connected

Build simple, secure, scalable systems with Go

An open-source programming language supported by Google

Easy to learn and great for teams

Built-in concurrency and a robust standard library

Large ecosystem of partners, communities, and tools

Get Started

Download

Opens a new window with the Get Started guide.

Opens a new window to download Go.

Download packages for

Windows 64-bit,

macOS,

Linux, and

more

The go command by default downloads and authenticates

modules using the Go module mirror and Go checksum database run by

Google. Learn more.

Opens in new window.

Companies using Go

Organizations in every industry use Go to power their software and services

View all stories

View case study

View case study

View case study

View case study

“At the time, no single team member knew Go, but

within a month, everyone was writing in Go and we were

building out the endpoints. It was the flexibility, how easy it was to use,

and the really cool concept behind Go (how Go handles native concurrency,

garbage collection, and of course safety+speed.) that helped engage us

during the build. Also, who can beat that cute mascot!”

— Jaime Enrique Garcia Lopez,

Senior Software Development Manager

at Capital One

"A small language that compiles fast makes for a happy developer.

The Go language is small, compiles really fast, and as a result it lets your

mind focus on the actual problem and less on the tool you are using to solve

it. Code, test, debug cycles are so quick that you forget you are not

working with an interpreted language. Looking at our code, you see

less boilerplate and more business logic."

— Clayton Coleman,

Lead Engineer, Open Shift

at RedHat

“Go has excellent characteristics for scalability and services

written using it typically have very small memory footprints.

Because code is compiled into a single static binary, services can also be

containerised with ease, making it much simpler to build and deploy. These

attributes make Go an ideal choice for companies building

microservices, as you can easily deploy into a highly available and

scalable environment such as Kubernetes.”

— Matt Boyle,

Lead Software Engineer

at Curve

"In our tightly managed environments where we run Go code,

we have seen a CPU reduction of approximately 10%

with cleaner and maintainable code."

— Bala Natarajan,

Sr. Director of Engineering, Developer Experience

at PayPal

"Tooling has always been a problem with our legacy code base... but we have

found that Go has excellent tooling, plus built-in testing, benchmarking,

and profiling frameworks. It is easy to write efficient and resilient

applications. After working on Go, most of our developers don't want

to go back to other languages."

— Benjamin Cane,

Vice President and Principal Engineer

at American Express

"...when a programming language is designed for exactly the environment most

of us use right now—scalable, cloud-based servers that are optimized for

performance—a lot can go right."

— John Biggs and Ben Popper,

at Stack Overflow

navigate_before

navigate_next

Try Go

Press Esc to move out of the editor.

// You can edit this code!

// Click here and start typing.

package main

import "fmt"

func main() {

fmt.Println("Hello, 世界")

}

Press Esc to move out of the editor.

Hello, 世界

Hello, World!

Conway's Game of Life

Fibonacci Closure

Peano Integers

Concurrent pi

Concurrent Prime Sieve

Peg Solitaire Solver

Tree Comparison

Run

Tour

What’s possible with Go

Use Go for a variety of software development purposes

Cloud & Network Services

With a strong ecosystem of tools and APIs on major cloud providers, it is easier than ever to build services with Go.

Popular Packages:

cloud.google.com/go

aws/client

Azure/azure-sdk-for-go

Learn More

arrow_forward

Command-line Interfaces

With popular open source packages and a robust standard library, use Go to create fast and elegant CLIs.

Popular Packages:

spf13/cobra

spf13/viper

urfave/cli

delve

chzyer/readline

Learn More

arrow_forward

Web Development

With enhanced memory performance and support for several IDEs, Go powers fast and scalable web applications.

Popular Packages:

net/http

html/template

flosch/pongo2

database/sql

elastic/go-elasticsearch

Learn More

arrow_forward

DevOps & Site Reliability

With fast build times, lean syntax, an automatic formatter and doc generator, Go is built to support both DevOps and SRE.

Popular Packages:

open-telemetry/opentelemetry-go

istio/istio

urfave/cli

Learn More

arrow_forward

More use cases

arrow_forward

Get started with Go

Explore a wealth of learning resources, including guided journeys, courses, books, and more.

Get Started

Download Go

Resources to start on your own

Guided learning journeys

Step-by-step tutorials to get your feet wet

Online learning

Browse resources and learn at your own pace

Featured books

Read through structured chapters and theories

Cloud Self-paced labs

Jump in to deploying Go apps on GCP

In-Person Trainings

Ardan Labs

Offering customized on-site live training classes.

Gopher Guides

Customized In-person, remote, and online training classes. Training for Developers by Developers.

Boss Sauce Creative

Personalized or track-based Go training for teams.

Shiju Varghese

On-site classroom training on Go and consulting on distributed systems architectures, in India.

Why Go

Use Cases

Case Studies

Get Started

Playground

Tour

Stack Overflow

Help

Packages

Standard Library

About Go Packages

About

Download

Blog

Issue Tracker

Release Notes

Brand Guidelines

Code of Conduct

Connect

Twitter

GitHub

Slack

r/golang

Meetup

Golang Weekly

Opens in new window.

Copyright

Terms of Service

Privacy Policy

Report an Issue

go.dev uses cookies from Google to deliver and enhance the quality of its services and to

analyze traffic. Learn more.

Okay

什么是 Go 或 Golang 编程语言? - 知乎

什么是 Go 或 Golang 编程语言? - 知乎切换模式写文章登录/注册什么是 Go 或 Golang 编程语言?极客事纪​已认证账号Go,也称为 Golang 或 Go 语言,是Google 开发的一种开源编程语言。软件开发人员在一系列操作系统和框架中使用 Go 来开发 Web 应用程序、云和网络服务以及其他类型的软件。Go 是静态类型的、显式的,并且是在C编程语言之后建模的。由于 Go 语言的快速启动时间、低运行时开销以及无需虚拟机 ( VM ) 即可运行的能力,它已成为一种非常流行的用于编写微服务和其他用途的语言。此外,Go 还用于并发编程——一种一次无序或部分顺序执行多个任务的策略。Go 语言的灵感来自Python的生产力和相对简单性。它使用 goroutines 或轻量级进程,以及一组包来进行高效的依赖管理。它旨在解决几个问题,包括缓慢的构建时间、不受控制的依赖性、重复工作、难以编写自动工具和跨语言开发。Golang的历史为什么大厂都在转向Go语言?Go语言会是开发者的最后归宿吗?Golang的历史Google 创建 Go 是为了解决自己的软件工程问题,并提供C++的替代方案。此外,随着多核处理器变得越来越流行,当时需要一种具有更高生产力水平的语言。Google 于 2007 年开始设计 Go。Go 开发人员希望创建一种更易于使用的编程语言,但仍具有其他语言(如 C++、Python 和JavaScript)所具有的有用特性。Go 于 2009 年作为一个开源项目被宣布,社区成员可以在其中就想法和代码进行协作。1.0 版随后于 2012 年发布。多年来,增加了新的更新和功能,例如 2022 年的泛型。Go 的受欢迎程度持续增长,因为它被谷歌、Cloudflare、Dropbox、MongoDB、Netflix、SoundCloud、Twitch 和 Uber 等知名公司使用.Go 编程语言有什么作用?Go 团队利用该语言的特性来开发软件:标准库基于分布式包的使用,可以轻松地在代码中添加和使用附加功能。代码包管理允许管理用户创建的和外部代码包,并允许使用一小组命令发布包。静态类型提供了一种类型系统,可确保转换和兼容性,同时避免动态类型语言带来的问题。对测试的支持包括与编写的代码并行运行并允许调试和质量保证的单元测试。平台独立性利用 Go 的模块化设计使其代码几乎可以在任何平台上编译。并发模型基于行为类似于线程的轻量级 goroutines 和促进 goroutines 之间通信的通道机制。代码的语法模仿了动态语言中常用的基本模式,并且支持组合接口而不是继承。这使开发人员能够编写可以同时执行多项任务的程序。以下是 Go 的一些工具:Gofmt自动格式化和缩进代码以提高可读性。Go run同时编译和运行代码。Go get与GitHub集成。Godoc根据代码结构和开发者注释生成基于超文本标记语言的文档。Go test运行单元测试和基准测试,启用代码测试和性能数据的收集。Go build将 Go 包和依赖项编译成可执行库。Go vet检查 Go源代码中的错误和可疑结构。围棋的好处使用 Go 的好处包括:快速的编译和执行速度;不需要虚拟机;可移植性;并发性;接口支持松散耦合的系统;自动垃圾收集;内存安全;独立的错误处理;和广泛的内置库。围棋的局限性Go 确实有一些缺点,例如:尽管增加了泛型,仍然专注于简单、可读的代码,而不是抽象的、隐式的代码;缺乏运行时安全;执行严格的规则;与函数重载不兼容;和不是传统上面向对象的。围棋有什么用?软件开发团队使用 Go 来创建各种软件应用程序:集装箱服务。Docker和Kubernetes等容器服务使用 Go 来实现并发性和可移植性。网络和云服务。Go 的并发特性以及工具和 API 生态系统使其非常适合网络服务、分布式函数和云服务。例如,OpenShift 和 Terraform 等云服务使用 Go 来创建 API 和高性能 Web 服务器。比特币的闪电网络和其他复杂的区块链技术使用围棋。网页服务。Go 的标准库中内置的超文本传输​​协议服务器使其对 Netflix 和 Twitch 等公司开发 Web 服务和服务器端架构非常有用。命令行实用程序。Terraform 和 OpenShift 等公司利用 Go 的简单语法、短运行时间、开源代码包和相对庞大的标准库来创建命令行界面。公用事业。Go 程序启动迅速,并且由于其最少的编译而可以轻松地重新分发。这使得 Go 非常适合创建工具,例如像 Teleport 这样的访问服务器。微服务。Go 语言的快速启动时间、低运行时开销以及无需 VM 即可运行的能力使其在编写微服务方面非常受欢迎。Uber 和 BBC 等公司将其用于此目的。数据科学。Go 的并发性和内存管理使其成为数据科学家并行处理和分析大型数据集的不错选择。Go 及其库也可用于机器学习,以开发预测模型和执行其他任务。Go 与其他编程语言相比如何?Golang 具有与其他编程语言类似的特性,但它提供了一个独特的替代方案:Go 的主要设计目标是促进快速编译,这与其他一些通用语言不同。C++Go 和 C++ 有一些关键的区别,例如:Go 减少了运行时错误和依赖项的数量,同时提高了内存安全性和内存管理。C++ 不会做所有这些,因为它使用手动内存管理。Go 使用比 C++ 更简单、更现代的语法。Go 使得编写并发和并行代码变得更加容易,因为它通过 goroutines 和通道内置了对并发的支持,这与依赖线程和锁的 C++ 不同。Go 的标准库比 C++ 小。红宝石Go 与Ruby的主要区别如下:Go 使用比 Ruby 更简单的语法。Go 使用静态类型系统来帮助捕获编译期间的错误;Ruby 需要解释器来编译和运行代码,这意味着编译可能需要更长的时间。Go 使用内置的并发性,而 Ruby 依赖于线程和锁,这使得 Go 更适合并发代码。Go 的标准库比 Ruby 小。和Java比较Go 和Java 的主要区别如下:Go 使用比 Java 更简单的语法。Go 的运行时和编译速度通常比 Java 快,Java 需要 VM 来运行其代码。Go 使用内置的并发性,而 Java 依赖于线程和锁。Go 的标准库比 Java 小。学习 Go 编程语言众所周知,Go 对于初学者来说简单易学。极客事纪提供学习 Go 的资源,例如交互式教程、Go 之旅、指南和解释文章。在其主页上提供了 Go 的演示,潜在用户可以在这里试用。学习 Go 的最佳方法之一是通过其官方 Go 教程。这些教程涵盖了该语言的基础知识,让初学者可以按照说明执行 Go 代码。用户可以在学习教程的同时参考Go的官方文档,实时学习概念并将所学知识应用于教程中的挑战。程序员还可以尝试自己的小型 Go 项目,并参与在线 Go 社区来学习这门语言。在线社区包括博客、YouTube 视频和 Reddit 等网站上的活跃用户。极客事纪社区还提供了关于如何学习这门语言的自己的课程和模块。发布于 2023-04-13 11:50・IP 属地北京编程语言计算机编程语言Go 语言​赞同 4​​添加评论​分享​喜欢​收藏​申请

《Go 入门指南》 | Go 技术论坛

《Go 入门指南》 | Go 技术论坛

Go

话题列表

社区 Wiki

优质外文

招聘求职

Go 实战教程

社区文档

登录

注册

Go

首页

Laravel

Go

PHP

Python

Vue.js

Java

MySQL

Rust

LK

Elasticsearch

F2E 前端

程序员

Server

Database

DevTools

Computer Science

手机开发

AdonisJS

社区

Wiki

教程

Go 实战教程首页

《G01 Go 实战:Web 入门》

《G02 Go API 实战》

《GX1 Golang 五分钟视频》

文档

社区文档首页

《高效的 Go 编程 Effective Go》

《Go Blog 中文翻译》

《Go 简易教程》

《Go 编程实例 Go by Example》

《Go 入门指南》

《Go 编程基础(视频)》

《Go Web 编程》

《Iris 框架中文文档》

《通过测试学习 Go 编程》

《Gin 框架中文文档》

《GORM 中文文档》

《Go SQL 数据库教程》

登录

注册

微信登录

进度 96.92%

Go 入门指南

更新于 1年前

Github 上《The Way to Go》中文译本的镜像,优化了排版

文档类型:系统文档

文章统计:196 篇,字数 16.46 万,点赞 2127

文章列表

所有讨论

基础信息

镜像说明

前言

第一章. Go 起源,发展与普及

1.1. 起源与发展

1.2. 主要特性与发展的环境和影响因素

第二章. 安装与运行环境

2.1. 平台与架构

2.2. Go 环境变量

2.3. 在 Linux 上安装 Go

2.4. 在 Mac OS X 上安装 Go

2.5. 在 Windows 上安装 Go

2.6. 安装目录清单

2.7. Go 运行时(runtime)

2.8. Go 解释器

第三章. 编辑器、IDE 等工具

章节说明

3.1. Go 开发环境的基本要求

3.2. 编辑器和集成开发环境

3.3. 调试器

3.4. 构建并运行 Go 程序

3.5. 格式化代码

3.6. 生成代码文档

3.7. 其它工具

3.8. Go 性能说明

3.9. 与其它语言进行交互

第四章. 基本结构和基本数据类型

4.1. 文件名、关键字与标识符

4.2. Go 程序的基本结构和要素

4.3. 常量

4.4. 变量

4.5. 基本类型和运算符

4.6. 字符串

4.7. strings 和 strconv 包

4.8. 时间和日期

4.9. 指针

第五章. 控制结构

章节说明

5.1. if-else 结构

5.2. 测试多返回值函数的错误

5.3. switch 结构

5.4. for 结构

5.5. Break 与 continue

5.6. 标签与 goto

第六章. 函数(function)

章节说明

6.1. 介绍

6.2. 函数参数与返回值

6.3. 传递变长参数

6.4. defer 和追踪

6.5. 内置函数

6.6. 递归函数

6.7. 将函数作为参数

6.8. 闭包

6.9. 应用闭包:将函数作为返回值

6.10. 使用闭包调试

6.11. 计算函数执行时间

6.12. 通过内存缓存来提升性能

第七章. 数组与切片

章节说明

7.1. 数组声明和初始化

7.2. 切片

7.3. For-range 结构

7.4. 切片重组(reslice)

7.5. 切片的复制与追加

7.6. 字符串、数组和切片的应用

第八章. Map

章节说明

8.1. 声明、初始化和 make

8.2. 测试键值对是否存在及删除元素

8.3. for-range 的配套用法

8.4. map 类型的切片

8.5. map 的排序

8.6. 将 map 的键值对调

第九章. 包(package)

章节说明

9.1. 标准库概述

9.2. regexp 包

9.3. 锁和 sync 包

9.4. 精密计算和 big 包

9.5. 自定义包和可见性

9.6. 为自定义包使用 godoc

9.7. 使用 go install 安装自定义包

9.8. 自定义包的目录结构、go install 和 go test

9.9. 通过 Git 打包和安装

9.10. Go 的外部包和项目

9.11. 在 Go 程序中使用外部库

第十章. 结构与方法

章节说明

10.1. 结构体定义

10.2. 使用工厂方法创建结构体实例

10.3. 使用自定义包中的结构体

10.4. 带标签的结构体

10.5. 匿名字段和内嵌结构体

10.6. 方法

10.7. 类型的 String() 方法和格式化描述符

10.8. 垃圾回收和 SetFinalizer

第十一章. 接口与反射

章节说明

11.1. 接口是什么

11.2. 接口嵌套接口

11.3. 类型断言:如何检测和转换接口变量的类型

11.4. 类型判断:type-switch

11.5. 测试一个值是否实现了某个接口

11.6. 使用方法集与接口

11.7. 第一个例子:使用 Sorter 接口排序

11.8. 第二个例子:读和写

11.9. 空接口

11.10 反射包

11.12. 接口与动态类型

11.13. 总结:Go 中的面向对象

11.14. 结构体、集合和高阶函数

第十二章. 读写数据

章节说明

12.1. 读取用户的输入

12.2. 文件读写

12.3. 文件拷贝

12.4. 从命令行读取参数

12.5. 用 buffer 读取文件

12.6. 用切片读写文件

12.7. 用 defer 关闭文件

12.8. 使用接口的实际例子:fmt.Fprintf

12.9. JSON 数据格式

12.10. XML 数据格式

12.11. 用 Gob 传输数据

12.12. Go 中的密码学

第十三章. 错误处理与测试

章节说明

13.1. 错误处理

13.2. 运行时异常和 panic

13.3. 从 panic 中恢复(Recover)

13.4. 自定义包中的错误处理和 panicking

13.5. 一种用闭包处理错误的模式

13.6. 启动外部命令和程序

13.7. Go 中的单元测试和基准测试

13.8. 测试的具体例子

13.9. 用(测试数据)表驱动测试

13.10. 性能调试:分析并优化 Go 程序

第十四章. 协程与通道

章节说明

14.1. 并发、并行和协程

14.2. 协程间的信道

14.3. 协程的同步:关闭通道-测试阻塞的通道

14.4. 使用 select 切换协程

14.5. 通道、超时和计时器(Ticker)

14.6. 协程和恢复(recover)

14.7. 新旧模型对比:任务和worker

14.8. 惰性生成器的实现

14.9. 实现 Futures 模式

14.10. 多路复用

已完成

14.11. 限制并发数

已完成

14.12. 链式操作

已完成

14.13. 多核运算

已完成

14.14. 多核运算处理大量数据

已完成

14.15. 漏桶算法 Leaky Bucket

已完成

14.16. 标杆分析 Goroutines

已完成

14.17. 使用 Channel 来并发读取对象

已完成

第十五章. 网络,模板和网页应用

章节说明

15.1. tcp 服务器

15.2. 一个简单的网页服务器

15.3. 访问并读取页面

15.4. 写一个简单的网页应用

15.5. 让 Web 应用更加健壮

已完成

15.6. 在 Web 应用中使用模板

已完成

15.7. 探索 Template 扩展的功能

已完成

15.8. 一个多功能的精致的 WebServer

已完成

15.9. RPC 远程调用

已完成

15.10. 使用 netchan 跨网络实现消息传递

已完成

15.11. Websocket 通讯

已完成

15.12. SMTP 发送邮件

已完成

第十六章. 常见的陷阱与错误

章节说明

16.1. 误用短声明导致变量覆盖

16.2. 误用字符串

16.3 发生错误时使用defer关闭一个文件

16.4. 何时使用 new() 和 make()

16.5. 不需要将一个指向切片的指针传递给函数

16.6. 使用指针指向接口类型

16.7. 使用值类型时误用指针

16.8 误用协程和通道

16.9. 闭包和协程的使用

16.10. 糟糕的错误处理

第十七章. 模式

17.1. 关于逗号 ok 模式

17.2. defer 模式

已完成

17.3.能见度模式

已完成

17.4. 操作者模式和接口

已完成

第十八章. 性能调优代码片段

18.1. 字符串

18.2. 数组和切片

18.3. 映射

18.4. 结构体

18.5. 接口

18.6. 函数

18.7. 文件

18.8. 协程(goroutine)与通道(channel)

18.9. 网络和网页应用

18.10. 其他

18.11. 出于性能考虑的最佳实践和建议

第十九章. 构建完整的应用程序

19.1. 简介

已完成

19.2. UrlShortener 项目介绍

已完成

19.3. 数据结构分析

已完成

19.4. 用户界面:Web 网页前端

已完成

19.5. 数据存储: gob

已完成

19.6. 使用 Goroutines 来提高性能

已完成

19.7. 使用 Json 来存储

已完成

19.8. 多台机器上的多线程

已完成

19.9. 使用 ProxyStore

已完成

19.10. 总结和优化

已完成

第二十章. Google App 引擎中的 Go

章节说明

第二十一章. Go 现实世界中的使用

章节说明

已完成

21.2. MROffice — Go 实现的 VOIP 系统

已完成

21.3. Atlassian— 虚拟机集群管理系统

已完成

21.4. Camlistore 个人住址存储系统

已完成

社区赞助商

成为赞助商

关于 LearnKu

LearnKu 是终身编程者的修道场

做最专业、严肃的技术论坛

LearnKu 诞生的故事

资源推荐

《社区使用指南》

《文档撰写指南》

《LearnKu 社区规范》

《提问的智慧》

服务提供商

其他信息

成为版主

所有测验

联系站长(反馈建议)

粤ICP备18099781号-6

|

粤公网安备 44030502004330号

|

违法和不良信息举报

由 Summer 设计和编码 ❤

请登录

提交

忘记密码?

or

注册

第三方账号登录

微信登录

GitHub 登录

内容举报

匿名举报,为防止滥用,仅管理员可见举报者。

我要举报该,理由是:

垃圾广告:恶意灌水、广告、推广等内容

无意义内容:测试、灌水、文不对题、消极内容、文章品质太差等

违规内容:色情、暴利、血腥、敏感信息等

不友善内容:人身攻击、挑衅辱骂、恶意行为

科学上网:翻墙、VPN、Shadowsocks,政策风险,会被关站!

不懂提问:提问太随意,需要再做一遍《提问的智慧》测验

随意提问:提问没有发布在社区问答分类下

排版混乱:没有合理使用 Markdown 编写文章,未使用代码高亮

内容结构混乱:逻辑不清晰,内容混乱,难以阅读

标题随意:标题党、标题不释义

尊重版权:分享付费课程、破解软件(付费),侵犯作者劳动成果

其他理由:请补充说明

举报

取消

golang语言介绍 - 知乎

golang语言介绍 - 知乎首发于重学编程之Golang切换模式写文章登录/注册golang语言介绍PaynePrograming Language - GolangGolang官网地址:https://golang.org/Golang官方文档:https://golang.org/doc/Golang Packages:https://golang.org/pkg/Golang中文网:https://studygolang.com/Golang中文文档:http://docscn.studygolang.com/Golang中文Packages:https://studygolang.com/pkgdoc摘要Golang(又称Go)是Google公司开发的一种静态强类型、编译型、并发型,并具有垃圾回收功能的编程语言。罗伯特·格瑞史莫,罗勃·派克(Rob Pike)及肯·汤普逊于2007年9月开始设计GO,稍后Ian Lance Taylor、Russ Cox加入项目。Go是基于Inferno操作系统所开发的。Go于2009年11月正式宣布推出,成为开放源代码项目,支持Linux、macOS、Windows等操作系统。在2016年,Go被软件评价公司TIOBE 选为“TIOBE 2016 年最佳语言”。目前,Go每半年发布一个二级版本(即从a.x升级到a.y)。描述Go的语法接近C语言,但对于变量的声明有所不同。Go支持垃圾回收功能。Go的并行计算模型是以东尼·霍尔的通信顺序进程(CSP)为基础,采取类似模型的其他语言包括Occam和Limbo[3],Go也具有这个模型的特征,比如通道传输。通过goroutine和通道等并行构造可以建造线程池和管道等[8]。在1.8版本中开放插件(Plugin)的支持,这意味着现在能从Go中动态加载部分函数。与C++相比,Go并不包括如枚举、异常处理、继承、泛型、断言、虚函数等功能,但增加了 切片(Slice) 型、并发、管道、垃圾回收功能、接口等特性的语言级支持。Go 2.0版本将支持泛型[9],对于断言的存在,则持负面态度,同时也为自己不提供类型继承来辩护。不同于Java,Go原生提供了关联数组(也称为哈希表(Hashes)或字典(Dictionaries)),就像字符串类型一样。历史2007年,Google设计Go,目的在于提高在多核、网络机器(networked machines)、大型代码库(codebases)的情况下的开发效率。当时在Google,设计师们想要解决其他语言使用中的缺点,但是仍保留他们的优点。静态类型和运行时效率。(如:C++)可读性和易用性。(如:Python 和 JavaScript)[12]高性能的网络和多进程。设计师们主要受他们之间流传的“不要像C++”启发。Go于2009年11月正式宣布推出,[16]版本1.0在2012年3月发布。之后,Go广泛应用于Google的产品以及许多其他组织和开源项目。在2016年11月,Go(一种无衬线体)和Go Mono 字体(一种等宽字体)分别由设计师 Charles Bigelow 和 Kris Holmes 发布。 两种字体均采用了 WGL4 ,并且依照着 DIN 1450 标准,可清晰地使用了 large x-height 和 letterforms 。在2018年8月,本地的图标更换了 。待描述完整 然而,Gopher mascot 仍旧命相同的名字。在2018年8月,Go的主要贡献者发布了两个关于语言新功能的“草稿设计——泛型 和 异常处理,同时寻求Go用户的反馈。Go 由于在1.x时,缺少对 泛型编程 的支持和冗长的 异常处理 而备受批评。以上来自wiki,更多详情可查看为什么需要学习Golang? “Go will be the server language of the future.” — Tobias Lütke, Shopify 硬件的局限性摩尔定律正在失效。英特尔公司在 2004 年推出了第一款具有 3.0 GHz时钟速度的奔腾 4 处理器。如今,我的 2016款 MacBook Pro 的时钟速度为 2.9 GHz。因此,差不多十年,原始处理能力都没有太多的增加。你可以在下图中看到处理能力的增长与时间的关系。从上面的图表可以看出,单线程的性能和处理器的频率在近十年几乎保持稳定。如果你认为添加更多的晶体管是一种解决问题的方法,那你就错了。这是因为在微观尺度上,量子特性开始显现(例如:量子隧道穿越),放更多的晶体管代价也会越多(为什么?),而且,每美元可以添加晶体管的数量也开始下降。所以,针对上述问题的解决方案如下:厂商开始向处理器添加越来越多的内核。如今,我们已经有四核和八核的 CPU 可用。我们还引入了超线程技术。为处理器添加更多的缓存以提升性能。但是,以上方案也有它们自身的限制。我们无法向处理器添加更多的缓存以提升性能,因为缓存具有物理限制:缓存越大,速度越慢。添加更多的内核到处理器也有它的成本。而且,这也无法无限扩展。这些多核处理器能同时运行多个线程,同时也能带来并发能力。我们稍后会讨论它。因此,如果我们不能依赖于硬件的改进,唯一的出路就是找到一个高效的软件来提升性能,但遗憾的是,现代编程语言都不是那么高效。 “现代处理器就像一辆有氮氧加速系统的直线竞速赛车,它们在直线竞速赛中表现优异。不幸的是,现代编程语言却像蒙特卡罗赛道,它们有大量的弯道。” - David Ungar Go 天生支持并发如上所述,硬件提供商正在向处理器添加更多的内核以提升性能。所有的数据中心都在这些处理器上运行,我们应该期待在未来几年内核数量的增长。更重要的是,如今的应用程序都是使用多个微服务来维持数据库的连接、消息队列和缓存的维护。因此,我们开发的软件和编程语言可以更容易的支持并发,并且它们应该随着内核数量的增长而可扩展。但是大多数现代编程语言(如 Java、Python 等)都来自于 90 年代的单线程环境。这些语言大多数都支持多线程。但真正的问题是并发执行,线程锁、竞争条件和死锁。这些问题都使得很难在这些语言上创建一个多线程的应用程序。例如,在 Java 中创建新的线程会消耗大量内存。因为每一个线程都会消耗大约 1 MB 大小的堆内存,如果你运行上千个线程,他们会对堆造成巨大的压力,最终会由于内存不足而宕机。此外,你想要在两个或者多个线程之间通信也是非常困难的。另一方面,Go 于 2009 年发布,那时多核处理器已经上市了。这也是为什么 Go 是在考虑并发的基础上构建的。Go 用 goroutine 来替代线程,它们从堆中消耗了大约 2 KB 的内存。因此你可以随时启动上百万个 goroutine。Go 直接在底层硬件上运行与其他现代高级语言(如 Java/Python)相比,使用 C、C++ 的最大好处就是它的性能,因为 C/C++ 是编译型语言而不是解释型语言。处理器能理解二进制文件。通常来说,当你编译一个用 Java 或者其他基于 JVM 的语言构建的应用程序,它将人类可读的代码编译为字节代码,这可以被 JVM 或者在底层操作系统之上运行的其他虚拟机所理解。当执行的时候,虚拟机解释这些字节码并且将他们转化为处理器能理解的二进制文件。用 Go 编写的代码易于维护我告诉你一件事,Go 没有像其他语言一样疯狂于编程语法,它的语法非常整洁。Go 的的设计者在谷歌创建这门语言的时候就考虑到了这一点,由于谷歌拥有非常强大的代码库,成千上万的开发者都工作在相同的代码库上,代码应该易于其他开发者理解,一段代码应该对另一段代码有最小的影响。这些都会使得代码易于维护,易于修改。Go 有意的忽视了许多现代面向对象语言的一些特性。没有类。 所有代码都仅用 package 分开,Go 只有结构体而不是类。不支持继承。 这将使得代码易于修改。在其他语言中,如: Java/Python,如果类 ABC 继承类 XYZ 并且你在类 XYZ 中做了一些改动,那么这可能会在继承类 XYZ 的其他类中产生一些副作用。通过移除继承,Go 也使得理解代码变得很容易 (因为当你在看一段代码时不需要同时查看父类)。没有构造方法。没有注解。没有泛型。没有异常。以上这些改变使得 Go 与其他语言截然不同,这使得用 Go 编程与其他语言很不一样。你可能不喜欢以上的一些观点。但是,并不是说没有上述这些特性,你就无法对你的应用程序编码。你要做的就是多写几行代码,但从积极的一面,它将使你的代码更加清晰,为代码添加更多的清晰度。Go 来势汹汹我知道这不是一个直接的技术优势,但 Go 是由谷歌设计并支持的,谷歌拥有世界上最大的云基础设施之一,并且规模庞大。谷歌设计 Go 以解决可扩展性和有效性问题。这些是创建我们自己的服务器时都会遇到的问题。Go 更多的也是被一些大公司所使用,如 Adobe、BBC、IBM,因特尔甚至是 Medium。发布于 2020-11-18 10:12Go 语言Go 编程​赞同 13​​添加评论​分享​喜欢​收藏​申请转载​文章被以下专栏收录重学编程之Golang互联网新宠-Golang,让我们从头开始学

Go 语言之旅

Go 语言之旅

Go 指南

前言 · Go语言圣经

前言 · Go语言圣经

前言

Go语言起源

Go语言项目

本书的组织

更多的信息

致谢

入门

Hello, World

命令行参数

查找重复的行

GIF动画

获取URL

并发获取多个URL

Web服务

本章要点

程序结构

命名

声明

变量

赋值

类型

包和文件

作用域

基础数据类型

整型

浮点数

复数

布尔型

字符串

常量

复合数据类型

数组

Slice

Map

结构体

JSON

文本和HTML模板

函数

函数声明

递归

多返回值

错误

函数值

匿名函数

可变参数

Deferred函数

Panic异常

Recover捕获异常

方法

方法声明

基于指针对象的方法

通过嵌入结构体来扩展类型

方法值和方法表达式

示例: Bit数组

封装

接口

接口是合约

接口类型

实现接口的条件

flag.Value接口

接口值

sort.Interface接口

http.Handler接口

error接口

示例: 表达式求值

类型断言

基于类型断言识别错误类型

通过类型断言查询接口

类型分支

示例: 基于标记的XML解码

补充几点

Goroutines和Channels

Goroutines

示例: 并发的Clock服务

示例: 并发的Echo服务

Channels

并发的循环

示例: 并发的Web爬虫

基于select的多路复用

示例: 并发的目录遍历

并发的退出

示例: 聊天服务

基于共享变量的并发

竞争条件

sync.Mutex互斥锁

sync.RWMutex读写锁

内存同步

sync.Once惰性初始化

竞争条件检测

示例: 并发的非阻塞缓存

Goroutines和线程

包和工具

包简介

导入路径

包声明

导入声明

包的匿名导入

包和命名

工具

测试

go test

测试函数

测试覆盖率

基准测试

剖析

示例函数

反射

为何需要反射?

reflect.Type和reflect.Value

Display递归打印

示例: 编码S表达式

通过reflect.Value修改值

示例: 解码S表达式

获取结构体字段标签

显示一个类型的方法集

几点忠告

底层编程

unsafe.Sizeof, Alignof 和 Offsetof

unsafe.Pointer

示例: 深度相等判断

通过cgo调用C代码

几点忠告

附录

附录A:原文勘误

附录B:作者译者

附录C:译文授权

附录D:其它语言

本书使用 GitBook 发布

前言

Go语言圣经(中文版)

Go语言圣经 《The Go Programming Language》 中文版本,仅供学习交流之用。对于希望学习CGO、Go汇编语言等高级用法的同学,我们推荐《Go语言高级编程》开源图书。

项目主页:http://github.com/golang-china/gopl-zh

原版官网:http://gopl.io

译者信息:

译者:柴树杉,Github @chai2010,Twitter @chaishushan

译者:Xargin, https://github.com/cch123

译者:CrazySssst

译者:foreversmart njutree@gmail.com

关注微信公众号(golang-china)

在线预览

https://docs.hacknode.org/gopl-zh/

https://books.studygolang.com/gopl-zh/

https://wizardforcel.gitbooks.io/gopl-zh/

译者序

在上个世纪70年代,贝尔实验室的Ken Thompson和Dennis M. Ritchie合作发明了UNIX操作系统,同时Dennis M. Ritchie为了解决UNIX系统的移植性问题而发明了C语言,贝尔实验室的UNIX和C语言两大发明奠定了整个现代IT行业最重要的软件基础(目前的三大桌面操作系统的中Linux和Mac OS X都是源于UNIX系统,两大移动平台的操作系统iOS和Android也都是源于UNIX系统。C系家族的编程语言占据统治地位达几十年之久)。在UNIX和C语言发明40年之后,目前已经在Google工作的Ken Thompson和Rob Pike(他们在贝尔实验室时就是同事)、还有Robert Griesemer(设计了V8引擎和HotSpot虚拟机)一起合作,为了解决在21世纪多核和网络化环境下越来越复杂的编程问题而发明了Go语言。从Go语言库早期代码库日志可以看出它的演化历程(Git用git log --before={2008-03-03} --reverse命令查看):

从早期提交日志中也可以看出,Go语言是从Ken Thompson发明的B语言、Dennis M. Ritchie发明的C语言逐步演化过来的,是C语言家族的成员,因此很多人将Go语言称为21世纪的C语言。纵观这几年来的发展趋势,Go语言已经成为云计算、云存储时代最重要的基础编程语言。

在C语言发明之后约5年的时间之后(1978年),Brian W. Kernighan和Dennis M. Ritchie合作编写出版了C语言方面的经典教材《The C Programming Language》,该书被誉为C语言程序员的圣经,作者也被大家亲切地称为K&R。同样在Go语言正式发布(2009年)约5年之后(2014年开始写作,2015年出版),由Go语言核心团队成员Alan A. A. Donovan和K&R中的Brian W. Kernighan合作编写了Go语言方面的经典教材《The Go Programming Language》。Go语言被誉为21世纪的C语言,如果说K&R所著的是圣经的旧约,那么D&K所著的必将成为圣经的新约。该书介绍了Go语言几乎全部特性,并且随着语言的深入层层递进,对每个细节都解读得非常细致,每一节内容都精彩不容错过,是广大Gopher的必读书目。大部分Go语言核心团队的成员都参与了该书校对工作,因此该书的质量是可以完全放心的。

同时,单凭阅读和学习其语法结构并不能真正地掌握一门编程语言,必须进行足够多的编程实践——亲自编写一些程序并研究学习别人写的程序。要从利用Go语言良好的特性使得程序模块化,充分利用Go的标准函数库以Go语言自己的风格来编写程序。书中包含了上百个精心挑选的习题,希望大家能先用自己的方式尝试完成习题,然后再参考官方给出的解决方案。

该书英文版约从2015年10月开始公开发售,其中日文版本最早参与翻译和审校(参考致谢部分)。在2015年10月,我们并不知道中文版是否会及时引进、将由哪家出版社引进、引进将由何人来翻译、何时能出版,这些信息都成了一个秘密。中国的Go语言社区是全球最大的Go语言社区,我们从一开始就始终紧跟着Go语言的发展脚步。我们应该也完全有能力以中国Go语言社区的力量同步完成Go语言圣经中文版的翻译工作。与此同时,国内有很多Go语言爱好者也在积极关注该书(本人也在第一时间购买了纸质版本,亚马逊价格314人民币。补充:国内也即将出版英文版,价格79元)。为了Go语言的学习和交流,大家决定合作免费翻译该书。

翻译工作从2015年11月20日前后开始,到2016年1月底初步完成,前后历时约2个月时间(在其它语言版本中,全球第一个完成翻译的,基本做到和原版同步)。其中,chai2010翻译了前言、第2 ~ 4章、第10 ~ 13章,Xargin翻译了第1章、第6章、第8 ~ 9章,CrazySssst翻译了第5章,foreversmart翻译了第7章,大家共同参与了基本的校验工作,还有其他一些朋友提供了积极的反馈建议。如果大家还有任何问题或建议,可以直接到中文版项目页面提交Issue,如果发现英文版原文在勘误中未提到的任何错误,可以直接去英文版项目提交。

最后,希望这本书能够帮助大家用Go语言快乐地编程。

2016年 1月 于 武汉

前言

“Go是一个开源的编程语言,它很容易用于构建简单、可靠和高效的软件。”(摘自Go语言官方网站:http://golang.org )

Go语言由来自Google公司的Robert Griesemer,Rob Pike和Ken Thompson三位大牛于2007年9月开始设计和实现,然后于2009年的11月对外正式发布(译注:关于Go语言的创世纪过程请参考 http://talks.golang.org/2015/how-go-was-made.slide )。语言及其配套工具的设计目标是具有表达力,高效的编译和执行效率,有效地编写高效和健壮的程序。

Go语言有着和C语言类似的语法外表,和C语言一样是专业程序员的必备工具,可以用最小的代价获得最大的战果。

但是它不仅仅是一个更新的C语言。它还从其他语言借鉴了很多好的想法,同时避免引入过度的复杂性。

Go语言中和并发编程相关的特性是全新的也是有效的,同时对数据抽象和面向对象编程的支持也很灵活。

Go语言同时还集成了自动垃圾收集技术用于更好地管理内存。

Go语言尤其适合编写网络服务相关基础设施,同时也适合开发一些工具软件和系统软件。

但是Go语言确实是一个通用的编程语言,它也可以用在图形图像驱动编程、移动应用程序开发

和机器学习等诸多领域。目前Go语言已经成为受欢迎的作为无类型的脚本语言的替代者:

因为Go编写的程序通常比脚本语言运行的更快也更安全,而且很少会发生意外的类型错误。

Go语言还是一个开源的项目,可以免费获取编译器、库、配套工具的源代码。

Go语言的贡献者来自一个活跃的全球社区。Go语言可以运行在类UNIX系统——

比如Linux、FreeBSD、OpenBSD、Mac OSX——和Plan9系统和Microsoft Windows操作系统之上。

Go语言编写的程序无需修改就可以运行在上面这些环境。

本书是为了帮助你开始以有效的方式使用Go语言,充分利用语言本身的特性和自带的标准库去编写清晰地道的Go程序。

交流学习如果有疑问或想和我交流,欢迎扫码下方二维码polarisxugopherstudio

Documentation - The Go Programming Language

Documentation - The Go Programming Language

Skip to Main Content

Why Go arrow_drop_down

Press Enter to activate/deactivate dropdown

Case Studies

Common problems companies solve with Go

Use Cases

Stories about how and why companies use Go

Security

How Go can help keep you secure by default

Learn

Press Enter to activate/deactivate dropdown

Docs arrow_drop_down

Press Enter to activate/deactivate dropdown

Effective Go

Tips for writing clear, performant, and idiomatic Go code

Go User Manual

A complete introduction to building software with Go

Standard library

Reference documentation for Go's standard library

Release Notes

Learn what's new in each Go release

Packages

Press Enter to activate/deactivate dropdown

Community arrow_drop_down

Press Enter to activate/deactivate dropdown

Recorded Talks

Videos from prior events

Meetups

open_in_new

Meet other local Go developers

Conferences

open_in_new

Learn and network with Go developers from around the world

Go blog

The Go project's official blog.

Go project

Get help and stay informed from Go

Get connected

Why Go navigate_next

navigate_beforeWhy Go

Case Studies

Use Cases

Security

Learn

Docs navigate_next

navigate_beforeDocs

Effective Go

Go User Manual

Standard library

Release Notes

Packages

Community navigate_next

navigate_beforeCommunity

Recorded Talks

Meetups

open_in_new

Conferences

open_in_new

Go blog

Go project

Get connected

Documentation

The Go programming language is an open source project to make programmers more

productive.

Go is expressive, concise, clean, and efficient. Its concurrency

mechanisms make it easy to write programs that get the most out of multicore

and networked machines, while its novel type system enables flexible and

modular program construction. Go compiles quickly to machine code yet has the

convenience of garbage collection and the power of run-time reflection. It's a

fast, statically typed, compiled language that feels like a dynamically typed,

interpreted language.

Getting Started

Installing Go

Instructions for downloading and installing Go.

Tutorial: Getting started

A brief Hello, World tutorial to get started. Learn a bit about Go code, tools, packages, and modules.

Tutorial: Create a module

A tutorial of short topics introducing functions, error handling, arrays, maps, unit testing, and compiling.

Tutorial: Getting started with multi-module workspaces

Introduces the basics of creating and using multi-module workspaces in Go. Multi-module workspaces are useful for making changes across multiple modules.

Tutorial: Developing a RESTful API with Go and Gin

Introduces the basics of writing a RESTful web service API with Go and the Gin Web Framework.

Tutorial: Getting started with generics

With generics, you can declare and use functions or types that are written to work with any of a set of types provided by calling code.

Tutorial: Getting started with fuzzing

Fuzzing can generate inputs to your tests that can catch edge cases and security issues that you may have missed.

Writing Web Applications

Building a simple web application.

How to write Go code

This doc explains how to develop a simple set of Go packages inside a module,

and it shows how to use the go command

to build and test packages.

A Tour of Go

An interactive introduction to Go in four sections.

The first section covers basic syntax and data structures; the second discusses

methods and interfaces; the third is about Generics; and the fourth introduces Go's concurrency primitives.

Each section concludes with a few exercises so you can practice what you've

learned. You can take the tour online or install it locally with:

$ go install golang.org/x/website/tour@latest

This will place the tour binary in your

GOPATH's bin directory.

Using and understanding Go

Effective Go

A document that gives tips for writing clear, idiomatic Go code.

A must read for any new Go programmer. It augments the tour and

the language specification, both of which should be read first.

Frequently Asked Questions (FAQ)

Answers to common questions about Go.

Editor plugins and IDEs

A document that summarizes commonly used editor plugins and IDEs with

Go support.

Diagnostics

Summarizes tools and methodologies to diagnose problems in Go programs.

A Guide to the Go Garbage Collector

A document that describes how Go manages memory, and how to make the most of it.

Managing dependencies

When your code uses external packages, those packages (distributed as modules) become dependencies.

Fuzzing

Main documentation page for Go fuzzing.

Coverage for Go applications

Main documentation page for coverage testing of Go applications.

Profile-guided optimization

Main documentation page for profile-guided optimization (PGO) of Go applications.

References

Package Documentation

The documentation for the Go standard library.

Command Documentation

The documentation for the Go tools.

Language Specification

The official Go Language specification.

Go Modules Reference

A detailed reference manual for Go's dependency management system.

go.mod file reference

Reference for the directives included in a go.mod file.

The Go Memory Model

A document that specifies the conditions under which reads of a variable in

one goroutine can be guaranteed to observe values produced by writes to the

same variable in a different goroutine.

Contribution Guide

Contributing to Go.

Release History

A summary of the changes between Go releases.

Accessing databases

Tutorial: Accessing a relational database

Introduces the basics of accessing a relational database using Go and the

database/sql package in the standard library.

Accessing relational databases

An overview of Go's data access features.

Opening a database handle

You use the Go database handle to execute database operations. Once you open a

handle with database connection properties, the handle represents a connection

pool it manages on your behalf.

Executing SQL statements that don't return data

For SQL operations that might change the database, including SQL

INSERT, UPDATE, and DELETE, you use

Exec methods.

Querying for data

For SELECT statements that return data from a query, using the

Query or QueryRow method.

Using prepared statements

Defining a prepared statement for repeated use can help your code run a bit

faster by avoiding the overhead of re-creating the statement each time your

code performs the database operation.

Executing transactions

sql.Tx exports methods representing transaction-specific semantics,

including Commit and Rollback, as well as methods you

use to perform common database operations.

Canceling in-progress database operations

Using context.Context, you can

have your application's function calls and services stop working early and

return an error when their processing is no longer needed.

Managing connections

For some advanced programs, you might need to tune connection pool parameters

or work with connections explicitly.

Avoiding SQL injection risk

You can avoid an SQL injection risk by providing SQL parameter values as

sql package function arguments

Developing modules

Developing and publishing modules

You can collect related packages into modules, then publish the modules for other developers to use. This topic gives an overview of developing and publishing modules.

Module release and versioning workflow

When you develop modules for use by other developers, you can follow a workflow that helps ensure a reliable, consistent experience for developers using the module. This topic describes the high-level steps in that workflow.

Managing module source

When you're developing modules to publish for others to use, you can help ensure that your modules are easier for other developers to use by following the repository conventions described in this topic.

Organizing a Go module

What is the right way to organize the files and directories in a typical Go project? This topic discusses some common layouts depending on the kind of module you have.

Developing a major version update

A major version update can be very disruptive to your module's users because it includes breaking changes and represents a new module. Learn more in this topic.

Publishing a module

When you want to make a module available for other developers, you publish it so that it's visible to Go tools. Once you've published the module, developers importing its packages will be able to resolve a dependency on the module by running commands such as go get.

Module version numbering

A module's developer uses each part of a module's version number to signal the version’s stability and backward compatibility. For each new release, a module's release version number specifically reflects the nature of the module's changes since the preceding release.

Talks

A Video Tour of Go

Three things that make Go fast, fun, and productive:

interfaces, reflection, and concurrency. Builds a toy web crawler to

demonstrate these.

Code that grows with grace

One of Go's key design goals is code adaptability; that it should be easy to take a simple design and build upon it in a clean and natural way. In this talk Andrew Gerrand describes a simple "chat roulette" server that matches pairs of incoming TCP connections, and then use Go's concurrency mechanisms, interfaces, and standard library to extend it with a web interface and other features. While the function of the program changes dramatically, Go's flexibility preserves the original design as it grows.

Go Concurrency Patterns

Concurrency is the key to designing high performance network services. Go's concurrency primitives (goroutines and channels) provide a simple and efficient means of expressing concurrent execution. In this talk we see how tricky concurrency problems can be solved gracefully with simple Go code.

Advanced Go Concurrency Patterns

This talk expands on the Go Concurrency Patterns talk to dive deeper into Go's concurrency primitives.

More

See the Go Talks site and wiki page for more Go talks.

Codewalks

Guided tours of Go programs.

First-Class Functions in Go

Generating arbitrary text: a Markov chain algorithm

Share Memory by Communicating

Language

JSON-RPC: a tale of interfaces

Go's Declaration Syntax

Defer, Panic, and Recover

Go Concurrency Patterns: Timing out, moving on

Go Slices: usage and internals

A GIF decoder: an exercise in Go interfaces

Error Handling and Go

Packages

JSON and Go - using the json package.

Gobs of data - the design and use of the gob package.

The Laws of Reflection - the fundamentals of the reflect package.

The Go image package - the fundamentals of the image package.

The Go image/draw package - the fundamentals of the image/draw package.

Modules

Using Go Modules - an introduction to using modules in a simple project.

Migrating to Go Modules - converting an existing project to use modules.

Publishing Go Modules - how to make new versions of modules available to others.

Go Modules: v2 and Beyond - creating and publishing major versions 2 and higher.

Keeping Your Modules Compatible - how to keep your modules compatible with prior minor/patch versions.

Tools

About the Go command - why we wrote it, what it is, what it's not, and how to use it.

Go Doc Comments - writing good program documentation

Debugging Go Code with GDB

Data Race Detector - a manual for the data race detector.

A Quick Guide to Go's Assembler - an introduction to the assembler used by Go.

C? Go? Cgo! - linking against C code with cgo.

Profiling Go Programs

Introducing the Go Race Detector - an introduction to the race detector.

Wiki

The Go Wiki, maintained by the Go community, includes articles about the Go language, tools, and other resources.

See the Learn page at the Wiki

for more Go learning resources.

Non-English Documentation

See the NonEnglish page

at the Wiki for localized

documentation.

Opens in new window.

Why Go

Use Cases

Case Studies

Get Started

Playground

Tour

Stack Overflow

Help

Packages

Standard Library

About Go Packages

About

Download

Blog

Issue Tracker

Release Notes

Brand Guidelines

Code of Conduct

Connect

Twitter

GitHub

Slack

r/golang

Meetup

Golang Weekly

Opens in new window.

Copyright

Terms of Service

Privacy Policy

Report an Issue

go.dev uses cookies from Google to deliver and enhance the quality of its services and to

analyze traffic. Learn more.

Okay

GitHub - Go-zh/tour: Go 语言官方教程中文版

GitHub - Go-zh/tour: Go 语言官方教程中文版

Skip to content

Toggle navigation

Sign in

Product

Actions

Automate any workflow

Packages

Host and manage packages

Security

Find and fix vulnerabilities

Codespaces

Instant dev environments

Copilot

Write better code with AI

Code review

Manage code changes

Issues

Plan and track work

Discussions

Collaborate outside of code

Explore

All features

Documentation

GitHub Skills

Blog

Solutions

For

Enterprise

Teams

Startups

Education

By Solution

CI/CD & Automation

DevOps

DevSecOps

Resources

Learning Pathways

White papers, Ebooks, Webinars

Customer Stories

Partners

Open Source

GitHub Sponsors

Fund open source developers

The ReadME Project

GitHub community articles

Repositories

Topics

Trending

Collections

Pricing

Search or jump to...

Search code, repositories, users, issues, pull requests...

Search

Clear

Search syntax tips

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Cancel

Submit feedback

Saved searches

Use saved searches to filter your results more quickly

Name

Query

To see all available qualifiers, see our documentation.

Cancel

Create saved search

Sign in

Sign up

You signed in with another tab or window. Reload to refresh your session.

You signed out in another tab or window. Reload to refresh your session.

You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

Go-zh

/

tour

Public

Notifications

Fork

221

Star

1.5k

Go 语言官方教程中文版

tour.go-zh.org

License

BSD-3-Clause license

1.5k

stars

221

forks

Branches

Tags

Activity

Star

Notifications

Code

Issues

51

Pull requests

4

Actions

Projects

0

Security

Insights

Additional navigation options

Code

Issues

Pull requests

Actions

Projects

Security

Insights

Go-zh/tour

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

 masterBranchesTagsGo to fileCodeFolders and filesNameNameLast commit messageLast commit dateLatest commit History581 Commitscontentcontent  gotourgotour  readerreader  solutionssolutions  staticstatic  templatetemplate  toolstools  vendor/golang.org/x/tourvendor/golang.org/x/tour  .gcloudignore.gcloudignore  AUTHORSAUTHORS  CONTRIBUTING.mdCONTRIBUTING.md  CONTRIBUTORSCONTRIBUTORS  LICENSELICENSE  README.mdREADME.md  TODOTODO  TRANSLATETRANSLATE  app.yamlapp.yaml  appengine.goappengine.go  codereview.cfgcodereview.cfg  fmt.gofmt.go  go.modgo.mod  go.sumgo.sum  local.golocal.go  tour.gotour.go  View all filesRepository files navigationREADMEBSD-3-Clause licenseGo 语言之旅

《Go 语言之旅》是官方 Go Tour 的中文翻译版。

请访问 https://tour.go-zh.org/ 开始学习。

下载/安装

要从源码安装本教程,首先请设置一个工作空间并执行

$ go get -u github.com/Go-zh/tour

这会在你工作空间的 bin 目录中创建一个可离线执行的 tour 文件。

(如果安装过程中出现 package 或 import 字样的错误提示,那么说明依赖库的导入路径又挂了。这时请猛戳 @OlingCat 并督促其解决= =||)

贡献方式

贡献方式应遵循与 Go 项目相同的流程:http://go-zh.org/doc/contribute.html

要在本地测试 tour 服务,请参考 Go App Engine 官方文档。

问题报告/发送补丁

本教程中文版直接托管在 Github 上,提交更改请直接发送 PR。

问题报告请在 github.com/Go-zh/tour/issues 上发起。

授权许可

除特别声明外,go-tour 源码文件均采用 BSD 风格的授权许可分发,许可内容见 LICENSE 文件。

About

Go 语言官方教程中文版

tour.go-zh.org

Resources

Readme

License

BSD-3-Clause license

Activity

Custom properties

Stars

1.5k

stars

Watchers

51

watching

Forks

221

forks

Report repository

Releases

1

tags

Packages

0

No packages published

Contributors

65

+ 51 contributors

Languages

Go

56.3%

JavaScript

27.4%

CSS

9.7%

HTML

5.5%

Shell

1.1%

Footer

© 2024 GitHub, Inc.

Footer navigation

Terms

Privacy

Security

Status

Docs

Contact

Manage cookies

Do not share my personal information

You can’t perform that action at this time.

Get Started - The Go Programming Language

Get Started - The Go Programming Language

Skip to Main Content

Why Go arrow_drop_down

Press Enter to activate/deactivate dropdown

Case Studies

Common problems companies solve with Go

Use Cases

Stories about how and why companies use Go

Security

How Go can help keep you secure by default

Learn

Press Enter to activate/deactivate dropdown

Docs arrow_drop_down

Press Enter to activate/deactivate dropdown

Effective Go

Tips for writing clear, performant, and idiomatic Go code

Go User Manual

A complete introduction to building software with Go

Standard library

Reference documentation for Go's standard library

Release Notes

Learn what's new in each Go release

Packages

Press Enter to activate/deactivate dropdown

Community arrow_drop_down

Press Enter to activate/deactivate dropdown

Recorded Talks

Videos from prior events

Meetups

open_in_new

Meet other local Go developers

Conferences

open_in_new

Learn and network with Go developers from around the world

Go blog

The Go project's official blog.

Go project

Get help and stay informed from Go

Get connected

Why Go navigate_next

navigate_beforeWhy Go

Case Studies

Use Cases

Security

Learn

Docs navigate_next

navigate_beforeDocs

Effective Go

Go User Manual

Standard library

Release Notes

Packages

Community navigate_next

navigate_beforeCommunity

Recorded Talks

Meetups

open_in_new

Conferences

open_in_new

Go blog

Go project

Get connected

Learn

Install the latest version of Go

Install the latest version of Go. For instructions to download and install

the Go compilers, tools, and libraries,

view the install documentation.

Download

Selected tutorials

Guided journeys

Qwiklabs

Tutorials

Training

Books

Selected tutorials

New to Go and don't know where to start?

Documentation

Everything there is to know about Go. Get started on a new project or brush up for your existing Go code.

View documentation

Tour of Go

An interactive introduction to Go in four sections. Each section concludes with a few exercises so you can practice what you've learned.

Take a tour

Go by example

Go by Example is a hands-on introduction to Go using annotated example programs. It’s a great starting point to use when tackling any Go project.

View examples

Guided learning journeys

Got the basics and want to learn more?

Web Dev

Go Web Examples provides easy to understand code snippets on how to use Go for web development.

Learn more

CLIs

This workshop will walk you through building a CLI app with Go, introducing you to basic Go principles and CLI frameworks along the way.

Learn more

New to coding?

Get started with this introductory course covering basic programming principles and Go fundamentals.

Learn more

Qwiklabs

Guided tours of Go programs

Deploy Go Apps on Google Cloud Serverless Platforms

1h 10m •

5 Credits

Use Go Code to Work with Google Cloud Data Sources

1h 10m •

5 Credits

Getting Started with Go on App Engine

20m •

1 Credits

Tutorials

Getting started

In this tutorial, you'll get a brief introduction to Go programming. Along the way, you will install Go, write some simple "Hello, world" code, use the go command to run your code, use the Go package discovery tool, and call functions of an external module.

Tutorial

Create a module

This is the first part of a tutorial that introduces a few fundamental features of the Go language. In this tutorial you'll create two modules. The first is a library which is intended to be imported by other libraries or applications. The second is a caller application which will use the first.

Tutorial

Developing a web service

This tutorial introduces the basics of writing a RESTful web service API with Go and the Gin Web Framework. In this tutorial, you will build a RESTful API server with two endpoints.

Interactive Tutorial

Training

Guided tours of Go programs

Ardan Labs

Offering customized on-site live training classes.

Gopher Guides

Customized In-person, remote, and online training classes. Training for Developers by Developers.

Boss Sauce Creative

Personalized or track-based Go training for teams.

Shiju Varghese

On-site classroom training on Go and consulting on distributed systems architectures, in India.

Books

PDF

The Go Programming Language

Alan A. A. Donovan, Brian W. Kernighan

view book

Manning.com

Get Programming with Go

Nathan Youngman, Roger Peppé

view book

GitHub

Go Programming Blueprints

This is the official source code repository for the book.

view book

O'Reilly.com

Introducing Go

Caleb Doxsey

view book

O'Reilly.com

Concurrency in Go

Katherine Cox-Buday

view book

Why Go

Use Cases

Case Studies

Get Started

Playground

Tour

Stack Overflow

Help

Packages

Standard Library

About Go Packages

About

Download

Blog

Issue Tracker

Release Notes

Brand Guidelines

Code of Conduct

Connect

Twitter

GitHub

Slack

r/golang

Meetup

Golang Weekly

Opens in new window.

Copyright

Terms of Service

Privacy Policy

Report an Issue

go.dev uses cookies from Google to deliver and enhance the quality of its services and to

analyze traffic. Learn more.

Okay