mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-11-24 23:29:01 +00:00
2265 lines
100 KiB
HTML
2265 lines
100 KiB
HTML
<!DOCTYPE HTML>
|
|
<html lang="zh-tw" >
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<title>變量 | Go语言圣经</title>
|
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
<meta name="description" content="">
|
|
<meta name="generator" content="GitBook 2.6.6">
|
|
|
|
|
|
<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-katex/katex.min.css">
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="next" href="../ch2/ch2-04.html" />
|
|
|
|
|
|
<link rel="prev" href="../ch2/ch2-02.html" />
|
|
|
|
|
|
|
|
</head>
|
|
<body>
|
|
|
|
|
|
<div class="book"
|
|
data-level="2.3"
|
|
data-chapter-title="變量"
|
|
data-filepath="ch2/ch2-03.md"
|
|
data-basepath=".."
|
|
data-revision="Sat Jan 02 2016 16:00:23 GMT+0800 (中国标准时间)"
|
|
data-innerlanguage="">
|
|
|
|
|
|
<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 " 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 active" 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>
|
|
|
|
Slice
|
|
</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>
|
|
|
|
Map
|
|
</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="CONTRIBUTORS.html">
|
|
|
|
|
|
<a href="../CONTRIBUTORS.html">
|
|
|
|
<i class="fa fa-check"></i>
|
|
|
|
<b>14.</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="23-變量">2.3. 變量</h2>
|
|
<p>var聲明語句可以創建一個特定類型的變量,然後給變量附加一個名字,併且設置變量的初始值。變量聲明的一般語法如下:</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">var</span> 變量名字 類型 = 表達式
|
|
</code></pre>
|
|
<p>其中“<em>類型</em>”或“<em>= 表達式</em>”兩個部分可以省略其中的一個。如果省略的是類型信息,那麽將根據初始化表達式來推導變量的類型信息。如果初始化表達式被省略,那麽將用零值初始化該變量。 數值類型變量對應的零值是0,布爾類型變量對應的零值是false,字符串類型對應的零值是空字符串,接口或引用類型(包括slice、map、chan和函數)變量對應的零值是nil。數組或結構體等聚合類型對應的零值是每個元素或字段都是對應該類型的零值。</p>
|
|
<p>零值初始化機製可以確保每個聲明的變量總是有一個良好定義的值,因此在Go語言中不存在未初始化的變量。這個特性可以簡化很多代碼,而且可以在沒有增加額外工作的前提下確保邊界條件下的合理行爲。例如:</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">var</span> s <span class="hljs-typename">string</span>
|
|
fmt.Println(s) <span class="hljs-comment">// ""</span>
|
|
</code></pre>
|
|
<p>這段代碼將打印一個空字符串,而不是導致錯誤或産生不可預知的行爲。Go語言程序員應該讓一些聚合類型的零值也具有意義,這樣可以保證不管任何類型的變量總是有一個合理有效的零值狀態。</p>
|
|
<p>也可以在一個聲明語句中同時聲明一組變量,或用一組初始化表達式聲明併初始化一組變量。如果省略每個變量的類型,將可以聲明多個類型不同的變量(類型由初始化表達式推導):</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">var</span> i, j, k <span class="hljs-typename">int</span> <span class="hljs-comment">// int, int, int</span>
|
|
<span class="hljs-keyword">var</span> b, f, s = <span class="hljs-constant">true</span>, <span class="hljs-number">2.3</span>, <span class="hljs-string">"four"</span> <span class="hljs-comment">// bool, float64, string</span>
|
|
</code></pre>
|
|
<p>初始化表達式可以是字面量或任意的表達式。在包級别聲明的變量會在main入口函數執行前完成初始化(§2.6.2),局部變量將在聲明語句被執行到的時候完成初始化。</p>
|
|
<p>一組變量也可以通過調用一個函數,由函數返迴的多個返迴值初始化:</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">var</span> f, err = os.Open(name) <span class="hljs-comment">// os.Open returns a file and an error</span>
|
|
</code></pre>
|
|
<h3 id="231-簡短變量聲明">2.3.1. 簡短變量聲明</h3>
|
|
<p>在函數內部,有一種稱爲簡短變量聲明語句的形式可用於聲明和初始化局部變量。它以“名字 := 表達式”形式聲明變量,變量的類型根據表達式來自動推導。下面是lissajous函數中的三個簡短變量聲明語句(§1.4):</p>
|
|
<pre><code class="lang-Go">anim := gif.GIF{LoopCount: nframes}
|
|
freq := rand.Float64() * <span class="hljs-number">3.0</span>
|
|
t := <span class="hljs-number">0.0</span>
|
|
</code></pre>
|
|
<p>因爲簡潔和靈活的特點,簡短變量聲明被廣泛用於大部分的局部變量的聲明和初始化。var形式的聲明語句往往是用於需要顯式指定變量類型地方,或者因爲變量稍後會被重新賦值而初始值無關緊要的地方。</p>
|
|
<pre><code class="lang-Go">i := <span class="hljs-number">100</span> <span class="hljs-comment">// an int</span>
|
|
<span class="hljs-keyword">var</span> boiling <span class="hljs-typename">float64</span> = <span class="hljs-number">100</span> <span class="hljs-comment">// a float64</span>
|
|
<span class="hljs-keyword">var</span> names []<span class="hljs-typename">string</span>
|
|
<span class="hljs-keyword">var</span> err error
|
|
<span class="hljs-keyword">var</span> p Point
|
|
</code></pre>
|
|
<p>和var形式聲明變語句一樣,簡短變量聲明語句也可以用來聲明和初始化一組變量:</p>
|
|
<pre><code class="lang-Go">i, j := <span class="hljs-number">0</span>, <span class="hljs-number">1</span>
|
|
</code></pre>
|
|
<p>但是這種同時聲明多個變量的方式應該限製隻在可以提高代碼可讀性的地方使用,比如for語句的循環的初始化語句部分。</p>
|
|
<p>請記住“:=”是一個變量聲明語句,而“=‘是一個變量賦值操作。也不要混淆多個變量的聲明和元組的多重賦值(§2.4.1),後者是將右邊各個的表達式值賦值給左邊對應位置的各個變量:</p>
|
|
<pre><code class="lang-Go">i, j = j, i <span class="hljs-comment">// 交換 i 和 j 的值</span>
|
|
</code></pre>
|
|
<p>和普通var形式的變量聲明語句一樣,簡短變量聲明語句也可以用函數的返迴值來聲明和初始化變量,像下面的os.Open函數調用將返迴兩個值:</p>
|
|
<pre><code class="lang-Go">f, err := os.Open(name)
|
|
<span class="hljs-keyword">if</span> err != <span class="hljs-constant">nil</span> {
|
|
<span class="hljs-keyword">return</span> err
|
|
}
|
|
<span class="hljs-comment">// ...use f...</span>
|
|
f.Close()
|
|
</code></pre>
|
|
<p>這里有一個比較微妙的地方:簡短變量聲明左邊的變量可能併不是全部都是剛剛聲明的。如果有一些已經在相同的詞法域聲明過了(§2.7),那麽簡短變量聲明語句對這些已經聲明過的變量就隻有賦值行爲了。</p>
|
|
<p>在下面的代碼中,第一個語句聲明了in和err兩個變量。在第二個語句隻聲明了out一個變量,然後對已經聲明的err進行了賦值操作。</p>
|
|
<pre><code class="lang-Go">in, err := os.Open(infile)
|
|
<span class="hljs-comment">// ...</span>
|
|
out, err := os.Create(outfile)
|
|
</code></pre>
|
|
<p>簡短變量聲明語句中必鬚至少要聲明一個新的變量,下面的代碼將不能編譯通過:</p>
|
|
<pre><code class="lang-Go">f, err := os.Open(infile)
|
|
<span class="hljs-comment">// ...</span>
|
|
f, err := os.Create(outfile) <span class="hljs-comment">// compile error: no new variables</span>
|
|
</code></pre>
|
|
<p>解決的方法是第二個簡短變量聲明語句改用普通的多重賦值語言。</p>
|
|
<p>簡短變量聲明語句隻有對已經在同級詞法域聲明過的變量才和賦值操作語句等價,如果變量是在外部詞法域聲明的,那麽簡短變量聲明語句將會在當前詞法域重新聲明一個新的變量。我們在本章後面將會看到類似的例子。</p>
|
|
<h3 id="232-指針">2.3.2. 指針</h3>
|
|
<p>一個變量對應一個保存了變量對應類型值的內存空間。普通變量在聲明語句創建時被綁定到一個變量名,比如叫x的變量,但是還有很多變量始終以表達式方式引入,例如x[i]或x.f變量。所有這些表達式一般都是讀取一個變量的值,除非它們是出現在賦值語句的左邊,這種時候是給對應變量賦予一個新的值。</p>
|
|
<p>一個指針的值是另一個變量的地址。一個指針對應變量在內存中的存儲位置。併不是每一個值都會有一個內存地址,但是對於每一個變量必然有對應的內存地址。通過指針,我們可以直接讀或更新對應變量的值,而不需要知道該變量的名字(如果變量有名字的話)。</p>
|
|
<p>如果用“var x int”聲明語句聲明一個x變量,那麽&x表達式(取x變量的內存地址)將産生一個指向該整數變量的指針,指針對應的數據類型是<code>*int</code>,指針被稱之爲“指向int類型的指針”。如果指針名字爲p,那麽可以説“p指針指向變量x”,或者説“p指針保存了x變量的內存地址”。同時<code>*p</code>表達式對應p指針指向的變量的值。一般<code>*p</code>表達式讀取指針指向的變量的值,這里爲int類型的值,同時因爲<code>*p</code>對應一個變量,所以該表達式也可以出現在賦值語句的左邊,表示更新指針所指向的變量的值。</p>
|
|
<pre><code class="lang-Go">x := <span class="hljs-number">1</span>
|
|
p := &x <span class="hljs-comment">// p, of type *int, points to x</span>
|
|
fmt.Println(*p) <span class="hljs-comment">// "1"</span>
|
|
*p = <span class="hljs-number">2</span> <span class="hljs-comment">// equivalent to x = 2</span>
|
|
fmt.Println(x) <span class="hljs-comment">// "2"</span>
|
|
</code></pre>
|
|
<p>對於聚合類型每個成員——比如結構體的每個字段、或者是數組的每個元素——也都是對應一個變量,因此可以被取地址。</p>
|
|
<p>變量有時候被稱爲可尋址的值。卽使變量由表達式臨時生成,那麽表達式也必鬚能接受<code>&</code>取地址操作。</p>
|
|
<p>任何類型的指針的零值都是nil。如果<code>p != nil</code>測試爲眞,那麽p是指向某個有效變量。指針之間也是可以進行相等測試的,隻有當它們指向同一個變量或全部是nil時才相等。</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">var</span> x, y <span class="hljs-typename">int</span>
|
|
fmt.Println(&x == &x, &x == &y, &x == <span class="hljs-constant">nil</span>) <span class="hljs-comment">// "true false false"</span>
|
|
</code></pre>
|
|
<p>在Go語言中,返迴函數中局部變量的地址也是安全的。例如下面的代碼,調用f函數時創建局部變量v,在局部變量地址被返迴之後依然有效,因爲指針p依然引用這個變量。</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">var</span> p = f()
|
|
|
|
<span class="hljs-keyword">func</span> f() *<span class="hljs-typename">int</span> {
|
|
v := <span class="hljs-number">1</span>
|
|
<span class="hljs-keyword">return</span> &v
|
|
}
|
|
</code></pre>
|
|
<p>每次調用f函數都將返迴不同的結果:</p>
|
|
<pre><code class="lang-Go">fmt.Println(f() == f()) <span class="hljs-comment">// "false"</span>
|
|
</code></pre>
|
|
<p>因爲指針包含了一個變量的地址,因此如果將指針作爲參數調用函數,那將可以在函數中通過該指針來更新變量的值。例如下面這個例子就是通過指針來更新變量的值,然後返迴更新後的值,可用在一個表達式中(譯註:這是對C語言中<code>++v</code>操作的模擬,這里隻是爲了説明指針的用法,incr函數模擬的做法併不推薦):</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">func</span> incr(p *<span class="hljs-typename">int</span>) <span class="hljs-typename">int</span> {
|
|
*p++ <span class="hljs-comment">// 非常重要:隻是增加p指向的變量的值,併不改變p指針!!!</span>
|
|
<span class="hljs-keyword">return</span> *p
|
|
}
|
|
|
|
v := <span class="hljs-number">1</span>
|
|
incr(&v) <span class="hljs-comment">// side effect: v is now 2</span>
|
|
fmt.Println(incr(&v)) <span class="hljs-comment">// "3" (and v is 3)</span>
|
|
</code></pre>
|
|
<p>每次我們對一個變量取地址,或者複製指針,我們都是爲原變量創建了新的别名。例如,<code>*p</code>就是是 變量v的别名。指針特别有價值的地方在於我們可以不用名字而訪問一個變量,但是這是一把雙刃劍:要找到一個變量的所有訪問者併不容易,我們必鬚知道變量全部的别名(譯註:這是Go語言的垃圾迴收器所做的工作)。不僅僅是指針會創建别名,很多其他引用類型也會創建别名,例如slice、map和chan,甚至結構體、數組和接口都會創建所引用變量的别名。</p>
|
|
<p>指針是實現標準庫中flag包的關鍵技術,它使用命令行參數來設置對應變量的值,而這些對應命令行標誌參數的變量可能會零散分布在整個程序中。爲了説明這一點,在早些的echo版本中,就包含了兩個可選的命令行參數:<code>-n</code>用於忽略行尾的換行符,<code>-s sep</code>用於指定分隔字符(默認是空格)。下面這是第四個版本,對應包路徑爲gopl.io/ch2/echo4。</p>
|
|
<pre><code class="lang-Go">gopl.io/ch2/echo4
|
|
<span class="hljs-comment">// Echo4 prints its command-line arguments.</span>
|
|
<span class="hljs-keyword">package</span> main
|
|
|
|
<span class="hljs-keyword">import</span> (
|
|
<span class="hljs-string">"flag"</span>
|
|
<span class="hljs-string">"fmt"</span>
|
|
<span class="hljs-string">"strings"</span>
|
|
)
|
|
|
|
<span class="hljs-keyword">var</span> n = flag.Bool(<span class="hljs-string">"n"</span>, <span class="hljs-constant">false</span>, <span class="hljs-string">"omit trailing newline"</span>)
|
|
<span class="hljs-keyword">var</span> sep = flag.String(<span class="hljs-string">"s"</span>, <span class="hljs-string">" "</span>, <span class="hljs-string">"separator"</span>)
|
|
|
|
<span class="hljs-keyword">func</span> main() {
|
|
flag.Parse()
|
|
fmt.Print(strings.Join(flag.Args(), *sep))
|
|
<span class="hljs-keyword">if</span> !*n {
|
|
fmt.Println()
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p>調用flag.Bool函數會創建一個新的對應布爾型標誌參數的變量。它有三個屬性:第一個是的命令行標誌參數的名字“n”,然後是該標誌參數的默認值(這里是false),最後是該標誌參數對應的描述信息。如果用戶在命令行輸入了一個無效的標誌參數,或者輸入<code>-h</code>或<code>-help</code>參數,那麽將打印所有標誌參數的名字、默認值和描述信息。類似的,調用flag.String函數將於創建一個對應字符串類型的標誌參數變量,同樣包含命令行標誌參數對應的參數名、默認值、和描述信息。程序中的<code>sep</code>和<code>n</code>變量分别是指向對應命令行標誌參數變量的指針,因此必鬚用<code>*sep</code>和<code>*n</code>形式的指針語法間接引用它們。</p>
|
|
<p>當程序運行時,必鬚在使用標誌參數對應的變量之前調用先flag.Parse函數,用於更新每個標誌參數對應變量的值(之前是默認值)。對於非標誌參數的普通命令行參數可以通過調用flag.Args()函數來訪問,返迴值對應對應一個字符串類型的slice。如果在flag.Parse函數解析命令行參數時遇到錯誤,默認將打印相關的提示信息,然後調用os.Exit(2)終止程序。</p>
|
|
<p>讓我們運行一些echo測試用例:</p>
|
|
<pre><code>$ go build gopl.io/ch2/echo4
|
|
$ ./echo4 a bc def
|
|
a bc def
|
|
$ ./echo4 -s / a bc def
|
|
a/bc/def
|
|
$ ./echo4 -n a bc def
|
|
a bc def$
|
|
$ ./echo4 -help
|
|
Usage of ./echo4:
|
|
-n omit trailing newline
|
|
-s string
|
|
separator (default " ")
|
|
</code></pre><h3 id="233-new函數">2.3.3. new函數</h3>
|
|
<p>另一個創建變量的方法是調用用內建的new函數。表達式new(T)將創建一個T類型的匿名變量,初始化爲T類型的零值,然後返迴變量地址,返迴的指針類型爲<code>*T</code>。</p>
|
|
<pre><code class="lang-Go">p := <span class="hljs-built_in">new</span>(<span class="hljs-typename">int</span>) <span class="hljs-comment">// p, *int 類型, 指向匿名的 int 變量</span>
|
|
fmt.Println(*p) <span class="hljs-comment">// "0"</span>
|
|
*p = <span class="hljs-number">2</span> <span class="hljs-comment">// 設置 int 匿名變量的值爲 2</span>
|
|
fmt.Println(*p) <span class="hljs-comment">// "2"</span>
|
|
</code></pre>
|
|
<p>用new創建變量和普通變量聲明語句方式創建變量沒有什麽區别,除了不需要聲明一個臨時變量的名字外,我們還可以在表達式中使用new(T)。換言之,new函數類似是一種語法醣,而不是一個新的基礎概念。</p>
|
|
<p>下面的兩個newInt函數有着相同的行爲:</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">func</span> newInt() *<span class="hljs-typename">int</span> { <span class="hljs-keyword">func</span> newInt() *<span class="hljs-typename">int</span> {
|
|
<span class="hljs-keyword">return</span> <span class="hljs-built_in">new</span>(<span class="hljs-typename">int</span>) <span class="hljs-keyword">var</span> dummy <span class="hljs-typename">int</span>
|
|
} <span class="hljs-keyword">return</span> &dummy
|
|
}
|
|
</code></pre>
|
|
<p>每次調用new函數都是返迴一個新的變量的地址,因此下面兩個地址是不同的:</p>
|
|
<pre><code class="lang-Go">p := <span class="hljs-built_in">new</span>(<span class="hljs-typename">int</span>)
|
|
q := <span class="hljs-built_in">new</span>(<span class="hljs-typename">int</span>)
|
|
fmt.Println(p == q) <span class="hljs-comment">// "false"</span>
|
|
</code></pre>
|
|
<p>當然也可能有特殊情況:如果兩個類型都是空的,也就是説類型的大小是0,例如<code>struct{}</code>和 <code>[0]int</code>, 有可能有相同的地址(依賴具體的語言實現)(譯註:請謹慎使用大小爲0的類型,因爲如果類型的大小位0好話,可能導致Go語言的自動垃圾迴收器有不同的行爲,具體請査看<code>runtime.SetFinalizer</code>函數相關文檔)。</p>
|
|
<p>new函數使用常見相對比較少,因爲對應結構體來説,可以直接用字面量語法創建新變量的方法會更靈活(§4.4.1)。</p>
|
|
<p>由於new隻是一個預定義的函數,它併不是一個關鍵字,因此我們可以將new名字重新定義爲别的類型。例如下面的例子:</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">func</span> delta(old, <span class="hljs-built_in">new</span> <span class="hljs-typename">int</span>) <span class="hljs-typename">int</span> { <span class="hljs-keyword">return</span> <span class="hljs-built_in">new</span> - old }
|
|
</code></pre>
|
|
<p>由於new被定義爲int類型的變量名,因此在delta函數內部是無法使用內置的new函數的。</p>
|
|
<h3 id="234-變量的生命週期">2.3.4. 變量的生命週期</h3>
|
|
<p>變量的生命週期指的是在程序運行期間變量有效存在的時間間隔。對於在包一級聲明的變量來説,它們的生命週期和整個程序的運行週期是一致的。而相比之下,在局部變量的聲明週期則是動態的:從每次創建一個新變量的聲明語句開始,直到該變量不再被引用爲止,然後變量的存儲空間可能被迴收。函數的參數變量和返迴值變量都是局部變量。它們在函數每次被調用的時候創建。</p>
|
|
<p>例如,下面是從1.4節的Lissajous程序摘録的代碼片段:</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">for</span> t := <span class="hljs-number">0.0</span>; t < cycles*<span class="hljs-number">2</span>*math.Pi; t += res {
|
|
x := math.Sin(t)
|
|
y := math.Sin(t*freq + phase)
|
|
img.SetColorIndex(size+<span class="hljs-typename">int</span>(x*size+<span class="hljs-number">0.5</span>), size+<span class="hljs-typename">int</span>(y*size+<span class="hljs-number">0.5</span>),
|
|
blackIndex)
|
|
}
|
|
</code></pre>
|
|
<p>譯註:函數的有右小括弧也可以另起一行縮進,同時爲了防止編譯器在行尾自動插入分號而導致的編譯錯誤,可以在末尾的參數變量後面顯式插入逗號。像下面這樣:</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">for</span> t := <span class="hljs-number">0.0</span>; t < cycles*<span class="hljs-number">2</span>*math.Pi; t += res {
|
|
x := math.Sin(t)
|
|
y := math.Sin(t*freq + phase)
|
|
img.SetColorIndex(
|
|
size+<span class="hljs-typename">int</span>(x*size+<span class="hljs-number">0.5</span>), size+<span class="hljs-typename">int</span>(y*size+<span class="hljs-number">0.5</span>),
|
|
blackIndex, <span class="hljs-comment">// 最後插入的逗號不會導致編譯錯誤,這是Go編譯器的一個特性</span>
|
|
) <span class="hljs-comment">// 小括弧另起一行縮進,和大括弧的風格保存一致</span>
|
|
}
|
|
</code></pre>
|
|
<p>在每次循環的開始會創建臨時變量t,然後在每次循環迭代中創建臨時變量x和y。</p>
|
|
<p>那麽垃Go語言的自動圾收集器是如何知道一個變量是何時可以被迴收的呢?這里我們可以避開完整的技術細節,基本的實現思路是,從每個包級的變量和每個當前運行函數的每一個局部變量開始,通過指針或引用的訪問路徑遍歷,是否可以找到該變量。如果不存在這樣的訪問路徑,那麽説明該變量是不可達的,也就是説它是否存在併不會影響程序後續的計算結果。</p>
|
|
<p>因爲一個變量的有效週期隻取決於是否可達,因此一個循環迭代內部的局部變量的生命週期可能超出其局部作用域。同時,局部變量可能在函數返迴之後依然存在。</p>
|
|
<p>編譯器會自動選擇在棧上還是在堆上分配局部變量的存儲空間,但可能令人驚訝的是,這個選擇併不是由用var還是new聲明變量的方式決定的。</p>
|
|
<pre><code class="lang-Go"><span class="hljs-keyword">var</span> global *<span class="hljs-typename">int</span>
|
|
|
|
<span class="hljs-keyword">func</span> f() { <span class="hljs-keyword">func</span> g() {
|
|
<span class="hljs-keyword">var</span> x <span class="hljs-typename">int</span> y := <span class="hljs-built_in">new</span>(<span class="hljs-typename">int</span>)
|
|
x = <span class="hljs-number">1</span> *y = <span class="hljs-number">1</span>
|
|
global = &x }
|
|
}
|
|
</code></pre>
|
|
<p>這里的x變量必鬚在堆上分配,因爲它在函數退出後依然可以通過包一級的global變量找到,雖然它是在函數內部定義的;用Go語言的術語説,這個x局部變量從函數f中逃逸了。相反,當g函數返迴時,變量<code>*y</code>將是不可達的,也就是説可以馬上被迴收的。因此,<code>*y</code>併沒有從函數g中逃逸,編譯器可以選擇在棧上分配<code>*y</code>的存儲空間(譯註:也可以選擇在堆上分配,然後由Go語言的GC迴收這個變量的內存空間),雖然這里用的是new方式。其實在任何時候,你併不需爲了編寫正確的代碼而要考慮變量的逃逸行爲,要記住的是,逃逸的變量需要額外分配內存,同時對性能的優化可能會産生細微的影響。</p>
|
|
<p>Go語言的自動垃圾收集器對編寫正確的代碼是一個鉅大的幫助,但也併不是説你完全不用考慮內存了。你雖然不需要顯式地分配和釋放內存,但是要編寫高效的程序你依然需要了解變量的生命週期。例如,如果將指向短生命週期對象的指針保存到具有長生命週期的對象中,特别是保存到全局變量時,會阻止對短生命週期對象的垃圾迴收(從而可能影響程序的性能)。</p>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<a href="../ch2/ch2-02.html" class="navigation navigation-prev " aria-label="Previous page: 聲明"><i class="fa fa-angle-left"></i></a>
|
|
|
|
|
|
<a href="../ch2/ch2-04.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-sharing/buttons.js"></script>
|
|
|
|
|
|
|
|
<script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
|
|
|
|
|
|
<script>
|
|
require(["gitbook"], function(gitbook) {
|
|
var config = {"katex":{},"highlight":{},"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>
|