mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-11-25 15:48:56 +00:00
2146 lines
73 KiB
HTML
2146 lines
73 KiB
HTML
|
<!DOCTYPE HTML>
|
||
|
<html lang="zh-tw" >
|
||
|
|
||
|
<head>
|
||
|
|
||
|
<meta charset="UTF-8">
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||
|
<title>Hello, World | Go编程语言</title>
|
||
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||
|
<meta name="description" content="">
|
||
|
<meta name="generator" content="GitBook 2.5.2">
|
||
|
|
||
|
|
||
|
<meta name="HandheldFriendly" content="true"/>
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||
|
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
|
||
|
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
||
|
|
||
|
<link rel="stylesheet" href="../gitbook/style.css">
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="next" href="../ch1/ch1-02.html" />
|
||
|
|
||
|
|
||
|
<link rel="prev" href="../ch1/ch1.html" />
|
||
|
|
||
|
|
||
|
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
|
||
|
<div class="book" data-level="1.1" data-chapter-title="Hello, World" data-filepath="ch1/ch1-01.md" data-basepath=".." data-revision="Wed Dec 09 2015 15:54:13 GMT+0800 (中国标准时间)">
|
||
|
|
||
|
|
||
|
<div class="book-summary">
|
||
|
<nav role="navigation">
|
||
|
<ul class="summary">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="0" data-path="index.html">
|
||
|
|
||
|
|
||
|
<a href="../index.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
前言
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="0.1" data-path="ch0/ch0-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch0/ch0-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>0.1.</b>
|
||
|
|
||
|
Go語言起源
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="0.2" data-path="ch0/ch0-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch0/ch0-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>0.2.</b>
|
||
|
|
||
|
Go語言項目
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="0.3" data-path="ch0/ch0-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch0/ch0-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>0.3.</b>
|
||
|
|
||
|
本書的組織
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="0.4" data-path="ch0/ch0-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch0/ch0-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>0.4.</b>
|
||
|
|
||
|
更多的信息
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="0.5" data-path="ch0/ch0-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch0/ch0-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>0.5.</b>
|
||
|
|
||
|
緻謝
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1" data-path="ch1/ch1.html">
|
||
|
|
||
|
|
||
|
<a href="../ch1/ch1.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>1.</b>
|
||
|
|
||
|
入門
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter active" data-level="1.1" data-path="ch1/ch1-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch1/ch1-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>1.1.</b>
|
||
|
|
||
|
Hello, World
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2" data-path="ch1/ch1-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch1/ch1-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>1.2.</b>
|
||
|
|
||
|
命令行參數
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.3" data-path="ch1/ch1-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch1/ch1-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>1.3.</b>
|
||
|
|
||
|
査找重復的行
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.4" data-path="ch1/ch1-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch1/ch1-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>1.4.</b>
|
||
|
|
||
|
GIF動畫
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.5" data-path="ch1/ch1-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch1/ch1-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>1.5.</b>
|
||
|
|
||
|
穫取URL
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.6" data-path="ch1/ch1-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch1/ch1-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>1.6.</b>
|
||
|
|
||
|
併髮穫取多個URL
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.7" data-path="ch1/ch1-07.html">
|
||
|
|
||
|
|
||
|
<a href="../ch1/ch1-07.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>1.7.</b>
|
||
|
|
||
|
Web服務
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.8" data-path="ch1/ch1-08.html">
|
||
|
|
||
|
|
||
|
<a href="../ch1/ch1-08.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>1.8.</b>
|
||
|
|
||
|
本章要點
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="2" data-path="ch2/ch2.html">
|
||
|
|
||
|
|
||
|
<a href="../ch2/ch2.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>2.</b>
|
||
|
|
||
|
程序結構
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="2.1" data-path="ch2/ch2-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch2/ch2-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>2.1.</b>
|
||
|
|
||
|
命名
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="2.2" data-path="ch2/ch2-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch2/ch2-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>2.2.</b>
|
||
|
|
||
|
聲明
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="2.3" data-path="ch2/ch2-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch2/ch2-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>2.3.</b>
|
||
|
|
||
|
變量
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="2.4" data-path="ch2/ch2-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch2/ch2-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>2.4.</b>
|
||
|
|
||
|
賦值
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="2.5" data-path="ch2/ch2-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch2/ch2-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>2.5.</b>
|
||
|
|
||
|
類型
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="2.6" data-path="ch2/ch2-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch2/ch2-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>2.6.</b>
|
||
|
|
||
|
包和文件
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="2.7" data-path="ch2/ch2-07.html">
|
||
|
|
||
|
|
||
|
<a href="../ch2/ch2-07.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>2.7.</b>
|
||
|
|
||
|
作用域
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="3" data-path="ch3/ch3.html">
|
||
|
|
||
|
|
||
|
<a href="../ch3/ch3.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>3.</b>
|
||
|
|
||
|
基礎數據類型
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="3.1" data-path="ch3/ch3-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch3/ch3-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>3.1.</b>
|
||
|
|
||
|
整型
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="3.2" data-path="ch3/ch3-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch3/ch3-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>3.2.</b>
|
||
|
|
||
|
浮點數
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="3.3" data-path="ch3/ch3-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch3/ch3-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>3.3.</b>
|
||
|
|
||
|
復數
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="3.4" data-path="ch3/ch3-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch3/ch3-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>3.4.</b>
|
||
|
|
||
|
佈爾型
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="3.5" data-path="ch3/ch3-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch3/ch3-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>3.5.</b>
|
||
|
|
||
|
字符串
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="3.6" data-path="ch3/ch3-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch3/ch3-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>3.6.</b>
|
||
|
|
||
|
常量
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="4" data-path="ch4/ch4.html">
|
||
|
|
||
|
|
||
|
<a href="../ch4/ch4.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>4.</b>
|
||
|
|
||
|
復閤數據類型
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="4.1" data-path="ch4/ch4-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch4/ch4-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>4.1.</b>
|
||
|
|
||
|
數組
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="4.2" data-path="ch4/ch4-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch4/ch4-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>4.2.</b>
|
||
|
|
||
|
切片
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="4.3" data-path="ch4/ch4-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch4/ch4-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>4.3.</b>
|
||
|
|
||
|
字典
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="4.4" data-path="ch4/ch4-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch4/ch4-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>4.4.</b>
|
||
|
|
||
|
結構體
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="4.5" data-path="ch4/ch4-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch4/ch4-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>4.5.</b>
|
||
|
|
||
|
JSON
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="4.6" data-path="ch4/ch4-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch4/ch4-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>4.6.</b>
|
||
|
|
||
|
文本和HTML模闆
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="5" data-path="ch5/ch5.html">
|
||
|
|
||
|
|
||
|
<a href="../ch5/ch5.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>5.</b>
|
||
|
|
||
|
函數
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="5.1" data-path="ch5/ch5-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch5/ch5-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>5.1.</b>
|
||
|
|
||
|
函數聲明
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="5.2" data-path="ch5/ch5-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch5/ch5-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>5.2.</b>
|
||
|
|
||
|
遞歸
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="5.3" data-path="ch5/ch5-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch5/ch5-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>5.3.</b>
|
||
|
|
||
|
多返迴值
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="5.4" data-path="ch5/ch5-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch5/ch5-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>5.4.</b>
|
||
|
|
||
|
錯誤
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="5.5" data-path="ch5/ch5-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch5/ch5-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>5.5.</b>
|
||
|
|
||
|
函數值
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="5.6" data-path="ch5/ch5-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch5/ch5-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>5.6.</b>
|
||
|
|
||
|
匿名函數
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="5.7" data-path="ch5/ch5-07.html">
|
||
|
|
||
|
|
||
|
<a href="../ch5/ch5-07.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>5.7.</b>
|
||
|
|
||
|
可變參數
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="5.8" data-path="ch5/ch5-08.html">
|
||
|
|
||
|
|
||
|
<a href="../ch5/ch5-08.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>5.8.</b>
|
||
|
|
||
|
Deferred函數
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="5.9" data-path="ch5/ch5-09.html">
|
||
|
|
||
|
|
||
|
<a href="../ch5/ch5-09.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>5.9.</b>
|
||
|
|
||
|
Panic異常
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="5.10" data-path="ch5/ch5-10.html">
|
||
|
|
||
|
|
||
|
<a href="../ch5/ch5-10.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>5.10.</b>
|
||
|
|
||
|
Recover捕穫異常
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="6" data-path="ch6/ch6.html">
|
||
|
|
||
|
|
||
|
<a href="../ch6/ch6.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>6.</b>
|
||
|
|
||
|
方法
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="6.1" data-path="ch6/ch6-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch6/ch6-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>6.1.</b>
|
||
|
|
||
|
方法聲明
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="6.2" data-path="ch6/ch6-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch6/ch6-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>6.2.</b>
|
||
|
|
||
|
基於指鍼對象的方法
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="6.3" data-path="ch6/ch6-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch6/ch6-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>6.3.</b>
|
||
|
|
||
|
通過嵌入結構體來擴展類型
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="6.4" data-path="ch6/ch6-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch6/ch6-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>6.4.</b>
|
||
|
|
||
|
方法值和方法錶達式
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="6.5" data-path="ch6/ch6-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch6/ch6-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>6.5.</b>
|
||
|
|
||
|
示例: Bit數組
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="6.6" data-path="ch6/ch6-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch6/ch6-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>6.6.</b>
|
||
|
|
||
|
封裝
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7" data-path="ch7/ch7.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.</b>
|
||
|
|
||
|
接口
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="7.1" data-path="ch7/ch7-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.1.</b>
|
||
|
|
||
|
接口是閤約
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.2" data-path="ch7/ch7-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.2.</b>
|
||
|
|
||
|
接口類型
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.3" data-path="ch7/ch7-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.3.</b>
|
||
|
|
||
|
實現接口的條件
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.4" data-path="ch7/ch7-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.4.</b>
|
||
|
|
||
|
flag.Value接口
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.5" data-path="ch7/ch7-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.5.</b>
|
||
|
|
||
|
接口值
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.6" data-path="ch7/ch7-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.6.</b>
|
||
|
|
||
|
sort.Interface接口
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.7" data-path="ch7/ch7-07.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-07.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.7.</b>
|
||
|
|
||
|
http.Handler接口
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.8" data-path="ch7/ch7-08.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-08.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.8.</b>
|
||
|
|
||
|
error接口
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.9" data-path="ch7/ch7-09.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-09.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.9.</b>
|
||
|
|
||
|
示例: 錶達式求值
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.10" data-path="ch7/ch7-10.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-10.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.10.</b>
|
||
|
|
||
|
類型斷言
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.11" data-path="ch7/ch7-11.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-11.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.11.</b>
|
||
|
|
||
|
基於類型斷言識彆錯誤類型
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.12" data-path="ch7/ch7-12.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-12.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.12.</b>
|
||
|
|
||
|
通過類型斷言査詢接口
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.13" data-path="ch7/ch7-13.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-13.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.13.</b>
|
||
|
|
||
|
類型分支
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.14" data-path="ch7/ch7-14.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-14.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.14.</b>
|
||
|
|
||
|
示例: 基於標記的XML解碼
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="7.15" data-path="ch7/ch7-15.html">
|
||
|
|
||
|
|
||
|
<a href="../ch7/ch7-15.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>7.15.</b>
|
||
|
|
||
|
補充幾點
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="8" data-path="ch8/ch8.html">
|
||
|
|
||
|
|
||
|
<a href="../ch8/ch8.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>8.</b>
|
||
|
|
||
|
Goroutines和Channels
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="8.1" data-path="ch8/ch8-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch8/ch8-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>8.1.</b>
|
||
|
|
||
|
Goroutines
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="8.2" data-path="ch8/ch8-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch8/ch8-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>8.2.</b>
|
||
|
|
||
|
示例: 併髮的Clock服務
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="8.3" data-path="ch8/ch8-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch8/ch8-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>8.3.</b>
|
||
|
|
||
|
示例: 併髮的Echo服務
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="8.4" data-path="ch8/ch8-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch8/ch8-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>8.4.</b>
|
||
|
|
||
|
Channels
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="8.5" data-path="ch8/ch8-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch8/ch8-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>8.5.</b>
|
||
|
|
||
|
併行的循環
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="8.6" data-path="ch8/ch8-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch8/ch8-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>8.6.</b>
|
||
|
|
||
|
示例: 併髮的Web爬蟲
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="8.7" data-path="ch8/ch8-07.html">
|
||
|
|
||
|
|
||
|
<a href="../ch8/ch8-07.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>8.7.</b>
|
||
|
|
||
|
基於select的多路復用
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="8.8" data-path="ch8/ch8-08.html">
|
||
|
|
||
|
|
||
|
<a href="../ch8/ch8-08.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>8.8.</b>
|
||
|
|
||
|
示例: 併髮的字典遍歷
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="8.9" data-path="ch8/ch8-09.html">
|
||
|
|
||
|
|
||
|
<a href="../ch8/ch8-09.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>8.9.</b>
|
||
|
|
||
|
併髮的退齣
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="8.10" data-path="ch8/ch8-10.html">
|
||
|
|
||
|
|
||
|
<a href="../ch8/ch8-10.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>8.10.</b>
|
||
|
|
||
|
示例: 聊天服務
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="9" data-path="ch9/ch9.html">
|
||
|
|
||
|
|
||
|
<a href="../ch9/ch9.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>9.</b>
|
||
|
|
||
|
基於共享變量的併髮
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="9.1" data-path="ch9/ch9-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch9/ch9-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>9.1.</b>
|
||
|
|
||
|
競爭條件
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="9.2" data-path="ch9/ch9-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch9/ch9-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>9.2.</b>
|
||
|
|
||
|
sync.Mutex互斥鎖
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="9.3" data-path="ch9/ch9-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch9/ch9-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>9.3.</b>
|
||
|
|
||
|
sync.RWMutex讀寫鎖
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="9.4" data-path="ch9/ch9-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch9/ch9-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>9.4.</b>
|
||
|
|
||
|
內存衕步
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="9.5" data-path="ch9/ch9-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch9/ch9-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>9.5.</b>
|
||
|
|
||
|
sync.Once初始化
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="9.6" data-path="ch9/ch9-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch9/ch9-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>9.6.</b>
|
||
|
|
||
|
競爭條件檢測
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="9.7" data-path="ch9/ch9-07.html">
|
||
|
|
||
|
|
||
|
<a href="../ch9/ch9-07.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>9.7.</b>
|
||
|
|
||
|
示例: 併髮的非阻塞緩存
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="9.8" data-path="ch9/ch9-08.html">
|
||
|
|
||
|
|
||
|
<a href="../ch9/ch9-08.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>9.8.</b>
|
||
|
|
||
|
Goroutines和綫程
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="10" data-path="ch10/ch10.html">
|
||
|
|
||
|
|
||
|
<a href="../ch10/ch10.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>10.</b>
|
||
|
|
||
|
包和工具
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="10.1" data-path="ch10/ch10-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch10/ch10-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>10.1.</b>
|
||
|
|
||
|
簡介
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="10.2" data-path="ch10/ch10-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch10/ch10-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>10.2.</b>
|
||
|
|
||
|
導入路徑
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="10.3" data-path="ch10/ch10-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch10/ch10-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>10.3.</b>
|
||
|
|
||
|
包聲明
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="10.4" data-path="ch10/ch10-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch10/ch10-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>10.4.</b>
|
||
|
|
||
|
導入聲明
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="10.5" data-path="ch10/ch10-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch10/ch10-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>10.5.</b>
|
||
|
|
||
|
匿名導入
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="10.6" data-path="ch10/ch10-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch10/ch10-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>10.6.</b>
|
||
|
|
||
|
包和命名
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="10.7" data-path="ch10/ch10-07.html">
|
||
|
|
||
|
|
||
|
<a href="../ch10/ch10-07.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>10.7.</b>
|
||
|
|
||
|
工具
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="11" data-path="ch11/ch11.html">
|
||
|
|
||
|
|
||
|
<a href="../ch11/ch11.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>11.</b>
|
||
|
|
||
|
測試
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="11.1" data-path="ch11/ch11-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch11/ch11-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>11.1.</b>
|
||
|
|
||
|
go test
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="11.2" data-path="ch11/ch11-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch11/ch11-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>11.2.</b>
|
||
|
|
||
|
測試函數
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="11.3" data-path="ch11/ch11-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch11/ch11-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>11.3.</b>
|
||
|
|
||
|
測試覆蓋率
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="11.4" data-path="ch11/ch11-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch11/ch11-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>11.4.</b>
|
||
|
|
||
|
基準測試
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="11.5" data-path="ch11/ch11-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch11/ch11-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>11.5.</b>
|
||
|
|
||
|
剖析
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="11.6" data-path="ch11/ch11-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch11/ch11-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>11.6.</b>
|
||
|
|
||
|
示例函數
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="12" data-path="ch12/ch12.html">
|
||
|
|
||
|
|
||
|
<a href="../ch12/ch12.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>12.</b>
|
||
|
|
||
|
反射
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="12.1" data-path="ch12/ch12-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch12/ch12-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>12.1.</b>
|
||
|
|
||
|
為何需要反射?
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="12.2" data-path="ch12/ch12-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch12/ch12-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>12.2.</b>
|
||
|
|
||
|
reflect.Type和reflect.Value
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="12.3" data-path="ch12/ch12-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch12/ch12-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>12.3.</b>
|
||
|
|
||
|
Display遞歸打印
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="12.4" data-path="ch12/ch12-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch12/ch12-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>12.4.</b>
|
||
|
|
||
|
示例: 編碼S錶達式
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="12.5" data-path="ch12/ch12-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch12/ch12-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>12.5.</b>
|
||
|
|
||
|
通過reflect.Value脩改值
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="12.6" data-path="ch12/ch12-06.html">
|
||
|
|
||
|
|
||
|
<a href="../ch12/ch12-06.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>12.6.</b>
|
||
|
|
||
|
示例: 解碼S錶達式
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="12.7" data-path="ch12/ch12-07.html">
|
||
|
|
||
|
|
||
|
<a href="../ch12/ch12-07.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>12.7.</b>
|
||
|
|
||
|
穫取結構體字段標識
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="12.8" data-path="ch12/ch12-08.html">
|
||
|
|
||
|
|
||
|
<a href="../ch12/ch12-08.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>12.8.</b>
|
||
|
|
||
|
顯示一個類型的方法集
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="12.9" data-path="ch12/ch12-09.html">
|
||
|
|
||
|
|
||
|
<a href="../ch12/ch12-09.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>12.9.</b>
|
||
|
|
||
|
幾點忠告
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="13" data-path="ch13/ch13.html">
|
||
|
|
||
|
|
||
|
<a href="../ch13/ch13.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>13.</b>
|
||
|
|
||
|
底層編程
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="13.1" data-path="ch13/ch13-01.html">
|
||
|
|
||
|
|
||
|
<a href="../ch13/ch13-01.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>13.1.</b>
|
||
|
|
||
|
unsafe.Sizeof, Alignof 和 Offsetof
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="13.2" data-path="ch13/ch13-02.html">
|
||
|
|
||
|
|
||
|
<a href="../ch13/ch13-02.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>13.2.</b>
|
||
|
|
||
|
unsafe.Pointer
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="13.3" data-path="ch13/ch13-03.html">
|
||
|
|
||
|
|
||
|
<a href="../ch13/ch13-03.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>13.3.</b>
|
||
|
|
||
|
示例: 深度相等判斷
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="13.4" data-path="ch13/ch13-04.html">
|
||
|
|
||
|
|
||
|
<a href="../ch13/ch13-04.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>13.4.</b>
|
||
|
|
||
|
通過cgo調用C代碼
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="13.5" data-path="ch13/ch13-05.html">
|
||
|
|
||
|
|
||
|
<a href="../ch13/ch13-05.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>13.5.</b>
|
||
|
|
||
|
幾點忠告
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="14" data-path="exercise/ex.html">
|
||
|
|
||
|
|
||
|
<a href="../exercise/ex.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>14.</b>
|
||
|
|
||
|
習題解答
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="14.1" data-path="exercise/ex-ch1.html">
|
||
|
|
||
|
|
||
|
<a href="../exercise/ex-ch1.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>14.1.</b>
|
||
|
|
||
|
第一章 入門
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="15" data-path="errata.html">
|
||
|
|
||
|
|
||
|
<a href="../errata.html">
|
||
|
|
||
|
<i class="fa fa-check"></i>
|
||
|
|
||
|
<b>15.</b>
|
||
|
|
||
|
勘誤
|
||
|
</a>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<li class="divider"></li>
|
||
|
<li>
|
||
|
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
||
|
本書使用 GitBook 釋出
|
||
|
</a>
|
||
|
</li>
|
||
|
|
||
|
</ul>
|
||
|
</nav>
|
||
|
</div>
|
||
|
|
||
|
<div class="book-body">
|
||
|
<div class="body-inner">
|
||
|
<div class="book-header" role="navigation">
|
||
|
<!-- Actions Left -->
|
||
|
|
||
|
|
||
|
<!-- Title -->
|
||
|
<h1>
|
||
|
<i class="fa fa-circle-o-notch fa-spin"></i>
|
||
|
<a href="../" >Go编程语言</a>
|
||
|
</h1>
|
||
|
</div>
|
||
|
|
||
|
<div class="page-wrapper" tabindex="-1" role="main">
|
||
|
<div class="page-inner">
|
||
|
|
||
|
|
||
|
<section class="normal" id="section-">
|
||
|
|
||
|
<h2 id="11-hello-world">1.1. Hello, World</h2>
|
||
|
<p>我們以1978年,c語言歷史上經典的hello world案例來開始吧。C語言對Go語言的設計產生了很多影響。用這個例子,我們來講解一些Go語言的覈心特性:</p>
|
||
|
<pre><code class="lang-go"><span class="hljs-comment">//gopl.io/ch1/helloworld</span>
|
||
|
<span class="hljs-keyword">package</span> main
|
||
|
|
||
|
<span class="hljs-keyword">import</span> <span class="hljs-string">"fmt"</span>
|
||
|
|
||
|
<span class="hljs-keyword">func</span> main() {
|
||
|
fmt.Println(<span class="hljs-string">"Hello, BF"</span>)
|
||
|
}
|
||
|
</code></pre>
|
||
|
<p>Go是一門編譯型語言,Go的工具鏈將源代碼和其依賴一起打包,生成機器的本地指令(譯註:靜態編譯)。Go語言提供的工具可以通過go下的一繫列子命令來調用。最簡單的一個子命令就是run。這個命令會將一個或多個以.go結束的源文件,和關聯庫鏈接到一起,然後運行最終的可執行文件。(本書將用$錶示命令行的提示符)</p>
|
||
|
<pre><code>$ go run helloworld.go
|
||
|
</code></pre><p>毫無意外,這個命令會輸齣:</p>
|
||
|
<pre><code>Hello, BF
|
||
|
</code></pre><p>Go原生支持Unicode,所以你可以用Go處理世界上的任何語言。</p>
|
||
|
<p>如果你希望自己的程序不隻是簡單的一次性實驗,那麼你一定會希望能夠編譯這個程序,併且能夠將編譯結果保存下來以備將來之用。這個可以用build子命令來實現:</p>
|
||
|
<pre><code>$ go build helloworld.go
|
||
|
</code></pre><p>這會創建一個名為helloworld的可執行的二進製文件,之後你可以在任何時間去運行這個二進製文件,不需要其它的任何處理(譯註:因為是靜態編譯,所以也不用擔心在繫統庫更新的時候衝突,倖福感滿滿)。</p>
|
||
|
<p>下麫是運行我們的編譯結果樣例:</p>
|
||
|
<pre><code>$ ./helloworld
|
||
|
Hello, BF
|
||
|
</code></pre><p>本書中我們所有的例子都做了一個特殊標記,你可以通過這些標記在gopl.io在綫網站上找到這些樣例代碼,比如這個 gopl.io/ch1/helloworld</p>
|
||
|
<p>如果你執行go get gopl.io/ch1/helloworld,go能夠自己從網上穫取到這些代碼,併且將這些代碼放到對應的目彔中。更詳細的介紹在2.6和10.7章節中。</p>
|
||
|
<p>我們來討論一下程序本身。Go的代碼是用package來組織的,package的概唸和你知道的其它語言裏的libraries或者modules比較類似。一個package會包含一個或多個.go結束的源代碼文件。每一個源文件都是以一個package xxx的聲明開頭的,比如我們的例子裏就是package main。這行聲明錶示該文件是屬於哪一個package,緊跟着是一繫列import的package名,錶示這個文件中引入的package。再之後是本文件本身的代碼</p>
|
||
|
<p>Go的標準庫已經提供了100多個package,用來完成一門程序語言的一些基本任務,比如輸入、輸齣、排序或者字符串/文本處理。比如fmt這個package,就包括接收輸入、格式化輸齣的各種函數。Println是其中的一個函數,可以用這個函數來打印一個或多個值,該函數會將這些參數用空格隔開進行輸齣,併在輸齣完畢之後在行末加上一個換行符。</p>
|
||
|
<p>package main比較特殊。這個package裏會定義一個獨立的程序,這個程序是可以運行的,而不是像其它package一樣的library。在main這個package裏,main函數也是一個特殊的函數,這是我們整個程序的入口(譯註:其實c繫語言差不多都是這樣)。main函數所做的事情就是我們程序做的事情。當然了,main函數一般完成的工作是調用其它packge裏的函數來完成自己的工作,比如fmt.Println。</p>
|
||
|
<p>我們必鬚告訴編譯器如果要正確地執行這個源文件,需要用到哪些package,這就是import在這個文件裏扮演的角色。上述的hello world隻用到了一個其它的package,就是fmt。一般情況下,需要import的package不隻一個。</p>
|
||
|
<p>也正是因為go語言必鬚引入所有用到的package的原則,假如你沒有在代碼裏import需要用到的package,程序將無法編譯通過,當你import了沒有用到的package,也會無法編譯通過(譯註:爭議特性之一)。</p>
|
||
|
<p>import聲明必鬚跟在文件的package聲明之後。在import之後,則是各種方法、變量、常量、類型的聲明(分彆用關鍵字func, var, const, type來進行定義)。這些內容的聲明順序併沒有什麼規定,可以隨便(譯註:最好還是定一下規範)。我們例子裏的程序比較簡單,隻包含了一個函數。併且在該函數裏也隻調用了一個其它函數。為了節省空間,有些時候的例子我們會省略package和import聲明,但是讀者需要註意這些聲明是一定要包含在源文件裏的。</p>
|
||
|
<p>一個函數的聲明包含func這個關鍵字、函數名、參數列錶(我們例子裏的main函數是空)、返迴結果列錶(這裏的例子也是空)以及包含在大括號裏的函數體。關於函數的更詳細描述在第五章。</p>
|
||
|
<p>Go是一門不需要分號作為語句或者聲明結束的語言,除非要在一行中將多個語句、聲明隔開。然而在編譯時,編譯器會主動在一些特定的符號(譯註:比如行末是,一個標識符、一個整數、浮點數、虛數、字符或字符串文字、關鍵字break、continue、fallthrough或return中的一個、運算符和分隔符++、--、)、]或}中的一個) 後添加分號,所以在哪裏加分號閤適是取決於Go的代碼的。例如:在Go語言中的函數聲明和 { 必鬚在衕一行,而在x + y的錶達式中,在+號後換行可以,但是在+號前換行則會有問題。</p>
|
||
|
<p>Go語言在代碼格式上採取了很強硬的態度。gofmt工具會將你的代碼格式化為標準格式,併且go工具中的fmt子命令會自動對特定package下的所有.go源文件應用gofmt。如果不指定package,則默認對當前目彔下的源文件進行格式化。本書中的所有代碼已經是執行過gofmt後的標準格式代碼。你應該在自己的代碼上也執行這種格式化。規定一種標準的代碼格式可以規避掉無盡的無意義的撕逼。當然了,也可以避免由於代碼格式導緻的邏輯上的歧義。</p>
|
||
|
<p>很多文本編輯器都可以設置為保存文件時自動執行gofmt,所以你的源代碼應該總是會被格式化。這裏還有一個相關的工具,goimports,會自動地添加你代碼裏需要用到的import聲明以及需要移除的import聲明。這個工具併沒有包含在標準的分髮包中,然而你可以自行安裝:</p>
|
||
|
<pre><code>$ go get golang.org/x/tools/cmd/goimports
|
||
|
</code></pre><p>對於大多數用戶來說,下載、build package、運行測試用例、顯示go的文檔等等常用功能都是可以用go的工具來實現的。這些工具的詳細介紹我們會在10.7節中提到。</p>
|
||
|
|
||
|
|
||
|
</section>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<a href="../ch1/ch1.html" class="navigation navigation-prev " aria-label="Previous page: 入門"><i class="fa fa-angle-left"></i></a>
|
||
|
|
||
|
|
||
|
<a href="../ch1/ch1-02.html" class="navigation navigation-next " aria-label="Next page: 命令行參數"><i class="fa fa-angle-right"></i></a>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<script src="../gitbook/app.js"></script>
|
||
|
|
||
|
|
||
|
<script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
<script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
<script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
<script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
|
||
|
|
||
|
|
||
|
<script>
|
||
|
require(["gitbook"], function(gitbook) {
|
||
|
var config = {"highlight":{},"search":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
|
||
|
gitbook.start(config);
|
||
|
});
|
||
|
</script>
|
||
|
|
||
|
|
||
|
</body>
|
||
|
|
||
|
</html>
|