没有合适的资源?快使用搜索试试~ 我知道了~
首页Go编程语言权威指南:解决实际问题与面向对象编程详解
Go编程语言权威指南:解决实际问题与面向对象编程详解
![](https://csdnimg.cn/release/wenkucmsfe/public/img/star.98a08eaa.png)
《Go编程语言》(Addison,2015)是一本专为想要学习Go语言的程序员打造的权威指南。无论你之前熟悉JavaScript、Ruby、Python、Java还是C++,这本书都能提供一个易于入门的起点,因为它不依赖于对Go的预先了解或特定编程经验。该书以实际问题为导向,通过文件I/O和文本处理、简单图形、Web客户端和服务器的示例程序,引导读者理解Go的基本概念。 第一部分是教程,让读者通过实践快速掌握Go的核心概念。接下来的章节深入探讨了Go程序的结构元素,如语法、控制流程、数据类型,以及如何组织程序成包、文件和函数。书中展示了大量标准库中的包,并指导读者如何创建自己的包。这部分内容强调了Go的模块系统及其在项目构建、测试和维护中的应用。 关于方法和接口的章节,作者揭示了Go在面向对象编程上的独特之处。Go支持方法在任何类型上声明,而接口则隐式实现,这让封装、组合和替换原则得以在现实世界案例中得到体现。这些章节解释了Go中面向对象编程的关键概念,以及如何有效地利用这些特性来设计和实现代码。 值得注意的是,本书尊重知识产权,指出许多制造商和销售商使用的标识可能为商标,并提醒读者购买时应遵守相关法规。作者和出版商对书中信息和程序的准确性承担责任,但不保证无误,也不承担因使用书中的信息或程序导致的偶然或间接损害的责任。 对于批量购买或特殊销售机会(包括电子版),读者可以在www.it-ebooks.info网站上获取更多信息。《Go编程语言》是一本全面且实用的教程,无论是初学者还是有经验的开发者,都能从中收获关于Go语言的深入理解和实践技巧。
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/9444684/bg10.jpg)
ptg16091132
THE GO PROJECTxv
Or ganization ofthe Book
We assume thatyou haveprogrammed inone ormoreother langu ages, whether comp ile d li ke
C, C++, andJava, orint erprete d li kePyt hon,Ruby, and JavaS crip t,sowewon’tspell out every-
thingasiffor a tot a lbeg inner.Sur face sy ntaxwill befami liar,aswill var iables andcon stants,
expressions,control flow,and functions.
Chapter1 isatut orialonthe basic cons tructsofGo, int roduce d thro ugh a dozen programsfor
ever ydaytasks like readingand writing files, for matting text, creating images, andcommuni-
cating wit h Internet clients andser vers.
Chapter2 des crib e sthe str uctural elements ofaGoprogram—de clarat ions,var iables, new
types, packages and files, andscope.Chapt er3 dis c ussesnumbers,boole ans, str ings, andcon-
st ants, andexplainshow topro cessUnico de.Chapt er4 des crib escomposite typ es, that is,
typesbui ltupfro m simpler onesusingarrays, maps, str ucts, and sli ces,Go’sappro ach to
dy namic lists. Chapt e r5 cov ers functions and dis cusseserror handling, panic and recover,
andthe defer st atement.
Chapters 1 through 5 are thu s thebasics, things thatare par t of any mainst reamimp erat ive
language . Go’ssyntaxand sty lesom etimesdif fer fro m ot her langu ages, but mostprogram-
mers will pickthemupquickly. The remainingchapt ers focus ontopics where Go’sappro ach
is lessconvent ion a l: met hods, interfaces, conc urrency,packages, testing , andreflec tion.
Go has an unusualappro a ch to obj e c t-oriente d prog ramming. There are noclass hierarchies,
or indeed any class es; comp lex obj e ctbeh avior s arecre ate d from simpler onesbycomposition,
notinher itance. Met hodsmay beass o ci ated wit h anyuser-define d type,not juststr uctures,
andthe rel ation shipbet weencon c rete typ es andabstrac t types(interfaces)isimp l icit, soa
concrete typ e maysat isf y an interface thatthe typ e’sdesig ner was unawareof. Met hodsare
covere d in Chapt er6and int erfaces in Chapt er7.
Chapter8 presentsGo’sappro ach to con cur rency,whichisbas e donthe ide a of communic at-
ingsequential pro cesses(CSP), embodie d by goroutinesand channel s.Cha pt er9 explainsthe
more tradition alasp ectsofcon c ur rency bas edonshare d var iables.
Chapter10des crib espackages, the mech a nism for organizinglibrar ies. Thischapt erals o
shows how tomakeeffec tive use ofthe go to ol, whichprovides for compi l at ion, testing ,
benchmarking , prog ram formatting , do cumentation,and manyother tasks, allwit h in a single
command.
Chapter11deals wit h test ing , whereGotakes a not ably lig htweig htappro ach,avoiding
abstrac tion-l aden framewor ksinfavor of simplelibrar ies andtools.The testing librar ies
prov ide a found ation atopwhichmorecomplex abstrac tions can bebui ltifnecessary.
Chapter12dis c ussesreflec tion,the abi l it y of a prog ram to examineits own represent ation
during exe c ut i on.Reflec tion isapow erfultool, thoug h on e to beusedcaref ully; thischapt e r
explains findingthe rig htbal ance byshowing how itisusedtoimp lementsom e importantGo
librar ies. Chapter13explainsthe gor y det ai ls oflow-le vel programmingthatusesthe unsafe
packagetosteparo und Go’styp e system, andwhenthatisappro priate.
The Go Programming Language
© 2016 Alan A. A. Donovan & Brian W. Kernighan
revision 3b600c, date 29 Sep 2015
www.it-ebooks.info
![](https://csdnimg.cn/release/download_crawler_static/9444684/bg11.jpg)
ptg16091132
xvi PREFACE
Each chapterhas a numberofexercis esthatyou can use totestyourunderst andingofGo, and
to explore extensions and alt e rnat ivestothe examples fro m thebook.
Al l butthe most trivialcodeexamples in the bookare avai lable for dow n lo ad from the public
Gitrep ository at gopl.io.Eachexampleisidentified byits packageimp o rt pat h andmay be
conv enientlyfetch ed, bui lt, andins tal le d usingthe go get command. You’ll need tocho ose a
direc tor y to beyourGowor ksp ace andset the GOPATH enviro nment var iable topoint toit.
The go to olwill cre ate the direc tor y if necessary.For example:
$export GOPATH=$HOME/gobook #choose workspace directory
$goget gopl.io/ch1/helloworld #fetch, build, install
$$GOPATH/bin/helloworld # run
Hello, BF
To run the examples, you will need atleast version1.5 ofGo.
$goversion
go version go1.5 linux/amd64
Fo llowthe ins tructions at https://golang.org/doc/install if the go to olonyou rcom-
puterisolder ormissing.
WheretoFind MoreInformation
Thebestsourcefor moreinfor mat ionabout Goisthe offici al we b site, https://golang.org,
whichprovides accesstothe documentation,includingthe Go Programmi n g Lang uageSpecifi-
cati on,stand ard packages, andthe like. There are als o tutorialsonhow towrite Goand how
to write itwel l,and a wide variet y of onlinetext andvide o resources thatwill bevaluablecom-
plements tothisbook. TheGoBlog at blog.golang.org pu blishessom e of the bestwriting
on Go, wit h ar ticles onthe state ofthe langu age, plans for the fut ure , reportsonconferences,
andin-depth explanation s of a wide variet y of Go-rel ate d topics.
Oneofthe most usefulasp ectsofonlineaccesstoGo(andareg rettablelimitation of a pap er
book) isthe abi lit y to run Goprogramsfro m theweb pages thatdes crib e them. Thisfunc-
tion ality isprovide d by the GoPlayg round at play.golang.org,and may beemb edde d
within other pages, suchasthe home pageat golang.org or the documentation pages ser ved
by the godoc to ol.
ThePlayg round makes itconvenienttoper for m simpleexp eriments toche ckone’sunder-
st andingofsyntax, semantics, orlibrar y packages wit h short programs, andinmanyways
takesthe place ofare ad-e val-print loop (REPL) in other langu ages. Its persistentURLs are
greatfor sharing snipp ets ofGocodewit h ot h ers, for rep ortingbugs ormak ingsug gestion s.
Builtatopthe Playg round,the GoTourat tour.golang.org is a sequence ofshort int erac tive
lessons onthe basic ideas andcon str uctions ofGo, anorderly wal k thro ugh the langu age.
Theprimary shortcomingofthe Playg round and the Touristhatthe y al lowonlystand ard
librar ies to beimp o rted,and manylibrar y fe ature s—networ k ing, for example—arerestr icted
The Go Programming Language
© 2016 Alan A. A. Donovan & Brian W. Kernighan
revision 3b600c, date 29 Sep 2015
www.it-ebooks.info
![](https://csdnimg.cn/release/download_crawler_static/9444684/bg12.jpg)
ptg16091132
WHERE TOFIND MORE INFORMATION xvii
forprac t ic al or sec urity reasons.The y also requireaccesstothe Int e rnet tocompi leand run
each program. Sofor moreelaborateexp eriments, you will havetorun Goprogramsonyour
ow n comp uter. For tunatelythe dow nlo ad processisstraig htfor ward, soitshouldnot take
more thanafew minut estofetch the Godistr ibution fro m golang.org andstart writing and
runningGoprogramsofyourown.
SinceGoisanopen-s ource pro jec t,you can readthe codefor any typ e or functioninthe stan-
dard librar y on l ineat https://golang.org/pkg;the samecodeispar t of the dow n lo ade d
dist ribut ion.Use thisto figureout how som ethingwor ks, ortoanswerquestion s ab out
det ails,ormerelytosee how exp erts write reallygood Go.
Acknowledgments
RobPikeand RussCox,coremembers ofthe Goteam, readthe manus cript several times wit h
greatcare; their comments oneverythingfro m word choice tooveral l st r uc tureand organiza-
tion havebeeninvaluable. Whi le prep aringthe Jap anes e transl ation,Yoshi kiShibata wentfar
beyond the cal l of duty; his met iculou s eyespott ednumerou s inconsistencies in the Eng lish
text anderror s in the code. Wegre atlyappre ciate thoro ugh revie ws andcriticalcomme ntson
theent i re manus cript fro m Br ian Goetz, Corey Kos ak, Ar noldRobbins, JoshBle e cherSny d er,
andPeter Weinberger.
We are indebte d to SameerAjmani,Itt aiBal aban, Dav id Crawshaw, BillyDon ohue, Jon athan
Feinberg , Andrew Gerrand, Rob ert Gries emer,JohnLinder man, Minux Ma, Bryan Mills, Bal a
Nataraj an, Cosmos Nicolaou , Paul Stanifor th, Nigel Tao,and HowardTrickey for many
helpf ulsug gestion s.Weals o than k DavidBrai lsfordand RaphLevien for typ esetting adv ice.
OureditorGre gDoenchatAddison-Wesle y gotthe bal l ro l lingoriginallyand has beencon-
tinuou sly helpf u leversince.The AWpro duc tionteam—Jo h nFuller,Day naIsley,Julie Nahi l,
Chut i Pras ertsith,and Barb ara Wo o d—hasbeenoutst anding; author s couldnot hop e forbet-
tersup p or t .
AlanDon ovan wishestothank:SameerAjmani,Chr isDemet riou, WaltDrummon d,and Reid
TatgeatGooglefor allow i ng him timetowrite;Steph enDon ovan, for his adv ice andtimely
encouragement; andabove all,his wifeLei laKazemi,for her unhesitating ent husi asm and
unwaver ingsup por t forthispro jec t,despit e thelon g hoursofdistrac tionand abs ente eism
from fami lylifethatitent a iled.
Br ian Ker nighanisdeeply gratef ultofriends and col leagues for their pat ience andforbearance
as hemov edslowlyalong the pat h to underst anding, and esp eci ally tohis wifeMeg , whohas
been unfailinglysup por t iveofbook-w rit i ng and somuchels e.
Ne w Yo r k
Oc tob er2015
The Go Programming Language
© 2016 Alan A. A. Donovan & Brian W. Kernighan
revision 3b600c, date 29 Sep 2015
www.it-ebooks.info
![](https://csdnimg.cn/release/download_crawler_static/9444684/bg14.jpg)
ptg16091132
1
Tutorial
Thischapt e risatourofthe basic comp onent sofGo. Wehop e to provide enough infor mat ion
andexamples toget you off the gro und and doing usefulthings as quicklyaspossible. The
examples here, and indeed inthe whole book, areaimed attasks thatyou mig hthavetodoin
therealwor ld. Inthischapt erwe’ll trytogiveyou a taste ofthe diversity ofprogramsthatone
mig htwrite inGo, ranging fro m simple file pro cessingand a bit of graphics tocon c ur rent
Internet clients andser vers. Wecer tain lywon’texplain everythinginthe firs t ch apt er, but
studying suchprogramsinanew langu agecan beaneffec tive way toget started.
Wh enyou’re learninganew langu age, there’sanatural tendency towrite codeasyou wou l d
have writt enitinalangu ageyou already know. Beawareofthisbiasasyou learn Goand try
to avoid it. We’ve tried toillustrateand explain how towrite good Go, souse the codehereas
aguide whenyou’re writing your own.
1.1. Hello, World
We’ll start wit h thenow-t radition al ‘‘hel l o, wor l d’’ example, whichapp e arsatthe beg inningof
TheCProgrammi n g Lang uag e,publishe d in 1978. Cisone ofthe most direc t influences on
Go,and ‘‘hel lo, wor ld’’ illustrates a numberofcentral ideas.
gopl.io/ch1/helloworld
package main
import "fmt"
func main() {
fmt.Println("Hello, BF")
}
1
The Go Programming Language
© 2016 Alan A. A. Donovan & Brian W. Kernighan
revision 3b600c, date 29 Sep 2015
www.it-ebooks.info
剩余399页未读,继续阅读
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/a85f9b5ddf8441b8b4d02a19e1ce0d8e_vanridin.jpg!1)
vanridin
- 粉丝: 108
- 资源: 1191
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
会员权益专享
最新资源
- VMP技术解析:Handle块优化与壳模板初始化
- C++ Primer 第四版更新:现代编程风格与标准库
- 计算机系统基础实验:缓冲区溢出攻击(Lab3)
- 中国结算网上业务平台:证券登记操作详解与常见问题
- FPGA驱动的五子棋博弈系统:加速与创新娱乐体验
- 多旋翼飞行器定点位置控制器设计实验
- 基于流量预测与潮汐效应的动态载频优化策略
- SQL练习:查询分析与高级操作
- 海底数据中心散热优化:从MATLAB到动态模拟
- 移动应用作业:MyDiaryBook - Google Material Design 日记APP
- Linux提权技术详解:从内核漏洞到Sudo配置错误
- 93分钟快速入门 LaTeX:从入门到实践
- 5G测试新挑战与罗德与施瓦茨解决方案
- EAS系统性能优化与故障诊断指南
- Java并发编程:JUC核心概念解析与应用
- 数据结构实验报告:基于不同存储结构的线性表和树实现
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)