-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.json
1 lines (1 loc) · 40.5 KB
/
content.json
1
{"pages":[{"title":"About","date":"2016-10-24T02:24:00.000Z","path":"about/index.html","text":"关于我自己Nothing!!!"},{"title":"Categories","date":"2020-03-24T15:22:41.437Z","path":"categories/index.html","text":""},{"title":"Tags","date":"2020-03-24T15:22:41.444Z","path":"tags/index.html","text":""}],"posts":[{"title":"1.2 语言的主要特性与发展的环境和影响因素","date":"2020-03-24T14:30:00.000Z","path":"wiki/Go入门指南/第一章 Go语言的起源,发展与普及/1.2 语言的主要特性与发展的环境和影响因素/","text":"1.2 语言的主要特性与发展的环境和影响因素1.2.1 影响 Go 语言发展的早期编程语言正如 “21 世纪的 C 语言” 这句话所说,Go 语言并不是凭空而造的,而是和 C++、Java 和 C# 一样属于 C 系。不仅如此,设计者们还汲取了其它编程语言的精粹部分融入到 Go 语言当中。 在声明和包的设计方面,Go 语言受到 Pascal、Modula 和 Oberon 系语言的影响;在并发原理的设计上,Go 语言从同样受到 Tony Hoare 的 CSP(通信序列进程 Communicating Sequential Processes)理论影响的 Limbo 和 Newsqueak 的实践中借鉴了一些经验,并使用了和 Erlang 类似的机制。 这是一门完全开源的编程语言,因为它使用 BSD 授权许可,所以任何人都可以进行商业软件的开发而不需要支付任何费用。 尽管为了能够让目前主流的开发者们能够对 Go 语言中的类 C 语言的语法感到非常亲切而易于转型,但是它在极大程度上简化了这些语法,使得它们比 C/C++ 的语法更加简洁和干净。同时,Go 语言也拥有一些动态语言的特性,这使得使用 Python 和 Ruby 的开发者们在使用 Go 语言的时候感觉非常容易上手。 下图展示了一些其它编程语言对 Go 语言的影响: 1.2.2 为什么要创造一门编程语言 C/C++ 的发展速度无法跟上计算机发展的脚步,十多年来也没有出现一门与时代相符的主流系统编程语言,因此人们需要一门新的系统编程语言来弥补这个空缺,尤其是在计算机信息时代。 相比计算机性能的提升,软件开发领域不被认为发展得足够快或者比硬件发展得更加成功(有许多项目均以失败告终),同时应用程序的体积始终在不断地扩大,这就迫切地需要一门具备更高层次概念的低级语言来突破现状。 在 Go 语言出现之前,开发者们总是面临非常艰难的抉择,究竟是使用执行速度快但是编译速度并不理想的语言(如:C++),还是使用编译速度较快但执行效率不佳的语言(如:.NET、Java),或者说开发难度较低但执行速度一般的动态语言呢?显然,Go 语言在这 3 个条件之间做到了最佳的平衡:快速编译,高效执行,易于开发。 1.2.3 Go 语言的发展目标Go 语言的主要目标是将静态语言的安全性和高效性与动态语言的易开发性进行有机结合,达到完美平衡,从而使编程变得更加有乐趣,而不是在艰难抉择中痛苦前行。 因此,Go 语言是一门类型安全和内存安全的编程语言。虽然 Go 语言中仍有指针的存在,但并不允许进行指针运算。 Go 语言的另一个目标是对于网络通信、并发和并行编程的极佳支持,从而更好地利用大量的分布式和多核的计算机,这一点对于谷歌内部的使用来说就非常重要了。设计者通过 goroutine 这种轻量级线程的概念来实现这个目标,然后通过 channel 来实现各个 goroutine 之间的通信。他们实现了分段栈增长和 goroutine 在线程基础上多路复用技术的自动化。 这个特性显然是 Go 语言最强有力的部分,不仅支持了日益重要的多核与多处理器计算机,也弥补了现存编程语言在这方面所存在的不足。 Go 语言中另一个非常重要的特性就是它的构建速度(编译和链接到机器代码的速度),一般情况下构建一个程序的时间只需要数百毫秒到几秒。作为大量使用 C++ 来构建基础设施的谷歌来说,无疑从根本上摆脱了 C++ 在构建速度上非常不理想的噩梦。这不仅极大地提升了开发者的生产力,同时也使得软件开发过程中的代码测试环节更加紧凑,而不必浪费大量的时间在等待程序的构建上。 依赖管理是现今软件开发的一个重要组成部分,但是 C 语言中“头文件”的概念却导致越来越多因为依赖关系而使得构建一个大型的项目需要长达几个小时的时间。人们越来越需要一门具有严格的、简洁的依赖关系分析系统从而能够快速编译的编程语言。这正是 Go 语言采用包模型的根本原因,这个模型通过严格的依赖关系检查机制来加快程序构建的速度,提供了非常好的可量测性。 整个 Go 语言标准库的编译时间一般都在 20 秒以内,其它的常规项目也只需要半秒钟的时间来完成编译工作。这种闪电般的编译速度甚至比编译 C 语言或者 Fortran 更加快,使得编译这一环节不再成为在软件开发中困扰开发人员的问题。在这之前,动态语言将快速编译作为自身的一大亮点,像 C++ 那样的静态语言一般都有非常漫长的编译和链接工作。而同样作为静态语言的 Go 语言,通过自身优良的构建机制,成功地去除了这个弊端,使得程序的构建过程变得微不足道,拥有了像脚本语言和动态语言那样的高效开发的能力。 另外,Go 语言在执行速度方面也可以与 C/C++ 相提并论。 由于内存问题(通常称为内存泄漏)长期以来一直伴随着 C++ 的开发者们,Go 语言的设计者们认为内存管理不应该是开发人员所需要考虑的问题。因此尽管 Go 语言像其它静态语言一样执行本地代码,但它依旧运行在某种意义上的虚拟机,以此来实现高效快速的垃圾回收(使用了一个简单的标记-清除算法)。 尽管垃圾回收并不容易实现,但考虑这将是未来并发应用程序发展的一个重要组成部分,Go 语言的设计者们还是完成了这项艰难的任务。 Go 语言还能够在运行时进行反射相关的操作。 使用 go install 能够很轻松地对第三方包进行部署。 此外,Go 语言还支持调用由 C 语言编写的海量库文件(第 3.9 节),从而能够将过去开发的软件进行快速迁移。 1.2.4 指导设计原则Go语言通过减少关键字的数量(25 个)来简化编码过程中的混乱和复杂度。干净、整齐和简洁的语法也能够提高程序的编译速度,因为这些关键字在编译过程中少到甚至不需要符号表来协助解析。 这些方面的工作都是为了减少编码的工作量,甚至可以与 Java 的简化程度相比较。 Go 语言有一种极简抽象艺术家的感觉,因为它只提供了一到两种方法来解决某个问题,这使得开发者们的代码都非常容易阅读和理解。众所周知,代码的可读性是软件工程里最重要的一部分( 译者注:代码是写给人看的,不是写给机器看的 )。 这些设计理念没有建立其它概念之上,所以并不会因为牵扯到一些概念而将某个概念复杂化,他们之间是相互独立的。 Go 语言有一套完整的编码规范,你可以在 Go 语言编码规范 页面进行查看。 它不像 Ruby 那样通过实现过程来定义编码规范。作为一门具有明确编码规范的语言,它要求可以采用不同的编译器如 gc 和 gccgo(第 2.1 节)进行编译工作,这对语言本身拥有更好的编码规范起到很大帮助。 LALR 是 Go 语言的语法标准,你也可以在 src/cmd/internal/gc/go.y 中查看到,这种语法标准在编译时不需要符号表来协助解析。 1.2.5 语言的特性Go 语言从本质上(程序和结构方面)来实现并发编程。 因为 Go 语言没有类和继承的概念,所以它和 Java 或 C++ 看起来并不相同。但是它通过接口(interface)的概念来实现多态性。Go 语言有一个清晰易懂的轻量级类型系统,在类型之间也没有层级之说。因此可以说这是一门混合型的语言。 在传统的面向对象语言中,使用面向对象编程技术显得非常臃肿,它们总是通过复杂的模式来构建庞大的类型层级,这违背了编程语言应该提升生产力的宗旨。 函数是 Go 语言中的基本构件,它们的使用方法非常灵活。在第六章,我们会看到 Go 语言在函数式编程方面的基本概念。 Go 语言使用静态类型,所以它是类型安全的一门语言,加上通过构建到本地代码,程序的执行速度也非常快。 作为强类型语言,隐式的类型转换是不被允许的,记住一条原则:让所有的东西都是显式的。 Go 语言其实也有一些动态语言的特性(通过关键字 var),所以它对那些逃离 Java 和 .Net 世界而使用 Python、Ruby、PHP 和 JavaScript 的开发者们也具有很大的吸引力。 Go 语言支持交叉编译,比如说你可以在运行 Linux 系统的计算机上开发运行 Windows 下运行的应用程序。这是第一门完全支持 UTF-8 的编程语言,这不仅体现在它可以处理使用 UTF-8 编码的字符串,就连它的源码文件格式都是使用的 UTF-8 编码。Go 语言做到了真正的国际化! 1.2.6 语言的用途Go 语言被设计成一门应用于搭载 Web 服务器,存储集群或类似用途的巨型中央服务器的系统编程语言。对于高性能分布式系统领域而言,Go 语言无疑比大多数其它语言有着更高的开发效率。它提供了海量并行的支持,这对于游戏服务端的开发而言是再好不过了。 Go 语言一个非常好的目标就是实现所谓的复杂事件处理(CEP),这项技术要求海量并行支持,高度的抽象化和高性能。当我们进入到物联网时代,CEP 必然会成为人们关注的焦点。 但是 Go 语言同时也是一门可以用于实现一般目标的语言,例如对于文本的处理,前端展现,甚至像使用脚本一样使用它。 值得注意的是,因为垃圾回收和自动内存分配的原因,Go 语言不适合用来开发对实时性要求很高的软件。 越来越多的谷歌内部的大型分布式应用程序都开始使用 Go 语言来开发,例如谷歌地球的一部分代码就是由 Go 语言完成的。 如果你想知道一些其它组织使用Go语言开发的实际应用项目,你可以到 使用 Go 的组织 页面进行查看。出于隐私保护的考虑,许多公司的项目都没有展示在这个页面。我们将会在第 21 章讨论到一个使用 Go 语言开发的大型存储区域网络(SAN)案例。 在 Chrome 浏览器中内置了一款 Go 语言的编译器用于本地客户端(NaCl),这很可能会被用于在 Chrome OS 中执行 Go 语言开发的应用程序。 Go 语言可以在 Intel 或 ARM 处理器上运行,因此它也可以在安卓系统下运行,例如 Nexus 系列的产品。 在 Google App Engine 中使用 Go 语言:2011 年 5 月 5 日,官方发布了用于开发运行在 Google App Engine 上的 Web 应用的 Go SDK,在此之前,开发者们只能选择使用 Python 或者 Java。这主要是 David Symonds 和 Nigel Tao 努力的成果。目前最新的稳定版是基于 Go 1.4 的 SDK 1.9.18,于 2015 年 2 月 18 日发布。当前 Go 语言的稳定版本是 Go 1.4.2。 1.2.7 关于特性缺失许多能够在大多数面向对象语言中使用的特性 Go 语言都没有支持,但其中的一部分可能会在未来被支持。 为了简化设计,不支持函数重载和操作符重载 为了避免在 C/C++ 开发中的一些 Bug 和混乱,不支持隐式转换 Go 语言通过另一种途径实现面向对象设计(第 10-11 章)来放弃类和类型的继承 尽管在接口的使用方面(第 11 章)可以实现类似变体类型的功能,但本身不支持变体类型 不支持动态加载代码 不支持动态链接库 不支持泛型 通过 recover 和 panic 来替代异常机制(第 13.2-3 节) 不支持静态变量 关于 Go 语言开发团队对于这些方面的讨论,你可以通过 Go 常见问题 页面查看。 1.2.8 使用 Go 语言编程如果你有其它语言的编程经历(面向对象编程语言,如:Java、C#、Object-C、Python、Ruby),在你进入到 Go 语言的世界之后,你将会像迷恋你的 X 语言一样无法自拔。Go 语言使用了与其它语言不同的设计模式,所以当你尝试将你的X语言的代码迁移到 Go 语言时,你将会非常失望,所以你需要从头开始,用 Go 的理念来思考。 如果你在至高点使用 Go 的理念来重新审视和分析一个问题,你通常会找到一个适用于 Go 语言的优雅的解决方案。 1.2.9 小结这里列举一些 Go 语言的必杀技: 简化问题,易于学习 内存管理,简洁语法,易于使用 快速编译,高效开发 高效执行 并发支持,轻松驾驭 静态类型 标准类库,规范统一 易于部署 文档全面 免费开源 链接 目录 上一节:起源与发展 下一章:安装与运行环境","tags":[],"categories":[{"name":"Go入门指南","slug":"Go入门指南","permalink":"https://wiki.zunpeng.xyz/categories/Go入门指南/"},{"name":"第一章 Go语言的起源,发展与普及","slug":"Go入门指南/第一章-Go语言的起源,发展与普及","permalink":"https://wiki.zunpeng.xyz/categories/Go入门指南/第一章-Go语言的起源,发展与普及/"}]},{"title":"webhook","date":"2020-03-23T01:42:00.000Z","path":"wiki/个人Wiki搭建/webhook/","text":"git clone https://github.com/dounine/github-webhook.git 修改hook.js 123456789101112131415161718192021222324252627282930313233343536373839404142434445var http = require('http')var createHandler = require('github-webhook-handler')var secretPassword = 'abc123' //github secret安全密码// webhook为gitbucket中url后的路径var handler = createHandler({path: '/webhook', secret: secretPassword})var cmd = require('node-cmd')// webhook服务端口var port = 8083var bash = '/opt/app/wiki/gitbucket-pull.sh' //执行的脚本 http.createServer(function (req, res) { handler(req, res, function (err) { res.writeHead(200, {'content-type': 'application/json'}) var msg = '{\"code\":404,\"msg\":\"没有这个地扯\"}' res.end(msg) console.log(msg) }) }).listen(port, function () { console.log(\"Github Hook Server running at http://0.0.0.0:\" + port + \"/webhook\");}); handler.on('error', function (err) { console.error('错误:', err.message)}) handler.on('push', function (event) { console.log('Received a push event for %s to %s', event.payload.repository.name, event.payload.ref) cmd.get(bash, function (err, data, stderr) { console.log(data) if (stderr) { console.log(\"脚本错误:\" + stderr) } }) }) handler.on('issues', function (event) { console.log('Received an issue event for %s action=%s: #%d %s', event.payload.repository.name, event.payload.action, event.payload.issue.number, event.payload.issue.title)}) 注意:需要根据git操作,预先对git工作目录进行手动pull一次,设置相关远程路径之类 gitbucket-pull.sh 1234#!/bin/bash#echo `date` >> test.logcd /opt/app/wikigit pull wiki master webhook启动cd $WEBHOOK_HOME && ./start.sh 参考 git-Webhook让部署自动化","tags":[],"categories":[{"name":"个人Wiki搭建","slug":"个人Wiki搭建","permalink":"https://wiki.zunpeng.xyz/categories/个人Wiki搭建/"}]},{"title":"Git基本操作","date":"2020-03-22T07:57:09.000Z","path":"wiki/Git/Git基本操作/","text":"初始化版本库git init 添加文件到版本库(只是添加到缓存区),.代表添加文件夹下所有文件git add . 把添加的文件提交到版本库,并填写提交备注git commit -m "first commit" 到目前为止,我们完成了代码库的初始化,但代码是在本地,还没有提交到远程服务器,所以关键的来了,要提交到就远程代码服务器,进行以下两步: 把本地库与远程库关联git remote add origin 你的远程库地址 例如:git remote add wiki http://192.168.0.107:8809/git/zunpeng/wiki-site.git 此处的wiki与origin是一个意思,只是命名不一样而已 git remote 可以查看当前目录已关联的git仓库 第一次推送时git push -u origin master 第一次推送后,直接使用该命令即可推送修改git push origin master 强制推送,有时可能上面两个推送命令不好用,可能会需要用到(慎用)git push -f origin master 参考资料 ://blog.csdn.net/JackLiu16/article/details/79751900","tags":[{"name":"Git","slug":"Git","permalink":"https://wiki.zunpeng.xyz/tags/Git/"}],"categories":[{"name":"Git","slug":"Git","permalink":"https://wiki.zunpeng.xyz/categories/Git/"}]},{"title":"Hexo操作命令","date":"2020-03-22T05:05:19.000Z","path":"wiki/Hexo/Hexo操作命令/","text":"init$ hexo init [folder]新建一个网站。如果没有设置 folder ,Hexo 默认在目前的文件夹建立网站。 new$ hexo new [layout] <title>新建一篇文章。如果没有设置 layout 的话,默认使用_config.yml 中的 default_layout 参数代替。如果标题包含空格的话,请使用引号括起来。 $ hexo new "post title with whitespace" 参数 描述 -p, --path 自定义新文章的路径 -r, --replace 如果存在同名文章,将其替换 -s, --slug 文章的 Slug,作为新文章的文件名和发布后的 URL 默认情况下,Hexo 会使用文章的标题来决定文章文件的路径。对于独立页面来说,Hexo 会创建一个以标题为名字的目录,并在目录中放置一个 index.md 文件。你可以使用 –path 参数来覆盖上述行为、自行决定文件的目录: 参考资料 Hexo文档","tags":[],"categories":[{"name":"Hexo","slug":"Hexo","permalink":"https://wiki.zunpeng.xyz/categories/Hexo/"}]},{"title":"前言","date":"2020-03-21T14:32:00.000Z","path":"wiki/Go入门指南/前言/","text":"前言用更少的代码,更短的编译时间,创建运行更快的程序,享受更多的乐趣对于学习 Go 编程语言的爱好者来说,这本书无疑是最适合你的一本书籍,这里包含了当前最全面的学习资源。本书通过对官方的在线文档、名人博客、书籍、相关文章以及演讲的资料收集和整理,并结合我自身在软件工程、编程语言和数据库开发的授课经验,将这些零碎的知识点组织成系统化的概念和技术分类来进行讲解。 随着软件规模的不断扩大,诸多的学者和谷歌的开发者们在公司内部的软件开发过程中开始经历大量的挫折,在诸多问题上都不能给出令人满意的解决方案,尤其是在使用 C++ 来开发大型的服务端软件时,情况更是不容乐观。由于二进制文件一般都是非常巨大的,因此需要耗费大量的时间在编译这些文件上,同时编程语言的设计思想也已经非常陈旧,这些情况都充分证明了现有的编程语言已不符合时下的生产环境。尽管硬件在过去的几十年中有了飞速的发展,但人们依旧没有找到机会去改变 C++ 在软件开发的重要地位,并在实际开发过程中忍受着它所带来的令人头疼的一些问题。因此学者们坐下来总结出了现在生产环境与软件开发之间的主要矛盾,v。 以下就是他们讨论得出的对编程语言的设计要求: 能够以更快的速度开发软件 开发出的软件能够很好地在现代的多核计算机上工作 开发出的软件能够很好地在网络环境下工作 使人们能够享受软件开发的过程 Go 语言就在这样的环境下诞生了,它让人感觉像是 Python 或 Ruby 这样的动态语言,但却又拥有像 C 或者 Java 这类语言的高性能和安全性。 Go 语言出现的目的是希望在编程领域创造最实用的方式来进行软件开发。它并不是要用奇怪的语法和晦涩难懂的概念来从根本上推翻已有的编程语言,而是建立并改善了 C、Java、C# 中的许多语法风格。它提倡通过接口来针对面向对象编程,通过 goroutine 和 channel 来支持并发和并行编程。 这本书是为那些想要学习 Go 这门全新的,迷人的和充满希望的编程语言的开发者量身定做的。当然,你在学习 Go 语言之前需要具备一些关于编程的基础知识和经验,并且拥有合适的学习环境,但你并不需要对 C 或者 Java 或其它类似的语言有非常深入的了解。 对于那些熟悉 C 或者面向对象编程语言的开发者,我们将会在本书中用 Go 和一些编程语言的相关概念进行比较(书中会使用大家所熟知的缩写 “OO” 来表示面向对象)。 本书将会从最基础的概念讲起,同时也会讨论一些类似在应用 goroutine 和 channel 时有多少种不同的模式,如何在 Go 语言中使用谷歌 API,如何操作内存,如何在 Go 语言中进行程序测试和如何使用模板来开发 Web 应用这些高级概念和技巧。 在本书的第一部分,我们将会讨论 Go 语言的起源(第 1 章),以及如何安装 Go 语言(第 2 章)和开发环境(第 3 章)。 在本书的第二部分,我们将会带领你贯穿 Go 语言的核心思想,譬如简单与复杂类型(第 4、7、8 章),控制结构(第 5 章),函数(第 6 章),结构与方法(第 10 章)和接口(第 11 章)。我们会对 Go 语言的函数式和面向对象编程进行透彻的讲解,包括如何使用 Go 语言来构造大型项目(第 9 章)。 在本书的第三部分,你将会学习到如何处理不同格式的文件(第 12 章)和如何在 Go 语言中巧妙地使用错误处理机制(第 13 章)。然后我们会对 Go 语言中最值得称赞的设计 goroutine 和 channel 进行并发和多核应用的基本技巧的讲解(第 14 章)。最后,我们会讨论如何将 Go 语言应用到分布式和 Web 应用中的相关网络技巧(第 15 章)。 我们会在本书的第四部分向你展示许多 Go 语言的开发模式和一些编码规范,以及一些非常有用的代码片段(第 18 章)。在前面章节完成对所有的 Go 语言技巧的学习之后,你将会学习如何构造一个完整 Go 语言项目(第 19 章),然后我们会介绍一些关于 Go 语言在云(Google App Engine)方面的应用(第 20 章)。在本书的最后一章(第 21 章),我们会讨论一些在全世界范围内已经将 Go 语言投入实际开发的公司和组织。本书将会在最后给出一些对 Go 语言爱好者的引用,Go 相关包和工具的参考,以及章节练习的答案和所有参考资源和文献的清单。 Go 语言有一个被称之为 “没有废物” 的宗旨,就是将一切没有必要的东西都去掉,不能去掉的就无底线地简化,同时追求最大程度的自动化。他完美地诠释了敏捷编程的 KISS 秘诀:短小精悍! Go 语言通过改善或去除在 C、C++ 或 Java 中的一些所谓“开放”特性来让开发者们的工作更加便利。这里只举例其中的几个,比如对于变量的默认初始化,内存分配与自动回收,以及更简洁却不失健壮的控制结构。同时我们也会发现 Go 语言旨在减少不必要的编码工作,这使得 Go 语言的代码更加简洁,从而比传统的面向对象语言更容易阅读和理解。 与 C++ 或 Java 这些有着庞大体系的语言相比,Go 语言简洁到可以将它整个的装入你的大脑中,而且比学习 Scala(Java 的并发语言)有更低的门槛,真可谓是 21 世纪的 C 语言! 作为一门系统编程语言,你不应该为 Go 语言的大多数代码示例和练习都和控制台有着密不可分的关系而感到惊奇,因为提供平台依赖性的 GUI(用户界面)框架并不是一个简单的任务。有许多由第三方发起的 GUI 框架项目正在如火如荼地进行中,或许我们会在不久的将来看到一些可用的 Go 语言 GUI 框架。不过现阶段的 Go 语言已经提供了大量有关 Web 方面的功能,我们可以通过它强大的 http 和 template 包来达到 Web 应用的 GUI 实现。 我们会经常涉及到一些关于 Go 语言的编码规范,了解和使用这些已经被广泛认同的规范应该是你学习阶段最重要的实践。我会在书中尽量使用已经讲解的概念或者技巧来解释相关的代码示例,以避免你在不了解某些高级概念的情况下而感到迷茫。 我们通过 227 个完整的代码示例和书中的解释说明来对所有涉及到的概念和技巧进行彻底的讲解,你可以下载这些代码到你的电脑上运行,从而加深对概念的理解。 本书会尽可能地将前后章节的内容联系起来,当然这也同时要求你通过学习不同的知识来对一个问题提出尽可能多的解决方案。记住,学习一门新语言的最佳方式就是实践,运行它的代码,修改并尝试更多的方案。因此,你绝对不可以忽略书中的 130 个代码练习,这将对你学习好 Go 语言有很大的帮助。比如,我们就为斐波那契算法提供了 13 个不同的版本,而这些版本都使用了不同的概念和技巧。 你可以通过访问本书的 官方网站 下载书中的代码(译者注:所有代码文件已经包括在 GitHub 仓库中),并获得有关本书的勘误情况和内容更新。 为了让你在成为 Go 语言大师的道路上更加顺利,我们会专注于一些特别的章节以提供 Go 语言开发模式的最佳实践,同时也会帮助初学者逃离一些语言的陷阱。第 18 章可以作为你在开发时的一个参考手册,因为当中包含了众多的有价值的代码片段以及相关的解释说明。 最后要说明的是,你可以通过完整的索引来快速定位你需要阅读的章节。书中所有的代码都在 Go1.4 版本下测试通过。 这里有一段来自在 C++、Java 和 Python 领域众所周知的专家 Bruce Eckel 的评论: “作为一个有着 C/C++ 背景的开发者,我在使用 Go 语言时仿佛呼吸到了新鲜空气一般,令人心旷神怡。我认为使用 Go 语言进行系统编程开发比使用 C++ 有着更显著的优势,因为它在解决一些很难用 C++ 解决的问题的同时,让我的工作变得更加高效。我并不是说 C++ 的存在是一个错误,相反地,我认为这是历史发展的必然结果。当我深陷在 C 语言这门略微比汇编语言好一点的泥潭时,我坚信任何语言的构造都不可能支持大型项目的开发。像垃圾回收或并发语言支持这类东西,在当时都是极其荒谬的主意,根本没有人在乎。C++ 向大型项目开发迈出了重要的第一步,带领我们走进这个广袤无垠的世界。很庆幸 Stroustrup 做了让 C++ 兼容 C 语言以能够让其编译 C 程序这个正确的决定。我们当时需要 C++ 的出现。” “之后我们学到了更多。我们毫无疑问地接受了垃圾回收,异常处理和虚拟机这些当年人们认为只有疯子才会想的东西。C++ 的复杂程度(新版的 C++ 甚至更加复杂)极大的影响了软件开发的高效性,这使得它再也不再适合这个时代。人们不再像过往那样认同在 C++ 中兼容使用 C 语言的方法,认为这些工作只是在浪费时间,牺牲人们的努力。就在此时,Go 语言已经成功地解决了 C++ 中那些本打算解决却未能解决的关键问题。” 我非常想要向发明这门精湛的语言的 Go 开发团队表示真挚的感谢,尤其是团队的领导者 Rob Pike、Russ Cox 和 Andrew Gerrand,他们阐述的例子和说明都非常的完美。同时,我还要感谢 Miek Gieben、Frank Muller、Ryanne Dolan 和 Satish V.J. 给予我巨大的帮助,还有那些 golang-nuts 邮件列表里的所有的成员。 欢迎来到 Go 语言开发的奇妙世界! 链接目录下一部分: Go 语言的起源,发展与普及","tags":[],"categories":[{"name":"Go入门指南","slug":"Go入门指南","permalink":"https://wiki.zunpeng.xyz/categories/Go入门指南/"}]},{"title":"目录","date":"2020-03-21T14:30:00.000Z","path":"wiki/Go入门指南/目录/","text":"目录 前言 第一部分:学习 Go 语言 第1章:Go 语言的起源,发展与普及 1.1 起源与发展 1.2 语言的主要特性与发展的环境和影响因素 第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 解释器 第3章:编辑器、集成开发环境与其它工具3.1 Go 开发环境的基本要求3.2 编辑器和集成开发环境3.3 调试器3.4 构建并运行 Go 程序3.5 格式化代码3.6 生成代码文档3.7 其它工具3.8 Go 性能说明3.9 与其它语言进行交互 第二部分:语言的核心结构与技术 第4章:基本结构和基本数据类型4.1 文件名、关键字与标识符4.2 Go 程序的基本结构和要素4.3 常量4.4 变量4.5 基本类型和运算符4.6 字符串4.7 strings 和 strconv 包4.8 时间和日期4.9 指针 第5章:控制结构5.1 if-else 结构5.2 测试多返回值函数的错误5.3 switch 结构5.4 for 结构5.5 Break 与 continue5.6 标签与 goto 第6章:函数(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章:数组与切片7.1 声明和初始化7.2 切片7.3 For-range 结构7.4 切片重组(reslice)7.5 切片的复制与追加7.6 字符串、数组和切片的应用 第8章:Map8.1 声明、初始化和 make8.2 测试键值对是否存在及删除元素8.3 for-range 的配套用法8.4 map 类型的切片8.5 map 的排序8.6 将 map 的键值对调 第9章:包(package)9.1 标准库概述9.2 regexp 包9.3 锁和 sync 包9.4 精密计算和 big 包9.5 自定义包和可见性9.6 为自定义包使用 godoc9.7 使用 go install 安装自定义包9.8 自定义包的目录结构、go install 和 go test9.9 通过 Git 打包和安装9.10 Go 的外部包和项目9.11 在 Go 程序中使用外部库 第10章:结构(struct)与方法(method)10.1 结构体定义10.2 使用工厂方法创建结构体实例10.3 使用自定义包中的结构体10.4 带标签的结构体10.5 匿名字段和内嵌结构体10.6 方法10.7 类型的 String() 方法和格式化描述符10.8 垃圾回收和 SetFinalizer 第11章:接口(interface)与反射(reflection)11.1 接口是什么11.2 接口嵌套接口11.3 类型断言:如何检测和转换接口变量的类型11.4 类型判断:type-switch11.5 测试一个值是否实现了某个接口11.6 使用方法集与接口11.7 第一个例子:使用 Sorter 接口排序11.8 第二个例子:读和写11.9 空接口11.10 反射包11.11 Printf 和反射11.12 接口与动态类型11.13 总结:Go 中的面向对象11.14 结构体、集合和高阶函数 第三部分:Go 高级编程 第12章:读写数据12.1 读取用户的输入12.2 文件读写12.3 文件拷贝12.4 从命令行读取参数12.5 用 buffer 读取文件12.6 用切片读写文件12.7 用 defer 关闭文件12.8 使用接口的实际例子:fmt.Fprintf12.9 格式化 JSON 数据12.10 XML 数据格式12.11 用 Gob 传输数据12.12 Go 中的密码学 第13章:错误处理与测试13.1 错误处理13.2 运行时异常和 panic13.3 从 panic 中恢复(Recover)13.4 自定义包中的错误处理和 panicking13.5 一种用闭包处理错误的模式13.6 启动外部命令和程序13.7 Go 中的单元测试和基准测试13.8 测试的具体例子13.9 用(测试数据)表驱动测试13.10 性能调试:分析并优化 Go 程序 第14章:协程(goroutine)与通道(channel)14.1 并发、并行和协程14.2 使用通道进行协程间通信14.3 协程同步:关闭通道-对阻塞的通道进行测试14.4 使用 select 切换协程14.5 通道,超时和计时器(Ticker)14.6 协程和恢复(recover)14.7 新旧模型对比:任务和worker14.8 惰性生成器的实现14.9 实现 Futures 模式14.10 复用14.11 限制同时处理的请求数14.12 链式协程14.13 在多核心上并行计算14.14 并行化大量数据的计算14.15 漏桶算法14.16 对Go协程进行基准测试14.17 使用通道并发访问对象 第15章:网络、模版与网页应用15.1 tcp服务器15.2 一个简单的web服务器15.3 访问并读取页面数据15.4 写一个简单的网页应用15.5 确保网页应用健壮15.6 用模板编写网页应用15.7 探索 template 包15.8 精巧的多功能网页服务器15.9 用 rpc 实现远程过程调用15.10 基于网络的通道 netchan15.11 与 websocket 通信15.12 用 smtp 发送邮件 第四部分:实际应用 第16章:常见的陷阱与错误16.1 误用短声明导致变量覆盖16.2 误用字符串16.3 发生错误时使用defer关闭一个文件16.4 何时使用new()和make()16.5 不需要将一个指向切片的指针传递给函数16.6 使用指针指向接口类型16.7 使用值类型时误用指针16.8 误用协程和通道16.9 闭包和协程的使用16.10 糟糕的错误处理 第17章:模式17.1 逗号ok模式17.2 defer 模式17.3 可见性模式17.4 运算符模式和接口 第18章:出于性能考虑的实用代码片段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章:构建一个完整的应用程序 第20章:Go 语言在 Google App Engine 的使用 第21章:实际部署案例 附录 A 代码引用 B 有趣的 Go 引用 C 代码示例列表 D 书中的包引用 E 书中的工具引用 F 常见问题解答 G 习题答案 H 参考文献索引","tags":[],"categories":[{"name":"Go入门指南","slug":"Go入门指南","permalink":"https://wiki.zunpeng.xyz/categories/Go入门指南/"}]},{"title":"1.1 起源与发展","date":"2020-03-21T14:30:00.000Z","path":"wiki/Go入门指南/第一章 Go语言的起源,发展与普及/1.1 起源与发展/","text":"语言起源 2007 年,并于 2009 年正式对外发布。它从 2009 年 9 月 21 日开始作为谷歌公司 20% 兼职项目,即相关员工利用 20% 的空余时间来参与 Go 语言的研发工作。该项目的三位领导者均是著名的 IT 工程师:Robert Griesemer,参与开发 Java HotSpot 虚拟机;Rob Pike,Go 语言项目总负责人,贝尔实验室 Unix 团队成员,参与的项目包括 Plan 9,Inferno 操作系统和 Limbo 编程语言;Ken Thompson,贝尔实验室 Unix 团队成员,C 语言、Unix 和 Plan 9 的创始人之一,与 Rob Pike 共同开发了 UTF-8 字符集规范。自 2008 年 1 月起,Ken Thompson 就开始研发一款以 C 语言为目标结果的编译器来拓展 Go 语言的设计思想。 这是一个由计算机领域 “发明之父” 所组成的黄金团队,他们对系统编程语言,操作系统和并行都有着非常深刻的见解 在 2008 年年中,Go 语言的设计工作接近尾声,一些员工开始以全职工作状态投入到这个项目的编译器和运行实现上。Ian Lance Taylor 也加入到了开发团队中,并于 2008 年 5 月创建了一个 gcc 前端。 Russ Cox 加入开发团队后着手语言和类库方面的开发,也就是 Go 语言的标准包。在 2009 年 10 月 30 日,Rob Pike 以 Google Techtalk 的形式第一次向人们宣告了 Go 语言的存在。 直到 2009 年 11 月 10 日,开发团队将 Go 语言项目以 BSD-style 授权(完全开源)正式公布了 Linux 和 Mac OS X 平台上的版本。Hector Chu 于同年 11 月 22 日公布了 Windows 版本。 作为一个开源项目,Go 语言借助开源社区的有生力量达到快速地发展,并吸引更多的开发者来使用并改善它。自该开源项目发布以来,超过 200 名非谷歌员工的贡献者对 Go 语言核心部分提交了超过 1000 个修改建议。在过去的 18 个月里,又有 150 开发者贡献了新的核心代码。这俨然形成了世界上最大的开源团队,并使该项目跻身 Ohloh 前 2% 的行列。大约在 2011 年 4 月 10 日,谷歌开始抽调员工进入全职开发 Go 语言项目。开源化的语言显然能够让更多的开发者参与其中并加速它的发展速度。Andrew Gerrand 在 2010 年加入到开发团队中成为共同开发者与支持者。 在 Go 语言在 2010 年 1 月 8 日被 Tiobe(闻名于它的编程语言流行程度排名)宣布为 “2009 年年度语言” 后,引起各界很大的反响。目前 Go 语言在这项排名中的最高记录是在 2017 年 1 月创下的第13名,流行程度 2.325%。 时间轴: 2007 年 9 月 21 日:雏形设计 2009 年 11 月 10日:首次公开发布 2010 年 1 月 8 日:当选 2009 年年度语言 2010 年 5 月:谷歌投入使用 2011 年 5 月 5 日:Google App Engine 支持 Go 语言 从 2010 年 5 月起,谷歌开始将 Go 语言投入到后端基础设施的实际开发中,例如开发用于管理后端复杂环境的项目。有句话叫 “吃你自己的狗食”,这也体现了谷歌确实想要投资这门语言,并认为它是有生产价值的。 Go 语言的官方网站是 golang.org,这个站点采用 Python 作为前端,并且使用 Go 语言自带的工具 godoc 运行在 Google App Engine 上来作为 Web 服务器提供文本内容。在官网的首页有一个功能叫做 Go Playground,是一个 Go 代码的简单编辑器的沙盒,它可以在没有安装 Go 语言的情况下在你的浏览器中编译并运行 Go,它提供了一些示例,其中包括国际惯例 “Hello, World!”。 更多的信息详见 github.com/golang/go,Go 项目 Bug 追踪和功能预期详见 github.com/golang/go/issues。 Go 通过以下的 Logo 来展示它的速度,并以囊地鼠(Gopher)作为它的吉祥物。 谷歌邮件列表 golang-nuts 非常活跃,每天的讨论和问题解答数以百计。 关于 Go 语言在 Google App Engine 的应用,这里有一个单独的邮件列表 google-appengine-go,不过 2 个邮件列表的讨论内容并不是分得很清楚,都会涉及到相关的话题。go-lang.cat-v.org/ 是 Go 语言开发社区的资源站,irc.freenode.net 的#go-nuts 是官方的 Go IRC 频道。 @golang 是 Go 语言在 Twitter 的官方帐号,大家一般使用 #golang 作为话题标签。 这里还有一个在 Linked-in 的小组:www.linkedin.com/groups?gid=2524765&trk=myg_ugrp_ovr。 Go 编程语言的维基百科:en.wikipedia.org/wiki/Go_(programming_language) “en.wikipedia.org/wiki/Go_(programming_language)”) Go 语言相关资源的搜索引擎页面:gowalker.org Go 语言还有一个运行在 Google App Engine 上的 Go Tour,你也可以通过执行命令 go install go-tour.googlecode.com/hg/gotour 安装到你的本地机器上。对于中文读者,可以访问该指南的 中文版本,或通过命令 go install https://bitbucket.org/mikespook/go-tour-zh/gotour 进行安装。 链接 目录 上一部分:前言 下一节: 语言的主要特性与发展的环境和影响因素","tags":[],"categories":[{"name":"Go入门指南","slug":"Go入门指南","permalink":"https://wiki.zunpeng.xyz/categories/Go入门指南/"},{"name":"第一章 Go语言的起源,发展与普及","slug":"Go入门指南/第一章-Go语言的起源,发展与普及","permalink":"https://wiki.zunpeng.xyz/categories/Go入门指南/第一章-Go语言的起源,发展与普及/"}]},{"title":"About Me","date":"2017-01-21T17:55:57.000Z","path":"wiki/index/","text":"这是 zunpeng 的个人 Wiki 站点,主要记录一些自己总结的只言片语的零散知识点。 先后了解或尝试过 OneNote、Evernote、Blog、leanote、Mindoc 等方式,或多或少都感觉欠缺些什么,在网上看到https://www.v2ex.com/t/347176?p=1这篇文章后,感觉作者的wiki制作的很漂亮(简洁、明了),顿时眼前一亮,决定参考其github上的源码做一下,终于搞了两天搞了出来,本人的wiki并没有使用github,而是使用的个人搭建的gitbucket做为版本管理器。 其主要特点就是: 界面简洁美观,排版字体友好 支持多级分类 方便修改和更新内容 部署简单 分类目录可展开和收缩 展开分类时可查看该分类下所有文章 / 词条的标题 每篇文章 / 词条能添加多个分类 / 标签 Wiki 可支持引用内部链接 使用 Markdown 书写文章 / 词条 支持全文搜索(可搜索内容和标题)","tags":[],"categories":[]}]}