-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
272 lines (237 loc) · 34.7 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>DreamLand</title>
<link href="/atom.xml" rel="self"/>
<link href="https://chuckniu.github.io/"/>
<updated>2018-07-08T17:47:49.370Z</updated>
<id>https://chuckniu.github.io/</id>
<author>
<name>Niu</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>Fabric 简明使用手册</title>
<link href="https://chuckniu.github.io/2017/06/08/Fabric-%E7%AE%80%E6%98%8E%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C/"/>
<id>https://chuckniu.github.io/2017/06/08/Fabric-简明使用手册/</id>
<published>2017-06-08T15:49:09.000Z</published>
<updated>2018-07-08T17:47:49.370Z</updated>
<content type="html"><![CDATA[<h3 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a><strong>Preface</strong></h3><blockquote>
<p>“The Times 03/Jan/2009 Chancellor on brink of second bailout for banks(2009年1月3日,财政大臣正处于实施第二轮银行紧急援助的边缘)。”</p>
</blockquote>
<p>比特币,C++ 开发。 核心宗旨:去中心化,开放性,自洽性,不可篡改,匿名性</p>
<blockquote>
<p>官方网站:<a href="https://bitcoin.org/" target="_blank" rel="external">https://bitcoin.org/</a></p>
<p>源码库:<a href="https://github.com/bitcoin" target="_blank" rel="external">https://github.com/bitcoin</a></p>
<p>创世区块:<a href="https://btc.com/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" target="_blank" rel="external">000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f</a></p>
</blockquote>
<p>以太坊,开发管理分布式应用的平台,主攻方向 “智能合约”,并为其定制了一种编程语言Solidity。以太坊的核心是以太坊虚拟机(EVM),允许用户按照自己的意愿创建操作。 以太坊给出了Go、Java、Python 等多语言的实现。</p>
<blockquote>
<p>官方网站:<a href="https://ethereum.org/" title="https://ethereum.org/" target="_blank" rel="external">https://ethereum.org/</a></p>
<p>源码库:<a href="https://github.com/ethereum" title="https://github.com/ethereum" target="_blank" rel="external">https://github.com/ethereum</a></p>
<p>The DAO</p>
<p>EVM( 图灵完备的智能合约虚拟机 )</p>
<p>DAPP</p>
<p><a href="https://ethereumclassic.org/" target="_blank" rel="external">Ethereum Classic</a></p>
</blockquote>
<p>HyperLeger,由 Linux 基金会主导。 该项目试图为新一代的事务应用创建一种开放的分布式账本标准,支持许可式区块链。</p>
<blockquote>
<p>官方网站:<a href="https://www.hyperledger.org/" title="https://www.hyperledger.org/" target="_blank" rel="external">https://www.hyperledger.org/</a></p>
<p>源码库:<a href="https://www.hyperledger.org/" title="https://www.hyperledger.org/" target="_blank" rel="external">https://github.com/hyperledger</a></p>
<p>PBFT</p>
</blockquote>
<h3 id="Concepts"><a href="#Concepts" class="headerlink" title="Concepts"></a><strong>Concepts</strong></h3><blockquote>
<p>区块:一个区块是一个数据包,其中包含零个或多个交易,前块(“父块”)的散列值,以及可选的其它数据。</p>
<p>创世区块:创世区块指区块链上的第一个区块,用来初始化相应的加密货币。</p>
<p>挖矿:挖矿是反复总计交易,构建区块,并尝试不同的随机数,直到找到一个随机数可以符合工作证明的条件的过程。</p>
<p>分叉:指向同一个父块的2个区块被同时生成的情况,某些部分的矿工看到其中一个区块,其他的矿工则看到另外一个区块。这导致2种区块链同时增长。通常来说,随着在一个链上的矿工得到幸运并且那条链增长的话,所有的矿工都会转到那条链上,数学上分几乎会在4个区块内完结自己。</p>
<p>双重花费:是一个故意的分叉,当一个有着大量挖矿能力的用户发送一个交易来购买产品,在收到产品后又做出另外一个交易把相同量的币发给自己。如果攻击者有超过50%的挖矿能力的话,双重花费最终可以在保证在任何区块深度上成功。低于50%的话,有部分可能性成功。但是它经常在深度2-5上有唯一显著的可能。因此在大多数的加密货币交易所还有金融服务在接受支付之前需要等待6个区块被生产出来(也叫“6次确认”)。</p>
<p>共识机制:区块链中各节点建立信任,对某个提案(Proposal)达成一致的算法。</p>
<p>工作量证明(Proof-of-Work):一种共识机制,该机制是一方(通常称为证明人)出示计算结果,这个结果众所周知是很难计算的但却很容易验证的。通过验证这个结果,任何人都能够确认证明人执行了一定量的计算工作量来产生这个结果。</p>
<p>股权证明机制(Proof of Stake):没有挖矿过程,在创世区块内写明了股权分配比例,之后通过转让、交易的方式(通常就是IPO),逐渐分散到用户手里,并通过“利息”的方式新增货币,实现对节点的奖励。</p>
<p>授权股权证明机制(Delegated Proof of Stake):由被社区选举的可信帐户(受托人,得票数排行前101位)来创建区块。</p>
<p>拜占庭将军问题( Byzantine failures ): Leslie Lamport 1982 年提出用来解释一致性问题的一个虚构模型。在将军总数大于3m ,背叛者为m 或者更少时,忠诚的将军可以达成命令上的一致。</p>
<p>零知识证明: 证明者和验证者之间进行交互,证明者能够在不向验证者提供任何有用的信息的情况下,使验证者相信某个论断是正确的。</p>
<p>图灵完备 (Turing-complete):指一个机器或装置能用来模拟图灵机(现代通用计算机的雏形)的功能,图灵完备的机器在可计算性上等价。</p>
</blockquote>
<h3 id="Deploy-Fabric-v0-6"><a href="#Deploy-Fabric-v0-6" class="headerlink" title="Deploy Fabric v0.6"></a><strong>Deploy Fabric v0.6</strong></h3><h3 id="1-Overview"><a href="#1-Overview" class="headerlink" title="1. Overview"></a>1. Overview</h3><p><img src="http://mmbiz.qpic.cn/mmbiz_png/Aiammx86AibQSTAicIczzLA8cAaVFyiax5wzG3B41MpgmAibCf8jN6ew8xnXayClcjrlXCc33oUJDCGBg2tBJoYhmPA/640" alt="overview"></p>
<h3 id="2-Prerequisites"><a href="#2-Prerequisites" class="headerlink" title="2. Prerequisites"></a>2. Prerequisites</h3><ul>
<li>Ubuntu/Debian or RHEL/CentOS</li>
<li>Docker</li>
<li>docker-compose</li>
<li>…</li>
</ul>
<h3 id="3-Steps"><a href="#3-Steps" class="headerlink" title="3. Steps"></a>3. Steps</h3><h4 id="1-Install-Docker"><a href="#1-Install-Docker" class="headerlink" title="1. Install Docker"></a>1. Install Docker</h4><font color="red">Warning: CentOS6 最高支持Docker版本1.7.1,若需更高版本请升级到CentOS7.</font>
<h5 id="另:推荐升级系统内核"><a href="#另:推荐升级系统内核" class="headerlink" title=" 另:推荐升级系统内核 "></a><font color="red"> 另:推荐升级系统内核 </font> <br><br></h5><h5 id="CentOS-6-x-升级CentOS内核"><a href="#CentOS-6-x-升级CentOS内核" class="headerlink" title="CentOS 6.x 升级CentOS内核:"></a><strong>CentOS 6.x 升级CentOS内核:</strong></h5><p>现有机器上CENTOS版本为CentOS release 6.6 (Final),内核版本2.6.32-504.el6.x86_64</p>
<p><strong>方式1 ( 无aufs模块 ):</strong></p>
<p><code>rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org</code><br><code>rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm</code><br><code>yum --enablerepo=elrepo-kernel install kernel-lt -y</code><br><code>vi /etc/grub.conf</code> —将default设置为0<br><code>reboot</code><br><code>uname -r</code> ==>版本为3.10.105-1.el6.elrepo.x86_64</p>
<p><strong>方式2 ( Install aufs ):</strong></p>
<p><code>cd /etc/yum.repos.d</code><br><code>wget http://www.hop5.in/yum/el6/hop5.repo</code><br><code>yum install kernel-ml-aufs kernel-ml-aufs-devel</code><br><code>vi /etc/grub.conf</code> —将default设置为0<br><code>reboot</code><br><code>uname -r</code> ==>版本为3.10.5-3.el6.x86_64</p>
<h5 id="CentOS-7-x-升级CentOS内核:"><a href="#CentOS-7-x-升级CentOS内核:" class="headerlink" title="CentOS 7.x 升级CentOS内核:"></a><strong>CentOS 7.x 升级CentOS内核:</strong></h5><p>现有版本为 3.10.0-514.el7.x86_64</p>
<p><code>rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org</code><br><code>rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm</code><br><code>yum --enablerepo=elrepo-kernel install kernel-lt -y</code><br><code>vi /boot/grub2/grub.cfg</code><br><code>grub2-set-default "centos_version"</code><br><code>grub2-editenv list</code><br><code>reboot</code><br><code>uname -r</code>==>版本为4.4.52-1.el7.elrepo.x86_64</p>
<p><strong>安装Docker</strong></p>
<p>官方脚本:<code>curl -fsSL https://get.docker.com/ | sh</code><br>阿里云脚本:<code>curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh -</code></p>
<p><strong>建立并加入Docker用户组</strong></p>
<p><code>sudo groupadd docker</code><br><code>sudo usermod -aG docker $USER</code></p>
<p><strong>启动Docker</strong></p>
<p>=> CentOS 6:<br><code>sudo service docker start</code></p>
<p>=> CentOS 7:<br><code>sudo systemctl enable docker sudo systemctl start docker</code></p>
<p><strong>验证Docker</strong></p>
<p><code>docker run hello-world</code></p>
<p><strong>安装docker-compose</strong></p>
<p><code>curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose</code><br><code>chmod +x /usr/local/bin/docker-compose</code></p>
<p><strong>基本Docker命令</strong></p>
<blockquote>
<p>显示docker基本信息:<code>docker info</code><br>下载镜像:<code>docker pull image_name</code><br>列出镜像列表:<code>docker images</code><br>删除镜像:<code>docker rmi image_name</code><br>开启容器:<code>docker run image_name</code><br>进入容器:<code>docker exec -it container_name /bin/bash</code><br>查看容器:<code>docker ps -a</code><br>修改容器:<code>docker commit container_id new_image_name</code><br>删除容器:<code>docker rm name/id</code><br>查看logs:<code>docker logs Name/ID</code><br>启动停止容器:<code>docker start/stop/restart Name/ID</code><br>强制删除所有容器:<code>docker rm -f $(docker ps -aq)</code><br>强制删除全部镜像:<code>docker rmi -f $(docker images -q)</code><br>从容器里面拷贝文件:<code>docker cp Name:/container_path local_path</code><br>保存镜像:<code>docker save image_name -o file_path</code><br>加载镜像:<code>docker loan -i file_path</code><br>构建镜像:<code>docker build -t image_name Dockerfile_path</code></p>
</blockquote>
<h4 id="2-获取Fabric镜像"><a href="#2-获取Fabric镜像" class="headerlink" title="2. 获取Fabric镜像"></a>2. 获取Fabric镜像</h4><p><code>mkdir -p $HOME/hyperledger/docker-compose</code><br><code>cd $HOME/hyperledger/docker-compose</code><br><code>curl https://raw.githubusercontent.com/hyperledger/fabric/v0.6/examples/docker-compose/four-peer-ca.yaml -o four-peer-ca.yaml 2>/dev/null</code><br><code>docker-compose -f xxx.yaml up -d</code> —单机部署<br><code>firewall-cmd --zone=public --add-port=2377/tcp --permanent && \</code><br><code>firewall-cmd --zone=public --add-port=7946/tcp --permanent && \</code><br><code>firewall-cmd --zone=public --add-port=7946/udp --permanent && \</code><br><code>firewall-cmd --zone=public --add-port=4789/tcp --permanent && \</code><br><code>firewall-cmd --zone=public --add-port=4789/udp --permanent && \</code><br><code>firewall-cmd --reload</code><br><code>docker swarm init --advertise-addr <MANAGER-IP></code>—初始化docker集群<br><code>docker swarm join ...</code>—加入集群<br><code>vim docker-stack.yml</code> —修改启动文件适用于多机部署<br><code>docker stack deploy --compose-file docker-stack.yml app_name</code><br><code>docker stack services app_name</code><br><code>docker stack rm app_name</code> —删除app</p>
<h3 id="Deploy-Fabric-v1-0"><a href="#Deploy-Fabric-v1-0" class="headerlink" title="Deploy Fabric v1.0"></a><strong>Deploy Fabric v1.0</strong></h3><h3 id="1-概览"><a href="#1-概览" class="headerlink" title="1. 概览"></a>1. 概览</h3><center> <img src="http://mmbiz.qpic.cn/mmbiz_png/Aiammx86AibQQC5In97lvde9Coq9WbJmfwejDz1wUrFqlnXO9ZicMs5Ok3ckTbCsmZYZZrXic1bjuOficZtypRGichBw/640" alt="overview"> </center>
<h3 id="2-构建-Fabric-服务"><a href="#2-构建-Fabric-服务" class="headerlink" title="2. 构建 Fabric 服务"></a>2. 构建 Fabric 服务</h3><p> 配置docker:<br><code>vim /lib/systemd/system/docker.service</code> 修改成:<br><code>ExecStart=/usr/bin/dockerd $DOCKER_OPTS -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock \</code><br><code>--api-cors-header='*' --default-ulimit=nofile=8192:16384 --default-ulimit=nproc=8192:16384</code><br><code>sudo systemctl daemon-reload</code><br><code>sudo systemctl restart docker.service</code></p>
<p><code>docker -H Worker_Node_IP:2375 version</code> — 验证</p>
<p><code>sysctl -w net.ipv4.ip_forward=1</code></p>
<p><code>firewall-cmd --zone=public --add-port=2375/tcp --permanent</code> — 打开相应的端口</p>
<p><code>firewall-cmd --list-ports</code> — 查看开放端口</p>
<p><code>mkdir -p <my_dev_workspace>/hackfest</code><br><code>cd <my_dev_workspace>/hackfest</code></p>
<p><code>curl -L https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sfhackfest/sfhackfest.tar.gz \</code><br><code>-o sfhackfest.tar.gz 2> /dev/null; tar -xvf sfhackfest.tar.gz</code></p>
<p><code>docker-compose -f docker-compose-gettingstarted.yml up -d</code></p>
<p><code>docker inspect orderer | grep IPAddress</code></p>
<p><code>docker exec -it cli bash</code><br><br><code>more results.txt</code> — 查看节点加入链情况</p>
<p><code>vim compose.yml</code> — 修改文件适用于多机部署</p>
<h3 id="3-测试-Fabric-环境"><a href="#3-测试-Fabric-环境" class="headerlink" title="3. 测试 Fabric 环境"></a>3. 测试 Fabric 环境</h3><p><code>curl -OOOOOO https://raw.githubusercontent.com/hyperledger/fabric-sdk-node/v1.0-alpha/examples/balance-transfer/{config.json,deploy.js,helper.js,invoke.js,query.js,package.json}</code></p>
<p><code>npm install</code></p>
<p><code>GOPATH=$PWD node deploy.js</code> — 部署chaincode及初始化worldstate</p>
<p><code>node invoke.js</code> — 发送操作请求</p>
<p><code>node query.js</code> — 查询账户状态</p>
<h3 id="Marbles-A-ChainCode-Demo"><a href="#Marbles-A-ChainCode-Demo" class="headerlink" title="Marbles: A ChainCode Demo"></a><strong>Marbles: A ChainCode Demo</strong></h3><h3 id="1-架构图"><a href="#1-架构图" class="headerlink" title="1. 架构图"></a>1. 架构图</h3><p><img src="https://raw.githubusercontent.com/IBM-Blockchain/marbles/v3.0/doc_images/comm_flow.png" alt="marbles"></p>
<h3 id="2-运行实例"><a href="#2-运行实例" class="headerlink" title="2. 运行实例"></a>2. 运行实例</h3><p><code>git clone http://gopkg.in/ibm-blockchain/marbles.v3</code></p>
<p><code>git submodule update --init --recursive</code></p>
<p><code>vim config/mycreds.json</code> – 修改配置文件</p>
<blockquote>
<p>npm install gulp -g<br>npm install<br>gulp marbles </p>
</blockquote>
<p>启动成功,即可访问应用。</p>
<p><center><img src="https://raw.githubusercontent.com/IBM-Blockchain/marbles/v3.0/doc_images/use_marbles1.png" alt="marbles market"></center><br></p>
<h2 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h2><hr>
<p><a href="https://wiki.hyperledger.org/" target="_blank" rel="external">Hyperledger Wiki</a><br><a href="http://hyperledger-fabric.readthedocs.io/en/latest/" target="_blank" rel="external">Fabric 官方文档</a><br><a href="http://mp.weixin.qq.com/s/glUhSF8yV7jkqvupd_5Rpg" target="_blank" rel="external">Fabric v1.0</a><br><a href="http://www.8btc.com/hyperledger-fabric1-0" target="_blank" rel="external">Fabric v1.0 架构概览</a><br><a href="http://blog.csdn.net/zxzxzxzx2121/article/details/53034151" target="_blank" rel="external">Fabric 协议</a><br><a href="http://www.8btc.com/hyperledger-fabric" target="_blank" rel="external">Fabric 术语</a><br><a href="https://yeasy.gitbooks.io/blockchain_guide/hyperledger/v0.6/install.html" target="_blank" rel="external">Fabric 安装部署</a><br><a href="https://github.com/IBM-Blockchain/learn-chaincode" target="_blank" rel="external">Learn Chaincode</a><br><a href="https://github.com/IBM-Blockchain" target="_blank" rel="external">IBM-Blockchain</a><br><a href="http://www.cnblogs.com/lion.net/p/6160548.html" target="_blank" rel="external">Swarm 构建</a><br><a href="https://docs.docker.com/engine/getstarted-voting-app/" target="_blank" rel="external">Swarm Compose 样例</a><br><a href="https://docs.docker.com/compose/compose-file/#version-3" target="_blank" rel="external">Docker Compose Version 3</a><br><a href="http://wutongtree.github.io/" target="_blank" rel="external">区块链实用手册</a><br><a href="https://www.gitbook.com/book/yeasy/blockchain_guide/details" target="_blank" rel="external">区块链技术指南</a><br><a href="http://geek.csdn.net/news/detail/134967" target="_blank" rel="external">区块链开发技术综述</a><br><a href="http://www.dockerinfo.net/3738.html" target="_blank" rel="external">Docker 跨主机通信</a><br><a href="http://fabric-chaintool.readthedocs.io/en/latest/" target="_blank" rel="external">Fabric Chaintool</a><br><a href="http://bitcoin-on-nodejs.ebookchain.org/" target="_blank" rel="external">Ebookchain</a><br><a href="http://www.mail-archive.com/cryptography@metzdowd.com/msg09997.html" target="_blank" rel="external">Bitcoin P2P e-cash paper</a><br><a href="https://blockchain.info/" target="_blank" rel="external">Bitcoin 市场</a><br><a href="https://www.maicoin.com/zh-TW/charts/btc" target="_blank" rel="external">比特币价格走势</a><br><a href="https://en.wikipedia.org/wiki/Satoshi_Nakamoto" target="_blank" rel="external">Satoshi Nakamoto</a><br><a href="https://en.wikipedia.org/wiki/Vitalik_Buterin" target="_blank" rel="external">Vitalik Buterin</a></p>
]]></content>
<summary type="html">
<h3 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a><strong>Preface</strong></h3><blockquote>
<p>“The Times 03/Jan/20
</summary>
<category term="BlockChain" scheme="https://chuckniu.github.io/categories/BlockChain/"/>
<category term="Hyperledger, Fabric, BlockChain" scheme="https://chuckniu.github.io/tags/Hyperledger-Fabric-BlockChain/"/>
</entry>
<entry>
<title>Go In Action</title>
<link href="https://chuckniu.github.io/2017/05/01/Go-In-Action/"/>
<id>https://chuckniu.github.io/2017/05/01/Go-In-Action/</id>
<published>2017-05-01T14:52:59.000Z</published>
<updated>2017-07-04T16:41:21.407Z</updated>
<content type="html"><![CDATA[<h4 id="1-Golang-起源"><a href="#1-Golang-起源" class="headerlink" title="1. Golang 起源"></a>1. Golang 起源</h4><p>GO 语言由 Google 于 2009 年 11 月开源,荣膺 TIOBE 2009,2016 年度语言。</p>
<p>主要贡献者为 Ken Thompson, Rob Pike, Robert Griesemer 等, 2012 年 3 月 release 1.0 版本, 最新版本 Go 1.8。</p>
<p>官网:<a href="https://golang.org/" target="_blank" rel="external">https://golang.org/</a></p>
<p>Go 语言设计为系统语言,风格简单实用,兼顾性能和效率,基于 CSP 并发模型,原生协程( goroutine )处理, 并发能力卓越。</p>
<p>业界案例:Docker, Hyperledger, TiDB</p>
<h4 id="2-安装环境"><a href="#2-安装环境" class="headerlink" title="2. 安装环境"></a>2. 安装环境</h4><p>Linux,Mac,Windows 等平台都有相应的安装包,安装完毕后设置 GOPATH 环境变量作为 workspace。</p>
<p>基础命令:</p>
<ol>
<li>go build 编译</li>
<li>go run 运行</li>
<li>go install 编译并复制到 bin 目录</li>
<li>go get 安装依赖包</li>
<li>go test 测试</li>
</ol>
<h4 id="3-基础语法"><a href="#3-基础语法" class="headerlink" title="3. 基础语法"></a>3. 基础语法</h4><p>规约:大小写约定权限,不用分号</p>
<p>基本类型:</p>
<ul>
<li>布尔型:bool</li>
<li>整型:int int64 int32 int16 int8 uint8(byte) uint16 uint32 uint64 uint</li>
<li>浮点型:float32 float64</li>
<li>复数型:complex64 complex128</li>
<li>字符串:string</li>
<li>字符型:byte rune</li>
</ul>
<p>复合类型:array, struct, function, interface, slice, map, channel</p>
<p>关键保留字 25 个:</p>
<ul>
<li>var, const :变量和常量的声明</li>
<li>package, import: 包声明,包导入</li>
<li>func: 定义函数和方法</li>
<li>return: 从函数返回</li>
<li>defer:在函数退出之前执行</li>
<li>go : 用于并行</li>
<li>select: 用于选择不同类型的通讯</li>
<li>interface: 用于定义接口</li>
<li>struct: 用于定义抽象数据类型</li>
<li>break、case、continue、for、fallthrough、else、if、switch、goto、default: 流程控制</li>
<li>chan: 用于channel通讯</li>
<li>type: 用于声明自定义类型</li>
<li>map: 用于声明map类型数据</li>
<li>range: 用于读取slice、map、channel数据</li>
</ul>
<p>内置函数:</p>
<ul>
<li>new 分配零值内存 并返回指针</li>
<li>make 分配内存初始化结构 并返回对象</li>
<li>append</li>
<li>close</li>
<li>recover</li>
<li>panic</li>
<li>len</li>
<li>delete</li>
<li>copy</li>
<li>…</li>
</ul>
<h4 id="4-实例"><a href="#4-实例" class="headerlink" title="4. 实例"></a>4. 实例</h4><ul>
<li><p>Hello World</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">package main</div><div class="line">import (</div><div class="line"> "fmt"</div><div class="line">)</div><div class="line">func main() {</div><div class="line"> fmt.Println("Hello,世界!")</div><div class="line">}</div></pre></td></tr></table></figure>
</li>
<li><p>变量定义</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">package main</div><div class="line">import (</div><div class="line"> "fmt"</div><div class="line">)</div><div class="line">var(</div><div class="line"> one int</div><div class="line"> two string</div><div class="line">)</div><div class="line">func main() {</div><div class="line"> one, two = 1,"2"</div><div class="line"> three:= "2"</div><div class="line"> fmt.Println(one, two, three )</div><div class="line">}</div></pre></td></tr></table></figure>
</li>
<li><p>struct, func</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div></pre></td><td class="code"><pre><div class="line">package main</div><div class="line">import (</div><div class="line"> "fmt"</div><div class="line">)</div><div class="line">type person struct{</div><div class="line"> name string</div><div class="line"> age int</div><div class="line"> gender byte</div><div class="line">}</div><div class="line">func (p *person) getAge() int {</div><div class="line"> return p.age</div><div class="line">}</div><div class="line">func (p *person) getNameAndAge() (string, int){</div><div class="line"> return p.name, p.age</div><div class="line">}</div><div class="line">func main() {</div><div class="line"> me := person{</div><div class="line"> name: "Meng",</div><div class="line"> age:18,</div><div class="line"> gender: 0}</div><div class="line"> wo:= new(person)</div><div class="line"> wo.name = "Xi"</div><div class="line"> wo.age = 20</div><div class="line"> wo.gender = 1</div><div class="line"> fmt.Println( me.getAge() )</div><div class="line"> fmt.Println( wo.getNameAndAge() )</div><div class="line">}</div></pre></td></tr></table></figure>
</li>
<li><p>array,slice</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">package main</div><div class="line">import (</div><div class="line"> "fmt"</div><div class="line">) </div><div class="line">func main() {</div><div class="line"> var array = [5]string{"1","2"}</div><div class="line"> var slice_ []int = make([]int,5,10)</div><div class="line"> fmt.Println(array)</div><div class="line"> fmt.Println(slice_)</div><div class="line"> slice_ = append(slice_,6)</div><div class="line"> array[5]="6" //报错</div><div class="line">}</div></pre></td></tr></table></figure>
</li>
<li><p>chan</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">package main</div><div class="line">import "fmt"</div><div class="line">func sum(values []int, resultChan chan int) {</div><div class="line"> sum := 0</div><div class="line"> for _, value := range values {</div><div class="line"> sum += value</div><div class="line"> }</div><div class="line"> // 将计算结果发送到channel中</div><div class="line"> resultChan <- sum</div><div class="line">}</div><div class="line">func main() {</div><div class="line"> values := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}</div><div class="line"> resultChan := make(chan int, 3)</div><div class="line"> go sum(values[:len(values)/2], resultChan)</div><div class="line"> go sum(values[len(values)/2:], resultChan)</div><div class="line"> go sum(values[len(values)/3:], resultChan)</div><div class="line"> sum1, sum2, sum3 := <-resultChan, <-resultChan, <-resultChan</div><div class="line"> fmt.Println("Result:", sum1, sum2, sum3)</div><div class="line">}</div></pre></td></tr></table></figure>
</li>
<li><p>Web Server</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">package main</div><div class="line">import (</div><div class="line"> "io"</div><div class="line"> "net/http"</div><div class="line"> "log"</div><div class="line">)</div><div class="line">func HelloServer(w http.ResponseWriter, req *http.Request) {</div><div class="line"> io.WriteString(w, "hello, world!\n")</div><div class="line">}</div><div class="line">func main() {</div><div class="line"> http.HandleFunc("/hello", HelloServer)</div><div class="line"> err := http.ListenAndServe(":8080", nil)</div><div class="line"> if err != nil {</div><div class="line"> log.Fatal("ListenAndServe: ", err)</div><div class="line"> }</div><div class="line">}</div></pre></td></tr></table></figure>
</li>
</ul>
<h4 id="5-Beego-Web-Framework"><a href="#5-Beego-Web-Framework" class="headerlink" title="5. Beego Web Framework"></a>5. Beego Web Framework</h4><p><a href="https://beego.me/" target="_blank" rel="external">Beego 官网 </a></p>
]]></content>
<summary type="html">
<h4 id="1-Golang-起源"><a href="#1-Golang-起源" class="headerlink" title="1. Golang 起源"></a>1. Golang 起源</h4><p>GO 语言由 Google 于 2009 年 11 月开源,荣膺
</summary>
<category term="Go" scheme="https://chuckniu.github.io/categories/Go/"/>
<category term="Go" scheme="https://chuckniu.github.io/tags/Go/"/>
</entry>
<entry>
<title>Hexo 极简使用指南</title>
<link href="https://chuckniu.github.io/2017/04/18/Hexo-%E6%9E%81%E7%AE%80%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/"/>
<id>https://chuckniu.github.io/2017/04/18/Hexo-极简使用指南/</id>
<published>2017-04-17T17:36:36.000Z</published>
<updated>2017-04-22T20:15:45.000Z</updated>
<content type="html"><![CDATA[<p><a href="https://hexo.io/" target="_blank" rel="external">Hexo</a> 是一个静态博客框架,可托管于 Github Pages。 部署流程参考 <a href="https://hexo.io/docs/" target="_blank" rel="external">官方文档</a>, Windows 下最好在 git bash 中执行命令。 </p>
<h4 id="Install-Git"><a href="#Install-Git" class="headerlink" title="Install Git"></a>Install Git</h4><h4 id="Install-Node-js"><a href="#Install-Node-js" class="headerlink" title="Install Node.js"></a>Install Node.js</h4><h4 id="本地安装-Hexo-Server"><a href="#本地安装-Hexo-Server" class="headerlink" title="本地安装 Hexo Server"></a>本地安装 Hexo Server</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">$ npm install -g hexo-cli</div><div class="line">$ hexo init blog</div><div class="line">$ <span class="built_in">cd</span> blog</div><div class="line">$ npm install</div><div class="line">$ hexo server</div></pre></td></tr></table></figure>
<p>开启本地server后,默认进入 Hello World 页面, 地址:<a href="http://localhost:4000" target="_blank" rel="external">http://localhost:4000</a> 启动前先确认监听端口没被占用。</p>
<h4 id="建立Github-Pages-项目"><a href="#建立Github-Pages-项目" class="headerlink" title="建立Github Pages 项目"></a>建立Github Pages 项目</h4><p>用于托管静态文件,默认域名为:username.github.io</p>
<h4 id="修改配置文件-config-yml"><a href="#修改配置文件-config-yml" class="headerlink" title="修改配置文件 _config.yml"></a>修改配置文件 _config.yml</h4><p>安装 deploy 依赖包:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ npm install hexo-deployer-git --save</div></pre></td></tr></table></figure>
<p>可在配置文件里定义Blog 信息,主题,部署地址等,修改 deploy 信息为:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">deploy:</div><div class="line"> type: git</div><div class="line"> repo: git@github.com:username/username.github.io.git</div><div class="line"> branch: master</div></pre></td></tr></table></figure></p>
<h4 id="新建文章"><a href="#新建文章" class="headerlink" title="新建文章"></a>新建文章</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo new <span class="string">"My New Post"</span></div></pre></td></tr></table></figure>
<h4 id="清除旧的静态文件"><a href="#清除旧的静态文件" class="headerlink" title="清除旧的静态文件"></a>清除旧的静态文件</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo clean</div></pre></td></tr></table></figure>
<h4 id="生成新的静态文件"><a href="#生成新的静态文件" class="headerlink" title="生成新的静态文件"></a>生成新的静态文件</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo generate</div></pre></td></tr></table></figure>
<h4 id="部署到站点"><a href="#部署到站点" class="headerlink" title="部署到站点"></a>部署到站点</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo deploy</div></pre></td></tr></table></figure>
<h4 id="访问-Blog"><a href="#访问-Blog" class="headerlink" title="访问 Blog"></a>访问 Blog</h4><p>进入 username.github.io 显示 Hexo 页面则说明搭建成功。</p>
]]></content>
<summary type="html">
<p><a href="https://hexo.io/" target="_blank" rel="external">Hexo</a> 是一个静态博客框架,可托管于 Github Pages。 部署流程参考 <a href="https://hexo.io/docs/" ta
</summary>
<category term="Blog" scheme="https://chuckniu.github.io/categories/Blog/"/>
<category term="Hexo" scheme="https://chuckniu.github.io/tags/Hexo/"/>
</entry>
</feed>