Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

This is the very first commit of this book. Hence there, for sure, are tons of
typos, and a glorious demonstration of my weak English. I'm still learning, deal
with it :)
  • Loading branch information...
commit aa9ff5403f2203ea2cf9425c1b9df77be9617bca 0 parents
@initpy authored
3  .gitignore
@@ -0,0 +1,3 @@
+_build
+app.yaml
+_static/fonts/
153 Makefile
@@ -0,0 +1,153 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER =
+BUILDDIR = _build
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+ @echo "Please use \`make <target>' where <target> is one of"
+ @echo " html to make standalone HTML files"
+ @echo " dirhtml to make HTML files named index.html in directories"
+ @echo " singlehtml to make a single large HTML file"
+ @echo " pickle to make pickle files"
+ @echo " json to make JSON files"
+ @echo " htmlhelp to make HTML files and a HTML help project"
+ @echo " qthelp to make HTML files and a qthelp project"
+ @echo " devhelp to make HTML files and a Devhelp project"
+ @echo " epub to make an epub"
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
+ @echo " text to make text files"
+ @echo " man to make manual pages"
+ @echo " texinfo to make Texinfo files"
+ @echo " info to make Texinfo files and run them through makeinfo"
+ @echo " gettext to make PO message catalogs"
+ @echo " changes to make an overview of all changed/added/deprecated items"
+ @echo " linkcheck to check all external links for integrity"
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+ -rm -rf $(BUILDDIR)/*
+
+html:
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+ @echo
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+ @echo
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/gobook.qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/gobook.qhc"
+
+devhelp:
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+ @echo
+ @echo "Build finished."
+ @echo "To view the help file:"
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/gobook"
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/gobook"
+ @echo "# devhelp"
+
+epub:
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+ @echo
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
+ "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through pdflatex..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+ @echo
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+ @echo
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo
+ @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+ @echo "Run \`make' in that directory to run these through makeinfo" \
+ "(use \`make info' here to do that automatically)."
+
+info:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo "Running Texinfo files through makeinfo..."
+ make -C $(BUILDDIR)/texinfo info
+ @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+ $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+ @echo
+ @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+ @echo
+ @echo "Link check complete; look for any errors in the above output " \
+ "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
BIN  _static/favicon.ico
Binary file not shown
BIN  _static/images/gophercolor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 _theme/gobook/layout.html
@@ -0,0 +1,111 @@
+{% extends "basic/layout.html" %}
+
+{%- block doctype -%}
+<!DOCTYPE html>
+{%- endblock %}
+
+{%- macro secondnav() %}
+ {%- if prev %}
+ &laquo; <a href="{{ prev.link|e }}" title="{{ prev.title|e }}">previous</a>
+ {{ reldelim2 }}
+ {%- endif %}
+ {%- if parents %}
+ <a href="{{ parents.0.link|e }}" title="{{ parents.0.title|e }}" accesskey="U">up</a>
+ {%- else %}
+ <a title="{{ docstitle }}" href="{{ pathto('index') }}" accesskey="U">up</a>
+ {%- endif %}
+ {%- if next %}
+ {{ reldelim2 }}
+ <a href="{{ next.link|e }}" title="{{ next.title|e }}">next</a> &raquo;
+ {%- endif %}
+{%- endmacro %}
+
+{% block extrahead %}
+{{ super() }}
+{% endblock %}
+
+{% block content %}
+<div id="wrapper">
+ <header id="hd">
+ <h1><a href="{{ pathto('index') }}">{{ docstitle }}</a></h1>
+ </header>
+
+ <section id="main">
+ <nav>{{ secondnav() }}</nav>
+ <section id="{{ pagename|replace('/', '-') }}">
+ {% block body %}{% endblock %}
+ </section>
+ <nav>{{ secondnav() }}</nav>
+ <footer>
+ &copy; <a href="http://big.appspot.com" title="Big Yuuta">Big Yuuta</a>
+ &mdash;
+ <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" title="License">License</a>
+ &mdash;
+ <a href="https://github.com/initpy/go-book/" title="Github Repo">Github</a>
+ &mdash;
+ <a href="{{ pathto('colophon')}}" title="Colophon">Colophon</a>.
+ </footer>
+ </section>
+
+ {% block sidebarwrapper %}
+ <aside id="sidebar">
+ {{ sidebar() }}
+ {%- if last_updated %}
+ <h3>Last update:</h3>
+ <p class="topless">{{ last_updated }}</p>
+ {%- endif %}
+ </aside>
+ <br class="clearboth" />
+ {% endblock %}
+</div>
+{% endblock %}
+
+{% block sidebarrel %}
+<h3>Browse</h3>
+<ul>
+ {% if prev %}
+ <li>Prev: <a href="{{ prev.link }}">{{ prev.title }}</a></li>
+ {% endif %}
+ {% if next %}
+ <li>Next: <a href="{{ next.link }}">{{ next.title }}</a></li>
+ {% endif %}
+</ul>
+<h3>You are here:</h3>
+<ul>
+ <li>
+ <a href="{{ pathto('index') }}">{{ docstitle }}</a>
+ {% for p in parents %}
+ <ul><li><a href="{{ p.link }}">{{ p.title }}</a>
+ {% endfor %}
+ <ul><li>{{ title }}</li></ul>
+ {% for p in parents %}</li></ul>{% endfor %}
+ </li>
+</ul>
+{% endblock %}
+
+{# Empty some default blocks out #}
+{% block relbar1 %}{% endblock %}
+{% block relbar2 %}{% endblock %}
+{% block sidebar1 %}{% endblock %}
+{% block sidebar2 %}{% endblock %}
+{% block footer %}{% endblock %}
+{% block sidebarsourcelink %}{% endblock %}
+
+{# Search box #}
+{% block sidebarsearch %}
+ {%- if pagename != "search" %}
+ <div id="searchbox" style="display: none">
+ <h3>{{ _('Quick search') }}</h3>
+ <form class="search" action="{{ pathto('search') }}" method="get">
+ <input type="text" name="q" />
+ <input type="submit" value="{{ _('Go') }}" />
+ <input type="hidden" name="check_keywords" value="yes" />
+ <input type="hidden" name="area" value="default" />
+ </form>
+ <p class="searchtip" style="font-size: 90%">
+ {{ _('Enter search terms.') }}
+ </p>
+ </div>
+ <script type="text/javascript">$('#searchbox').show(0);</script>
+ {%- endif %}
+{% endblock %}
3  _theme/gobook/search.html
@@ -0,0 +1,3 @@
+{% extends "basic/search.html" %}
+{% block bodyclass %}{% endblock %}
+{% block sidebarwrapper %}{% endblock %}
627 _theme/gobook/static/default.css
@@ -0,0 +1,627 @@
+/*
+@font-face {
+ font-family:Rancho;
+ src:url('fonts/Rancho/Rancho-Regular.ttf');
+}
+*/
+@import url(http://fonts.googleapis.com/css?family=Rancho);
+
+* {
+ margin:0;
+ padding:0;
+ border:0;
+}
+
+body {
+ margin:0;
+ background:#503e2a;
+ background:#4b0000;
+ background: -moz-linear-gradient(top, #100000 0%, #4b0000 40%); /* FF3.6+ */
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#100000), color-stop(40%,#4b0000)); /* Chrome,Safari4+ */
+ background: -webkit-linear-gradient(top, #100000 0%,#4b0000 40%); /* Chrome10+,Safari5.1+ */
+ background: -o-linear-gradient(top, #100000 0%,#4b0000 40%); /* Opera 11.10+ */
+ background: -ms-linear-gradient(top, #100000 0%,#4b0000 40%); /* IE10+ */
+ background: linear-gradient(top, #100000 0%,#4b0000 40%); /* W3C */
+ font:12px/1.5 Verdana,sans-serif;
+ color:white;
+ text-align:left;
+}
+
+figure, footer, header, nav, section, figcaption {
+ display:block;
+}
+
+#wrapper {
+ width:960px;
+ margin:0px auto;
+}
+
+#main {
+ float:left;
+ margin:0;
+ width:640px;
+ font-size:1em;
+ color:#000;
+}
+
+#main > section {
+ padding:20px;
+ background-color:#fff;
+ min-height:600px;
+ -moz-box-shadow:#100000 0 0 10px;
+ -webkit-box-shadow:#100000 0 0 10px;
+}
+
+#sidebar {
+ float:right;
+ margin:0;
+ width:280px;
+ font-size:1em;
+ background-color:transparent;
+ color:#fff;
+ padding:30px 10px 0px 20px;
+ text-align:left;
+ text-shadow:#000000 1px 1px 1px;
+}
+
+header {
+ padding:4px 0 12px 0;
+}
+
+footer {
+ color:#f9f0bf;
+ font-size:90%;
+ padding-bottom:2em;
+ text-align:right
+}
+
+/*** links ***/
+a {
+ text-decoration:none;
+}
+
+a:link, a:visited {
+ color:#ffffbf;
+}
+
+img {
+ margin:10px;
+}
+
+a img {
+ border:none;
+}
+
+#main a:link, #main a:visited {
+ color:#08519c;
+}
+
+#sidebar a:link, #sidebar a:visited {
+ color:#f9f05a;
+}
+
+#main a:hover {
+ text-decoration:underline;
+}
+
+#sidebar a:hover {
+ color:#f9f0bf;
+ text-decoration:underline;
+}
+
+h2 a, h3 a, h4 a {
+ text-decoration:none !important;
+}
+
+a.reference em {
+ font-style:normal;
+}
+
+a:hover {
+ text-decoration:underline;
+}
+
+header h1 a {
+ font-family:Rancho;
+ color:white;
+}
+
+header nav a:hover{
+ text-decoration:none;
+}
+
+
+#main footer a, #main footer a:link, #main footer a:visited,
+#main footer a:hover {
+ color:#f9f0bf;
+}
+
+/*** sidebar ***/
+#sidebar div.sphinxsidebarwrapper {
+ font-size:92%;
+ margin-right:14px;
+}
+
+#sidebar h3, #sidebar h4 {
+ color:white;
+ font-size:175%;
+}
+
+#sidebar a {
+ color:white;
+}
+
+#sidebar ul ul {
+ margin-top:0;
+ margin-bottom:0;
+}
+
+#sidebar li {
+ margin-top:0.2em;
+ margin-bottom:0.2em;
+}
+
+/*** nav ***/
+#main nav {
+ margin:0;
+ padding:10px;
+ background-color:#200000;
+ font-size:11px;
+ text-align:right;
+ color:#fff;
+ -moz-box-shadow:#100000 0 0 10px;
+ -webkit-box-shadow:#100000 0 0 10px;
+}
+
+#main nav a, #main nav a:link, #main nav a:visited {
+ color:#f9f0bf;
+}
+
+#main nav a:hover {
+ text-decoration:underline;
+}
+
+section#main h2{
+ clear:left;
+}
+
+header h1 {
+ font-family:Rancho;
+ color:white;
+ font-size:48px;
+ text-shadow:#100000 1px 1px 4px;
+}
+
+header nav {
+ position:absolute;
+ top:5px;
+ margin-left:-5px;
+ padding:7px 0;
+ color:#263E2B;
+}
+
+header nav a, header nav a:visited {
+ color:#fff;
+}
+
+header nav a {
+ padding:0 4px;
+}
+
+header nav:hover {
+ color:#fff;
+}
+
+footer {
+ margin:10px 0;
+ color:#fff;
+ text-align:center;
+ text-shadow:#100000 1px 1px 4px;
+}
+
+/*** content ***/
+/*** basic styles ***/
+dd {
+ margin-left:15px;
+}
+
+h1,h2,h3,h4 {
+ margin-top:1em;
+ font-family:"Trebuchet MS",sans-serif;
+ font-family:Rancho;
+ font-weight:normal;
+}
+
+h1 {
+ font-size:300%;
+ margin-top:0.6em;
+ margin-bottom:.4em;
+ line-height:1.1em;
+ color:#67001f;
+}
+
+h2 {
+ font-size:250%;
+ margin-bottom:.6em;
+ line-height:1.2em;
+ color:#7f2704;
+}
+
+h3 {
+ font-size:175%;
+ margin-bottom:.2em;
+ color:#a63603;
+}
+
+h4 {
+ font-size:150%;
+ margin-top:1.5em;
+ margin-bottom:3px;
+ color:#f46d43;
+}
+
+div.figure {
+ text-align:center;
+}
+
+div.figure p.caption {
+ font-size:1em;
+ margin-top:0;
+ margin-bottom:1.5em;
+ color:#555;
+}
+
+hr {
+ color:#ccc;
+ background-color:#ccc;
+ height:1px;
+ border:0;
+}
+
+p, ul, dl {
+ margin-top:.6em;
+ margin-bottom:1em;
+ padding-bottom:0.1em;
+}
+
+caption {
+ font-size:1em;
+ font-weight:bold;
+ margin-top:0.5em;
+ margin-bottom:0.5em;
+ margin-left:2px;
+ text-align:center;
+}
+
+blockquote {
+ padding:0 1em;
+ margin:1em 0;
+ font:125%/1.2em "Trebuchet MS", sans-serif;
+ color:#234f32;
+ border-left:2px solid #94da3a;
+}
+
+strong {
+ font-weight:bold;
+}
+
+em {
+ font-style:italic;
+}
+
+ins {
+ font-weight:bold;
+ text-decoration:none;
+}
+
+/*** lists ***/
+ul {
+ padding-left:30px;
+}
+
+ol {
+ padding-left:30px;
+}
+
+ol.arabic li {
+ list-style-type:decimal;
+}
+
+ul li {
+ list-style-type:square;
+ margin-bottom:.4em;
+}
+
+ol li {
+ margin-bottom:.4em;
+}
+
+ul ul {
+ padding-left:1.2em;
+}
+
+ul ul ul {
+ padding-left:1em;
+}
+
+ul.linklist, ul.toc {
+ padding-left:0;
+}
+
+ul.toc ul {
+ margin-left:.6em;
+}
+
+ul.toc ul li {
+ list-style-type:square;
+}
+
+ul.toc ul ul li {
+ list-style-type:disc;
+}
+
+ul.linklist li, ul.toc li {
+ list-style-type:none;
+}
+
+dt {
+ font-weight:bold;
+ margin-top:.5em;
+ font-size:1.1em;
+}
+
+dd {
+ margin-bottom:.8em;
+}
+
+ol.toc {
+ margin-bottom:2em;
+}
+
+ol.toc li {
+ font-size:125%;
+ padding:.5em;
+ line-height:1.2em;
+ clear:right;
+}
+
+ol.toc li.b {
+ background-color:#E0FFB8;
+}
+
+ol.toc li a:hover {
+ background-color:transparent !important;
+ text-decoration:underline !important;
+}
+
+ol.toc span.release-date {
+ float:right;
+ font-size:85%;
+ padding-right:.5em;
+}
+
+ol.toc span.comment-count {
+ font-size:75%;
+ color:#999;
+}
+
+/*** tables ***/
+table {
+ color:#000;
+ margin-bottom:1em;
+ width:100%;
+}
+
+table.docutils td p {
+ margin-top:0;
+ margin-bottom:.5em;
+}
+
+table.docutils td, table.docutils th {
+ border-bottom:1px solid #dfdfdf;
+ padding:4px 2px;
+}
+
+table.docutils thead th {
+ border-bottom:2px solid #dfdfdf;
+ text-align:left;
+ font-weight:bold;
+ white-space:nowrap;
+}
+
+table.docutils thead th p {
+ margin:0;
+ padding:0;
+}
+
+table.docutils {
+ border-collapse:collapse;
+}
+
+/*** code blocks ***/
+.literal {
+ white-space:nowrap;
+}
+
+.literal {
+ color:#aa0000;
+}
+
+#sidebar .literal {
+ color:white;
+ background:transparent;
+ font-size:11px;
+}
+
+h4 .literal {
+ color:#234f32;
+ font-size:13px;
+}
+
+pre {
+ font-size:small;
+ background:#222;
+ border:1px solid #111;
+ border-width:1px 0;
+ margin:1em 0;
+ padding:.3em .4em;
+ overflow:hidden;
+ line-height:1.3em;
+}
+
+dt .literal, table .literal {
+ background:none;
+}
+
+#main a.reference tt.literal {
+ border-bottom:1px #234f32 dotted;
+}
+
+/* Restore colors of pygments hyperlinked code */
+#main .highlight .k a:link, #main .highlight .k a:visited {
+ color:#000000;
+ text-decoration:none;
+ border-bottom:1px dotted #000000;
+}
+
+#main .highlight .nf a:link, #main .highlight .nf a:visited {
+ color:#990000;
+ text-decoration:none;
+ border-bottom:1px dotted #990000;
+}
+
+/*** notes & admonitions ***/
+.note, .admonition {
+ padding:.8em 1em .8em;
+ margin:1em 0;
+ border:1px solid #fee391;
+ background:url(note.png) .8em .8em no-repeat;
+ background-color:#fff7bc;
+}
+
+.admonition-title {
+ font-weight:bold;
+ margin-top:0 !important;
+ margin-bottom:0 !important;
+}
+
+.admonition .last {
+ margin-bottom:0 !important;
+}
+
+.note, .admonition {
+ padding-left:65px;
+ background-image:url(note.png);
+}
+
+div.admonition-philosophy {
+ padding-left:65px;
+ background-color:#fff7f3;
+ border-color:#f4cae4;
+ background-image:url(philosophy.png);
+}
+
+div.admonition-remember {
+ padding-left:65px;
+ background-image::url(remember.png);
+}
+
+/*** versoinadded/changes ***/
+div.versionadded, div.versionchanged {
+}
+
+div.versionadded span.title, div.versionchanged span.title {
+ font-weight:bold;
+}
+
+/*** p-links ***/
+a.headerlink {
+ color:#c60f0f;
+ font-size:0.8em;
+ padding:0 4px 0 4px;
+ text-decoration:none;
+ visibility:hidden;
+}
+
+h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink,
+h4:hover > a.headerlink, h5:hover > a.headerlink, h6:hover > a.headerlink,
+dt:hover > a.headerlink {
+ visibility:visible;
+}
+
+/*** index ***/
+table.indextable td {
+ text-align:left;
+ vertical-align:top;
+}
+
+table.indextable dl, table.indextable dd {
+ margin-top:0;
+ margin-bottom:0;
+}
+
+table.indextable tr.pcap {
+ height:10px;
+}
+
+table.indextable tr.cap {
+ margin-top:10px;
+ background-color:#f2f2f2;
+}
+
+/*** page-specific overrides ***/
+div#contents ul {
+ margin-bottom:0;
+}
+
+div#contents ul li {
+ margin-bottom:0;
+}
+
+div#contents ul ul li {
+ margin-top:0.3em;
+}
+
+/*** IE hacks ***/
+* pre {
+ width:100%;
+}
+
+.clearboth {
+ clear:both;
+}
+
+.linenos {
+ color:#eee;
+}
+
+.centerit, .graphviz {
+ text-align:center;
+ display:block;
+ margin:20px auto;
+}
+
+.output {
+ border:1px solid #d9d6ad;
+ background-color:#efeedb;
+ padding:20px;
+ margin:10px 0;
+}
+
+.rightfloat {
+ float:right;
+}
+
+.side {
+ float:right;
+ padding:0 0 0 20px;
+ border-left:3px solid #d9d6ad;
+ color:#555;
+ width:250px;
+ clear:both;
+}
+
+.a{
+ margin:20px 0;
+ border:1px solid #eee;
+}
BIN  _theme/gobook/static/note.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  _theme/gobook/static/philosophy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  _theme/gobook/static/remember.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 _theme/gobook/theme.conf
@@ -0,0 +1,4 @@
+[theme]
+inherit = basic
+stylesheet = default.css
+pygments_style = trac
280 basic.rst
@@ -0,0 +1,280 @@
+.. include:: common.txt
+
+The basic things
+****************
+In the previous chapter, we saw that Go programs are orginized in *packages* and
+that Go natively supports UTF-8 for strings and identifiers. In this chapter we
+will see how to declare and use variables and constants and the different Go
+built-in types.
+
+
+How to declare a variable?
+==========================
+There are sevral ways to declare a variable in Go.
+
+The basic form is:
+
+.. code-block:: go
+
+ // declare a variable named "variable_name" of type "type"
+ var variable_name type
+
+You can declare sevral variables of the same type in a single line, by
+separating them with commas.
+
+.. code-block:: go
+
+ // declare variables var1, var2, and var3 all of type type
+ var var1, var2, var3 type
+
+And you can initialize a variable when declaring it too
+
+.. code-block:: go
+
+ /* declare a variable named "variable_name" of type "type" and initalize it
+ to value*/
+ var variable_name type = value
+
+You can even initalize many variables that are declared in the same statement
+
+.. code-block:: go
+
+ /* declare a var1, var2, var3 of type "type" and initalize them to value1,
+ value2, and value3 respectively*/
+ var var1, var2, var3 type = value1, value2, value3
+
+Guess what? You can omit the type and it will be infered from the initalizers
+
+.. code-block:: go
+
+ /* declare and initialize var1, var2 and var3 and initalize them to
+ respectively: value1, value2, and value3 /
+ var var1, var2, var3 = value1, value2, value3
+
+Even shorter, inside a function body (let me repeat that: only inside a function
+body) you can even drop the keyword ``var`` and use the ``:=`` instead of ``=``
+
+.. code-block:: go
+
+ // omit var and type, and use ':=' instead of '=' inside the function body
+ func test(){
+ var1, var2, var3 := value1, value2, value3
+ }
+
+Don't worry. It's actually easy. The examples with the builtin types, below,
+will illustrate both of these forms. Just remember that, unlike the C way, in Go
+the type is put at the end of the declaration and -should I repeat it?- **that
+the := operator can only be used inside a function body**.
+
+.. _primitive-types:
+
+The builtin types
+=================
+
+Boolean
+-------
+For boolean truth values, Go has the type ``bool`` (like the C++ one) that takes
+one of the values: ``true`` or ``false``.
+
+.. code-block:: go
+ :linenos:
+
+ //Example snippet
+ var active bool //basic form
+ var enabled, disabled = true, false //type ommited, varables initialized
+ func test(){
+ var available bool //general form
+ valid := false //type and var omited, and variable initalized
+ available = true //normal assignation
+ }
+
+
+Numeric types
+-------------
+For integer values, signed and unsigned, Go has ``int`` and ``uint`` both having
+the appropriate length for your machine (32 or 64 bits) But there's also
+explicit sized ints: ``int8``, ``int16``, ``int32``, ``int64`` and ``byte``,
+``uint8``, ``uint16``, ``uint32``, ``uint64``. With ``byte`` being an alias for
+``uint8``.
+
+For floating point values, we have ``float32`` and ``float64``.
+
+Wait that's not all, Go has native support for complex numbers too! In fact, you
+can use ``complex64`` for numbers with 32 bits for the real part and 32 bits
+for the imaginary part, and there is ``complex128`` for numbers with 64 bits for
+the real part and 64 bits for the imaginary part.
+
+Table of numeric types
+^^^^^^^^^^^^^^^^^^^^^^
+
+From the `Go Programming Language Specification`_
+
++----------+----------------------------------------------------------------------------------------+
+|Type | Values |
++==========+========================================================================================+
+|uint8 | the set of all unsigned 8-bit integers (0 to 255) |
++----------+----------------------------------------------------------------------------------------+
+|uint16 | the set of all unsigned 16-bit integers (0 to 65535) |
++----------+----------------------------------------------------------------------------------------+
+|uint32 | the set of all unsigned 32-bit integers (0 to 4294967295) |
++----------+----------------------------------------------------------------------------------------+
+|uint64 | the set of all unsigned 64-bit integers (0 to 18446744073709551615) |
++----------+----------------------------------------------------------------------------------------+
+| |
++----------+----------------------------------------------------------------------------------------+
+|int8 | the set of all signed 8-bit integers (-128 to 127) |
++----------+----------------------------------------------------------------------------------------+
+|int16 | the set of all signed 16-bit integers (-32768 to 32767) |
++----------+----------------------------------------------------------------------------------------+
+|int32 | the set of all signed 32-bit integers (-2147483648 to 2147483647) |
++----------+----------------------------------------------------------------------------------------+
+|int64 | the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807) |
++----------+----------------------------------------------------------------------------------------+
+| |
++----------+----------------------------------------------------------------------------------------+
+|float32 | the set of all IEEE-754 32-bit floating-point numbers |
++----------+----------------------------------------------------------------------------------------+
+|float64 | the set of all IEEE-754 64-bit floating-point numbers |
++----------+----------------------------------------------------------------------------------------+
+| |
++----------+----------------------------------------------------------------------------------------+
+|complex64 | the set of all complex numbers with float32 real and imaginary parts |
++----------+----------------------------------------------------------------------------------------+
+|complex128| the set of all complex numbers with float64 real and imaginary parts |
++----------+----------------------------------------------------------------------------------------+
+| |
++----------+----------------------------------------------------------------------------------------+
+| byte familiar alias for uint8 |
++----------+----------------------------------------------------------------------------------------+
+
+
+.. code-block:: go
+ :linenos:
+
+ //Example snippet
+ var i int32 //basic form with a int32
+ var x, y, z = 1, 2, 3 //type omited, variables initialized
+ func test(){
+ var pi float32 //basic form
+ one, two, thre := 1, 2, 3 //type and var omited, variables initialized
+ c := 10+3i // a complex number, type infered and keyword 'var' omited.
+ pi = 3.14 // normal assignation
+ }
+
+Strings
+-------
+As seen in the previous chapter, strings are in UTF-8 and they are enclosed
+between two double quotes (") and their type is -you bet!- ``string``.
+
+.. code-block:: go
+ :linenos:
+
+ //Example snippet
+ var french_hello string //basic form
+ var empty_string string = "" // here empty_string (like french_hello) equals ""
+ func test(){
+ no, yes, maybe := "no", "yes", "maybe" //var and type omited
+ japanese_hello := "Ohaiou" //type inferred, var keyword omited
+ french_hello = "Bonjour" //normal assignation
+ }
+
+Constants
+=========
+In Go, constants are -uh- constant values created at compile time, and they
+can be: numbers, boolean or strings.
+
+The syntax to declare a constant is:
+
+.. code-block:: go
+
+ const constant_name = value
+
+Some examples:
+
+.. code-block:: go
+ :linenos:
+
+ //example snippet
+ const i = 100
+ const pi = 3.14
+ const prefix = "go_"
+
+Facilities
+==========
+
+Grouping declarations
+---------------------
+Multiple ``var``, ``const`` and ``import`` declarations can be grouped using
+parenthesis.
+
+So instead of writing:
+
+.. code-block:: go
+ :linenos:
+
+ //example snippet
+ import "fmt"
+ import "os"
+
+ const i = 100
+ const pi = 3.14
+ const prefix = "go_"
+
+ var i int
+ var pi = float32
+ var prefix string
+
+You can write:
+
+.. code-block:: go
+ :linenos:
+
+ //example snippet with grouping
+ import(
+ "fmt"
+ "os"
+ )
+
+ const(
+ i = 100
+ pi = 3.14
+ prefix = "go_"
+ )
+
+ var(
+ i int
+ pi = float32
+ prefix string
+ )
+
+
+*Of course*, you group consts with consts, vars with vars and imports with imports
+but you can not mix them in the same group!
+
+iota and enumerations
+---------------------
+Go provides the keyword ``iota`` that can be used when declaring enumerated
+constants, This keyword yelds an incremented value by 1, starting from 0, each
+time it is used.
+
+Example:
+
+.. code-block:: go
+ :linenos:
+
+ //example snippet
+ const(
+ x = iota //x == 0
+ y = iota //y == 1
+ z = iota //z == 2
+ w // implicitely w == iota, therefore: w == 3
+ )
+
+
+Well, that's it for this chapter. I told you, it won't be hard. In fact, Go
+eases variables declarations a lot. You'd almost feel like coding with a
+scripting language like python --and it's even better.
+
+.. external links and footnotes:
+
+.. _Go Programming Language Specification: http://golang.com/doc/go_spec.html#Numeric_types
49 colophon.rst
@@ -0,0 +1,49 @@
+Colophon
+********
+This humble work was and is still being done on vim_ using Sphinx_ with the help
+of Graphviz_ (for the various drawings and diagrams) and some tea as the
+author's fuel.
+
+The font used for the titles is `Rancho Regular`_ released by `Sideshow`_ under
+the `Apache License, version 2.0`_
+
+The examples provided in this book are in public domain. You can do whatever you
+want with them and I claim no responsability over their use. Just leave me
+alone.
+
+The whole work is produced in HTML5, and I don't care if your browser is old.
+It's easier for you to upgrade your browser than for me to rewrite the template
+used to generate this. I don't care :)
+
+The Go gopher was drawn by `Renée French`_, the artist who also made Glenda_
+the `Plan 9`_ bunny.
+
+License
+=======
+This work is licensed under a `Creative Commons
+Attribution-NonCommercial-ShareAlike 3.0 Unported License`_. The source code is
+available on github at `https://github.com/initpy/go-book/
+<https://github.com/initpy/go-book/>`_.
+
+Your pull requests for new content, typos, better ideas... are more than
+welcome! If you want to translate this work, please let me know, I'd love to
+share your translation here too.
+
+A little request, and I know most of you won't do it anyway. But I'd hate it if
+this work is copyied/pasted to spam search engines and make money out of it.
+Really.
+
+
+.. external links and footnotes:
+
+.. _vim: http://www.vim.org
+.. _Sphinx: http://sphinx.pocoo.org/
+.. _Graphviz: http://graphviz.org/
+.. _Rancho Regular: http://www.google.com/webfonts/specimen/Rancho
+.. _Sideshow: https://profiles.google.com/sideshowfonts/about
+.. _Apache License, version 2.0: http://www.apache.org/licenses/LICENSE-2.0.html
+.. _Renée French: http://www.reneefrench.com/
+.. _Glenda: http://cm.bell-labs.com/plan9/glenda.html
+.. _Plan 9: http://cm.bell-labs.com/plan9/
+.. _Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License:
+ http://creativecommons.org/licenses/by-nc-sa/3.0/
1  common.txt
@@ -0,0 +1 @@
+.. common substitution strings and misc.
435 composite.rst
@@ -0,0 +1,435 @@
+.. include:: common.txt
+
+.. _composite-types:
+
+Basic composite types
+*********************
+In the :doc:`previous chapter<functions>`, we saw how to combine the traditional
+control flow idioms seen in :doc:`chapter 3<control>` to create blocks of
+reusable code, called *functions*. In this chapter, we'll see how to combine
+the basic data types seen in :ref:`chapter 2<primitive-types>`, in order to
+create complex data types.
+
+The problem
+===========
+Go comes with some *primitive* types: ints, floats, complex numbers, booleans,
+and strings. Fair enough, but you'll notice as you start to write complex
+programs that you'll need more advanced forms of data.
+
+Here's an example:
+
+So in the previous chapter, we wrote the ``MAX(A, B int)`` function to find out
+the bigger value between two integers A, and B. Now, suppose that A, and B are
+actually the ages of persons whose names are respectively Tom and Bob. We need
+our program to output the name of the older person, and by how many years he is
+older.
+
+Sure, we still can use the ``MAX(A, B int)`` function by giving it as input
+parameters, the ages of Tom and Bob. But it'd be nicer to write a function
+``Older`` for real **people**. And not for integers.
+
+*People*! I said people! Thus the need to *create* a custom type to *represent*
+people, and this type will be used for the input parameters of the ``Older``
+function we'd like to write.
+
+Structs
+=======
+In Go, as in C and other languages, we can declare new types that act as
+*containers* for attributes or fields of some other types. For example, we can
+create a custom type called ``person`` to represent a real-world person, and
+that will contain the person's *name* **and** his *age*.
+
+.. graphviz::
+
+ digraph person {
+ rankdir=LR;
+ graph [bgcolor=transparent, resolution=96, fontsize="10" ];
+ edge [arrowsize=.5, arrowtail="dot", color="#FF6600"];
+ node [shape=record, fontsize=8, height=.1, penwidth=.4]
+ person[label="<f0>Tom|<f1>25"];
+ node[shape=plaintext];
+ pName [label="P.name"];
+ pAge [label="P.age"];
+ pName->person:f0;
+ pAge->person:f1;
+ }
+
+
+A type like this is called a ``struct`` (a structure)
+
+How to declare a struct in Go?
+------------------------------
+.. code-block:: go
+ :linenos:
+
+ type person struct{
+ name string //field name of type string.
+ age int //field age of type int.
+ }
+
+See? It's easy. A person ``struct`` is a container of two fields:
+
+- The person's name: a field of type ``string``.
+- The person's age: a field of type ``int``.
+
+And we declare a ``person`` variable as we used to in :doc:`chapter 2<basic>`.
+
+Thus, writing things like:
+
+.. code-block:: go
+ :linenos:
+
+ type person struct{
+ name string
+ age int
+ }
+
+ var P person // tom is a variable of type person
+
+You access and assign a struct's field with the *dot nottation*. That is, if
+``P`` is a variable of type ``person``, then you can access its fields like
+this:
+
+.. code-block:: go
+ :linenos:
+
+ P.name = "Tom" //assign "Tom" to P's name field.
+ P.age = 25 //set P's age to 25 (an int)
+ fmt.Println("The person's name is %s", P.name) //Access P's name field.
+
+There's even two short assignment statement syntaxes:
+
+1. By providing the values for each (and every) field in order:
+
+.. code-block:: go
+ :linenos:
+
+ //declare a variable P of type person and initialize its fields
+ //name to "Tom" and age to 25.
+ P := person{"Tom", 25}
+
+2. By using field:value initializers for any number of fields in any order:
+
+.. code-block:: go
+ :linenos:
+
+ //declare a variable P of type person and initialize its fields
+ //name to "Tom" and age to 25.
+ //Order, here, doesn't count since we specify the fields.
+ P := person{age:24, name:"Tom"}
+
+
+Good. Let's write our ``Older`` function that takes two input parameters of type
+``person``, and returns the older one *and* the difference in their ages.
+
+.. code-block:: go
+ :linenos:
+
+ package main
+ import "fmt"
+
+ // We declare our new type
+ type person struct{
+ name string
+ age int
+ }
+
+
+ //return the older person of p1 and p2
+ //and the difference in their ages
+ func Older(p1, p2 person) (person, int){
+ if p1.age>p2.age { //compare p1 and p2's ages
+ return p1, p1.age-p2.age
+ }
+ return p2, p2.age-p1.age
+ }
+
+ func main(){
+ var tom person
+
+ tom.name, tom.age = "Tom", 18
+
+ //Look how to declare and initialize easily
+ bob := person{age:25, name:"Bob"} //specify the fields and their values
+ paul := person{"Paul", 43} //specify values of fields in their order
+
+ tb_Older, tb_diff := Older(tom, bob)
+ tp_Older, tp_diff := Older(tom, paul)
+ bp_Older, bp_diff := Older(bob, paul)
+
+ fmt.Printf("Of %s and %s, %s is older by %d years\n",
+ tom.name, bob.name, tb_Older.name, tb_diff)
+
+ fmt.Printf("Of %s and %s, %s is older by %d years\n",
+ tom.name, paul.name, tp_Older.name, tp_diff)
+
+ fmt.Printf("Of %s and %s, %s is older by %d years\n",
+ bob.name, paul.name, bp_Older.name, bp_diff)
+ }
+
+Output:
+
+.. container:: output
+
+ | Of Tom and Bob, Bob is older by 7 years
+ | Of Tom and Paul, Paul is older by 25 years
+ | Of Bob and Paul, Paul is older by 18 years
+
+And that's about it! ``struct`` types are handy, easy to declare and to use!
+
+Ready for another problem?
+
+.. _Older100:
+
+Now, suppose that we'd like to retrieve the older of, not 2, but 10 persons!
+Would you write a ``Older10`` function that would take 10 input ``person``\s?
+Sure you can! But, seriously, that would be one ugly, very ugly function! Don't
+write it, just picture it in your brain. Still not convinced? Ok, imagine a
+``Older100`` function with **100** input parameters! Convinced, now?
+
+Ok, let's see how to solve these kind of problems using arrays.
+
+.. _arrays:
+
+Arrays
+======
+An array is a *block* of **n** *consucitive* objects of the same **type**. That
+is a *set* of indexed objects, where you can say: *object number 1*, *object
+number 2*, etc...
+
+In fact, in Go as in C and other languages, the indexing starts from 0, so you
+actually say: *object number 0*, *object number 1*... *object number n-1*
+
+.. graphviz::
+
+ digraph array_s {
+ rankdir=LR;
+ graph [bgcolor=transparent, resolution=96, fontsize="10" ];
+ edge [arrowsize=.5, arrowtail="dot", color="#555555"];
+ node [shape=record, fontsize=8, height=.1, penwidth=.4]
+ array[label="{<f0>A[0]|<f1>[A]1|<f2>A[2]|<f4>A[3]|...|<fn>A[n-1]}"];
+ }
+
+
+Here's how to declare an array of 10 ``int``\s, for example:
+
+.. code-block:: go
+ :linenos:
+
+ //declare an array A of 10 ints
+ var A [10]int
+
+And here's how to declare an array of 10 ``person``\s:
+
+.. code-block:: go
+ :linenos:
+
+ //declare an array A of 10 persons
+ var people [10]person
+
+
+You can access the x :sup:`th` element of an array ``A``, with the syntax:
+**A[x]**. So you say: A[0], A[1] and so on...
+
+For example, the name of the 3rd person is:
+
+.. code-block:: go
+ :linenos:
+
+ //declare an array A of 10 persons
+ var people [10]person
+
+ //Remember indices start from 0!
+ third_name := people[2].name //use the dot to access the third 'name'.
+ //or more verbosely:
+ third_person := people[2]
+ thirdname := third_person.name
+
+.. graphviz::
+
+ digraph array_s {
+ //rankdir=LR;
+ graph [bgcolor=transparent, resolution=96, fontsize="10" ];
+ edge [arrowsize=.5, arrowhead="dot", color="#555555"];
+ node [shape=record, fontsize=8, height=.1, penwidth=.4]
+ people[label="<f0>people[0]|<f1>[people1]|<f2>people[2]|<f3>people[3]|...|<fn>people[n-1]"];
+ p2[shape=circle, penwidth=1, color=crimson, fontcolor=black, label=<
+ <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4" VALIGN="MIDDLE">
+ <TR>
+ <TD BGCOLOR="lightyellow">Tom</TD>
+ <TD BGCOLOR="lightblue">25</TD>
+ </TR>
+ </TABLE>>]
+ p2->people:f2 [label=" Zoom on people[2]", fontsize=6, color=crimson, fontcolor=crimson]
+ }
+
+The idea now is to write a function ``Older10`` that takes an array of 10
+``person``\s as its input, and returns the older ``person`` in this array.
+
+.. code-block:: go
+ :linenos:
+
+ package main
+ import "fmt"
+
+ //Our struct
+ type person struct{
+ name string
+ age int
+ }
+
+ //return the older person in a group of 10 persons
+ func Older10(people [10]person) person{
+ older := people[0] //the first one is yje older for now
+ //loop through the array and check if we could find an older person.
+ for i:= 1; i<10; i++{ //we skiped the first here
+ if people[i].age > older.age{ //compare the current's person age with the older one
+ older = people[i] //if people[i] is older, replace the value of older
+ }
+ }
+ return older
+ }
+
+ func main(){
+ // declare an example array variable of 10 person called: array
+ var array [10]person
+
+ // initialize some of the elements of the array, the others ar by default
+ // set to person{"", 0}
+ array[1] = person{"Paul", 23};
+ array[2] = person{"Jim", 24};
+ array[3] = person{"Sam", 84};
+ array[4] = person{"Rob", 54};
+ array[8] = person{"Karl", 19};
+
+ older := Older10(array) //call the function by passing it our array
+
+ fmt.Println("The older of the group is: ", older.name)
+ }
+
+Output:
+
+.. container:: output
+
+ | The older of the group is: Sam
+
+
+We could have declared and initialized the variable ``array`` of the ``main()``
+function above in a single shot like this:
+
+.. code-block:: go
+ :linenos:
+
+ //declare and initialize an array A of 10 person
+ array := [10]person {
+ person{"", 0},
+ person{"Paul", 23},
+ person{"Jim", 24},
+ person{"Sam", 84},
+ person{"Rob", 54},
+ person{"", 0},
+ person{"", 0},
+ person{"", 0},
+ person{"Karl", 10},
+ person{"", 0}}
+
+This means that to initialize an array, you put its elements between two braces,
+and you separate them with commas.
+
+We can even omit the size of the array, and Go will count the number of element
+given in the initialization. So we could have written:
+
+.. code-block:: go
+ :linenos:
+
+ //declare and initialize an array of 10 person, but let the compiler guess the size.
+ array := [...]person { //omit the size, and put ... instead.
+ person{"", 0},
+ person{"Paul", 23},
+ person{"Jim", 24},
+ person{"Sam", 84},
+ person{"Rob", 54},
+ person{"", 0},
+ person{"", 0},
+ person{"", 0},
+ person{"Karl", 10},
+ person{"", 0}}
+
+.. _arrays-note:
+
+.. note::
+ **However**, the **size of an array is an important part of its
+ definition**. They don't *grow* and they don't *shrink*. You can't, for
+ example, have an array of 9 elements, and use it with a function that
+ expects an array of 10 elements as an input. Simply because they are of
+ *different* types. **Rememeber this.**
+
+Some things to keep in mind too:
+
+- Arrays are values. Assigning one array to another, copies all the elements.
+ That is: if ``A``, and ``B`` are arrays of the same type, and we write: ``B =
+ A``, then ``B[0] == A[0]``, ``B[1] == A[1]``... ``B[n-1] == A[n-1]``.
+
+- When passing an array to a function, it is copied. i.e. The function recieves
+ a copy of that array, and *not* a reference (pointer) to it.
+
+- Go comes with a built-in function ``len`` that returns variables sizes. In the
+ previous example: ``len(array) == 10``.
+
+Multi-dimensional arrays
+========================
+You can think to yourself: *"Hey! I want an array of arrays!"*. Yes, that's
+possible, and often used actually.
+
+You can declare a 2-dimensional array like this:
+
+.. code-block:: go
+ :linenos:
+
+ //declare and initialize an array of 2 arrays of 4 ints
+ a := [2][4]int {[4]int{1,2,3,4}, [4]int{5,6,7,8}}
+
+This is an array of (2 arrays (of 4 ``int``)). You can think of it as a matrix,
+or a table of two lines each made of 4 columns.
+
+.. graphviz::
+
+ digraph array_2 {
+ rankdir=LR;
+ graph [bgcolor=transparent, resolution=96, fontsize="10" ];
+ edge [arrowsize=.5, arrowtail="dot", color="#ff6600"];
+ node [shape=record, fontsize=8, height=.1, penwidth=.4]
+ array[label="{<f00>1|<f01>2|<f02>3|<f03>4}|{<f10>5|<f11>6|<f12>7|<f13>8}"];
+ node[shape="plaintext", fixedsize="true"]
+ exnode00 [label="A[0,0]"];
+ exnode01 [label="A[0,1]"];
+ exnode11 [label="A[1,1]"];
+ exnode13 [label="A[1,3]"];
+ exnode00->array:f00;
+ exnode01->array:f01;
+ exnode11->array:f11;
+ exnode13->array:f13;
+ }
+
+The previous declaration may be simplified, using the fact that the compiler can
+count arrays' elements for us, like this:
+
+.. code-block:: go
+ :linenos:
+
+ //simplify the previous declaration, with the '...' syntax
+ a := [2][4]int {[...]int{1,2,3,4}, [...]int{5,6,7,8}}
+
+Guess what? Since Go is about cleaner code, you can even simplify:
+
+.. code-block:: go
+ :linenos:
+
+ //über simpifikation!
+ a := [2][4]int {{1,2,3,4}, {5,6,7,8}}
+
+Cool, eh? Now, we can combine multiple fields of different types to create a
+``struct`` and we can have ``array``\s of, as many as we want, of objects of the
+same type, and pass it as a *single block* to our functions. But this is just
+the begining! In the next chapter, we will see how to create and use some
+advanced composite data types with pointers.
241 conf.py
@@ -0,0 +1,241 @@
+# -*- coding: utf-8 -*-
+#
+# gobook documentation build configuration file, created by
+# sphinx-quickstart on Mon Oct 17 19:58:23 2011.
+#
+# This file is execfile()d with the current directory set to its containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys, os
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#sys.path.insert(0, os.path.abspath('.'))
+
+# -- General configuration -----------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be extensions
+# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.graphviz']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'gobook'
+copyright = u'2011, Big Yuuta'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '1'
+# The full version, including alpha/beta/rc tags.
+release = '1'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = []
+
+# The reST default role (used for this markup: `text`) to use for all documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'monokai'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- Options for HTML output ---------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+html_theme = 'gobook'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further. For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+html_theme_path = ["_theme"]
+
+# The name for this set of Sphinx documents. If None, it defaults to
+# "<project> v<release> documentation".
+html_title = "Let's learn Go!"
+
+# A shorter title for the navigation bar. Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it. The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'gobookdoc'
+
+
+# -- Options for LaTeX output --------------------------------------------------
+
+latex_elements = {
+# The paper size ('letterpaper' or 'a4paper').
+#'papersize': 'letterpaper',
+
+# The font size ('10pt', '11pt' or '12pt').
+#'pointsize': '10pt',
+
+# Additional stuff for the LaTeX preamble.
+#'preamble': '',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass [howto/manual]).
+latex_documents = [
+ ('index', 'gobook.tex', u'gobook Documentation',
+ u'Big Yuuta', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output --------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+ ('index', 'gobook', u'gobook Documentation',
+ [u'Big Yuuta'], 1)
+]
+
+# If true, show URL addresses after external links.
+#man_show_urls = False
+
+
+# -- Options for Texinfo output ------------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+# dir menu entry, description, category)
+texinfo_documents = [
+ ('index', 'gobook', u'gobook Documentation', u'Big Yuuta',
+ 'gobook', 'One line description of project.', 'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#texinfo_appendices = []
+
+# If false, no module index is generated.
+#texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#texinfo_show_urls = 'footnote'
23 contents.rst
@@ -0,0 +1,23 @@
+Table of contents
+*****************
+
+.. toctree::
+ :maxdepth: 1
+
+ preface
+ first
+ hello
+ basic
+ pointers
+ control
+ functions
+ composite
+ slices
+ maps
+ more-functions
+ even-more-functions
+ methods
+ more-methods
+ interfaces
+ more-interfaces
+ colophon
349 control.rst
@@ -0,0 +1,349 @@
+.. include:: common.txt
+
+Basic Control flow
+******************
+So in the previous chapter, we learned how to declare variables and constants,
+and we saw the different basic, builtin types that come with Go. In this
+chapter, we will see the basic control constructions, or how to *process* this
+data. But before that, let's talk about comments and semicolons.
+
+Comments
+========
+You probably noticed in the example snippets given in previous chapters, some
+comments. Didn't you?
+Go, have the same comments convention as in C++. That is:
+
+* Single line comments: Everything from ``//`` until the end of the line is a
+ comment.
+* bloc comments: Everything betwwen ``/*`` and ``*/`` is a comment.
+
+.. code-block:: go
+ :linenos:
+
+ //Single line comment, this is ignored by the compiler.
+ /* Everything from now on until the keyword var on line 4
+ is a comment, and is ignored by the compiler*/
+ var(
+ i int
+ pi = float32
+ prefix string
+ )
+
+Semicolons
+==========
+If you've programmed with C, or C++, or Pascal, you might wonder why, in the
+previous examples, there weren't any semicolons.
+In fact, you don't need them in Go. Go automatically inserts semicolons on every
+line end that looks like the end of a statement.
+
+And this makes the code a lot cleaner, and easy on the eyes.
+
+the only place you typically see semicolons is separating the clauses of for
+loops and the like; they are not necessary after every statement.
+
+Note that you can use semicolons to separate sevral statements written on the
+same line.
+
+The one surprise is that it's important to put the opening brace of a construct
+such as an if statement on the same line as the if; if you don't, there are
+situations that may not compile or may give the wrong result [#f1]_
+
+Ok let's begin, now.
+
+The if statement
+================
+Perhaps the most well-known statement type in imperative programming. And it can
+be summarized like this: if condition met, do this, else do that.
+
+In Go, you don't need parenthesis for the condition.
+
+.. code-block:: go
+ :linenos:
+
+ if x>10{
+ fmt.Println("x is greater than 10")
+ } else {
+ fmt.Println("x is less than 10")
+ }
+
+You can also have a leading initial short statement before the condition too.
+
+.. code-block:: go
+ :linenos:
+
+ // compute the value of x, and then compare.
+ if x := computed_value(); x>10{
+ fmt.Println("x is greater than 10")
+ } else {
+ fmt.Println("x is less than 10")
+ }
+
+You can combine multiple if/else statements.
+
+.. code-block:: go
+ :linenos:
+
+ if i == 3 {
+ fmt.Println("i is equal to 3")
+ } else if i < 3{
+ fmt.Println("i is less than 3")
+ } else {
+ fmt.Println("i is greater than 3")
+ }
+
+The for statement
+=================
+The ``for`` statement is used for iterations and loops.
+Its general syntax is:
+
+.. code-block:: go
+ :linenos:
+
+ for expression1; expression2; expression3{
+ ...
+ }
+
+Gramatically, ``expression1``, ``expression2``, and ``expression3`` are
+expressions, where ``expression1``, and ``expression3`` are used for
+assignements or function calls (``expression1`` before starting the loop, and
+``expression3`` at the end of evey iteration) and ``expression2`` is used to
+determine whether to continue or stop the iterations.
+
+An example would be better than the previous paragraph, right? Here we go!
+
+.. code-block:: go
+ :linenos:
+
+ package main
+ import "fmt"
+
+ func main(){
+ sum := 0;
+ for i:=0; i<10; i++{
+ sum += i
+ }
+ fmt.Println("sum is equal to ", sum)
+ }
+
+we initalize our variable ``sum`` to 0; and we start our ``for`` loop with
+initializing the variable ``i`` to 0; (``i:=0``) and we execute the for loop's
+body (``sum += i``) *while* the condition ``i<10`` is met, and at the end of
+each iteration, we execute the ``i++`` expression (increment i)
+
+So you guess, the output from the previous program would be:
+
+.. container:: output
+
+ | sum is equal to 45
+
+Because: sum = 0+1+2+3+4+5+6+7+8+9 = 45
+
+**Question:** Is it possible to combine lines 5 and 6 into a single one, in the
+previous program? How?
+
+Actually ``expression1``, ``expression2``, and ``expression3`` are all optional.
+This means you can omit, one, two or all of them in a for loop. If you omit
+``expression1`` or ``expression3`` it means they simply won't be executed. If
+you omit ``expression2`` that'd mean that it is always true and that the loop
+will ieterate for ever -unless a ``break`` statement is met.
+
+And since these expressions may be omitted, you can have something like:
+
+.. code-block:: go
+ :linenos:
+
+ //expression1 and expression3 are omitted here
+ sum := 1
+ for ; sum < 1000; {
+ sum += sum
+ }
+
+Which can be simplified by removing the semicolons:
+
+.. code-block:: go
+ :linenos:
+
+ //expression1 and expression3 are omitted here, and semicolons gone.
+ sum := 1
+ for sum < 1000 {
+ sum += sum
+ }
+
+Or when even expression2 is omitted too, have something like this:
+
+.. code-block:: go
+ :linenos:
+
+ //infinite loop, no semicolons at all.
+ for {
+ fmt.Println("I loop for ever!")
+ }
+
+break and continue
+==================
+
+With ``break`` you can quit loops early. i.e. finish the loop even if the
+condition expressed by ``expression2`` is still true.
+
+.. code-block:: go
+ :linenos:
+
+ //infinite loop, no semicolons at all.
+ for i:=10; i>0; i--{
+ if i<5{
+ break
+ }
+ fmt.Println("i")
+ }
+
+The previous snippet says: loop from 10 to 0, and print the numbers (line 6) but
+if i<5 break the loop! Hence, the program will print numbers 10, 9, 8, 7, 6, 5.
+
+``continue``, on the other hand will just break the current iteration and
+*skips* to the next one.
+
+.. code-block:: go
+ :linenos:
+
+ //infinite loop, no semicolons at all.
+ for i:=10; i>0; i--{
+ if i==5{
+ continue
+ }
+ fmt.Println("i")
+ }
+
+Here the program will print all the numbers from 10 down to 1, except 5! Because
+on line 3, the condition ``if i==5`` will be ``true`` so ``continue`` will be
+executed and the ``fmt.Println(i) (for i == 5)`` won't be run.
+
+The switch statement
+====================
+Sometimes, you'll need to write a complicated chain of ``if``/``else`` tests.
+And the code becomes ugly and hard to read and maintain. The ``switch``
+statement, makes it look nicer and easier to read.
+
+Go's swith is more flexible than its C equivalent, because the case expression
+need not to be constants or even integers.
+
+The general form of a switch statement is
+
+.. code-block:: go
+ :linenos:
+
+ //general form of a switch statement
+ switch sExpr {
+ case expr1:
+ some instructions
+ case expr2:
+ some other instructions
+ case expr3:
+ some other instructions
+ default:
+ other code
+ }
+
+The type of ``sExpr`` and the expressions ``expr1``, ``expr2``, ``expr3``...
+type should match. i.e. if ``var`` is of type *int* the cases expressions should
+be of type *int* too!
+
+Of course, you can have as many cases you want.
+
+Multiple match expressions can be used, each separated by commas in the case
+statement.
+
+If there is no ``sExpr`` at all, then by default it's *bool* and so should be
+the cases expressions.
+
+If more than one case statements match, then the first in lexical order is
+executed.
+
+The *default* case is optional and can be anywhere within the switch block, and
+not necessarily the last one.
+
+Unlike certain other languages, each case block is independent and code does not
+"fall through" (each of the case code blocks are like independent if-else code
+blocks. There is a fallthrough statement that you can explicitly use to obtain
+that behavior.)
+
+Some switch examples:
+---------------------
+
+.. code-block:: go
+ :linenos:
+
+ //simple switch example
+ i := 10
+ switch i {
+ case 1:
+ fmt.Println("i is equal to 1")
+ case 2, 3, 4:
+ fmt.Println("i is equal to 2, 3 or 4")
+ case 10:
+ fmt.Println("i is equal to 10")
+ default:
+ fmt.Println("All I know is that i is an integer")
+ }
+
+In this snippet, we initialized ``i`` to 10, but in practice, you should think
+of ``i`` as a computed value (result of a function or some other calculus before
+the switch statement)
+
+Notice that in line 6, we grouped some expressions (2, 3, and 4) in a single
+case statement.
+
+.. code-block:: go
+ :linenos:
+
+ //switch example without sExpr
+ i := 10
+ switch {
+ case i<10:
+ fmt.Println("i is less than 10")
+ case i>10, i<0:
+ fmt.Println("i is either bigger than 10 or less than 0")
+ case i==10:
+ fmt.Println("i is equal to 10")
+ default:
+ fmt.Println("This won't be printed anyway")
+ }
+
+Now, in this example, we omitted ``sExpr`` of the general form. So the cases
+expressions should be of type *bool*. And so they are! (They're comparisons that
+return either ``true`` or ``false``)
+
+**Question** Can you tell why the ``default`` case on line 10 will never be
+reached?
+
+
+.. code-block:: go
+ :linenos:
+
+ //switch example with fallthrough
+ i := 6
+ switch i {
+ case 4:
+ fmt.Println("was <= 4")
+ fallthrough
+ case 5:
+ fmt.Println("was <= 5")
+ fallthrough
+ case 6:
+ fmt.Println("was <= 6")
+ fallthrough
+ case 7:
+ fmt.Println("was <= 7")
+ fallthrough
+ case 8:
+ fmt.Println("was <= 8")
+ fallthrough
+ default:
+ fmt.Println("default case")
+ }
+
+In this example, the case on line 10 matches, but since there is
+``fallthrough``, the code for ``case 7:`` and so on will be executed too (just
+like a C switch that doesn't use the ``break`` keyword)
+
+
+.. [#f1] http://golang.org/doc/go_tutorial.html#tmp_33
441 even-more-functions.rst
</
@@ -0,0 +1,441 @@
+.. include:: common.txt
+
+Even more on functions
+**********************
+In the previous chapter, we learned how to write variadic, and recursive
+functions and how to use the defer statement to ``defer`` functions calls just
+before the executing function returns.
+
+In this chapter, we will learn something that might seem surprising a little
+bit, but that will end up being *awesome*.
+
+Function types
+==============
+Do you rememebr when we talked about
+:ref:`functions signatures <functions-signatures>`? That what matters most in a
+function, beside what it actually does, is the parameters and results numbers
+and types.
+
+Well, a function type denotes the set of all functions with the same parameter
+and result types.
+
+For example: the functions with signatures: func ``SUM(int, int) int`` and
+``MAX(int, int) int`` are of the same type, because their parameters and
+results count, and types are the same.
+
+Does this sound strange? One computes a sum, and the other the max, yet they are
+both of the same type?
+
+Yes, they are. Picture this with me: The numbers 1, and 23 are both of the same
+type (``int``) yet their *values* are different. Paul and Sam are both of the
+same "human" type, yet their "values" (beliefs, jobs, weight...) are different.
+
+The function's body, what it actually does, is what makes the difference between
+two functions of the same type. Just like how many coffees you can by with 1
+dollar or 23 dollars.
+
+Same thing for functions: What they do, their bodies, is what differentiate two
+functions of the same type.
+
+Convinced? Let's see how to declare functions types.
+
+How to declare a function type?
+-------------------------------
+The syntax is simple:
+
+``type type_name func(input1 type1, input2 type2..) (result resulttype1, ..)``
+
+Some examples to illustrate this:
+
+.. code-block:: go
+ :linenos:
+
+ //twoOne is the type of functions with two int paarmeters and an int result.
+ // max(int, int) int and sum(int, int) int, for eg. are of this type.
+ type twoOne func(int, int) int
+
+ //slice_transform is the type of functions that takes a slice and outputs a
+ //slice.
+ //invert(s []int) []int and sort(s []int) []int are of this type.
+ type slice_transform func(s []int) []int
+
+ //varbytes is the type of variadic functions that takes bytes and outputs a
+ // boolean.
+ // redundant(...byte) bool, and contains_zero(...byte) bool are of this type
+ type varbytes func(...byte) bool
+
+Is it clear now?
+
+*Yes, by why is this even useful or worth the hassle?* You might say. Well,
+I'm glad you asked this question! Read on, you will see the beauty of this.
+
+Functions are values
+====================
+Functions of the same type are values of this type! This means: You can declare
+a variable of a given function-type and assign any function of the same type to
+it. You can pass functions as parameters to other functions, you can also have
+functions that return other functions as results... And this, my friend, offers
+a lot of beautiful, smart and powerful opportunities! Let me show you some
+examples.
+
+Example 1: Write a program that given a slice of ints will return another slice
+that contains only the odd elements of the first slice.
+
+.. code-block:: go
+ :linenos:
+
+ package main
+ import "fmt"
+
+ type test_int func(int) bool
+
+ // isOdd takes an ints and returns a bool set to true if the
+ // int parameter is odd, or false if not.
+ // isOdd is of type func(int) bool which is what test_int is declared to be.
+
+ func isOdd(i int) bool{
+ if i%2 == 0 {
+ return false
+ }
+ return true
+ }
+
+ //same comment for isEven
+ func isEven(i int) bool{
+ if i%2 == 0 {
+ return true
+ }
+ return false
+ }
+
+ // we could've written:
+ // func filter(s []int, f func(int) bool) []int
+ func filter(s []int, f test_int) []int{
+ var result []int
+ for _, value := range s{
+ if f(value) {
+ result = append(result, value)
+ }
+ }
+ return result
+ }
+
+ func main(){
+ s := []int {1, 2, 3, 4, 5, 7}
+ fmt.Println("s = ", s)
+ o := filter(s, isOdd)
+ fmt.Println("Odd elements of s are: ", o)
+ e := filter(s, isEven)
+ fmt.Println("Even elements of s are: ", e)
+ }
+
+Output:
+
+.. container:: output
+
+ | s = [1 2 3 4 5 7]
+ | Odd elements of s are: [1 3 5 7]
+ | Even elements of s are: [2 4]
+
+The functions ``isOdd`` and ``isEven`` are very simple. They take an ``int``,
+and return a ``bool``. Of course, they're just little examples of functions of
+type ``test_int``. One can imagine more advanced and complex functions that are
+of this type.
+
+The intersting part is the ``filter`` function, which takes a slice of type
+``[]int`` *and* a function of type ``test_int`` and returns a slice of type
+``[]int``.
+
+Look at how we made a call ``f(value)`` on line 30. In fact, the function
+``filter`` doesn't *care* how ``f`` works, what matters for it is that ``f``
+needs an ``int`` parameter, and that it returns a ``bool`` result.
+
+And we used this fact, in our ``main`` function. We called ``filter`` using
+different functions of type ``test_int``.
+
+If we're asked to extend the program to filter all the elements of the slice
+that, for example, are multiple of 3. All we would have to do is write a new
+function ``is3Multiple(i int) bool`` and use it with ``filter``.
+
+Now, if we want to filter the odd integers that are multiple of 3, we call
+filter twice likes this:
+
+``slice := filter(filter(s, isOdd), is3Multiple)``
+
+The function ``filter`` is good at what it does. It filters a slice given a
+criteria, and this criteria is expressed in the form of functions.
+
+Cool, isn't it?
+
+Anonymous functions
+===================
+In the previous example, we wrote the functions ``isOdd`` and ``isEven`` outside
+of the main function. It is possible to declare *anonymous* functions in Go,
+that is functions without a name, and assign them to variables.
+
+Let's see what this means with an example:
+
+.. code-block:: go
+ :linenos:
+
+ package main
+ import "fmt"
+
+ func main(){
+ //add1 is a variable of type func(int) int
+ //we don't declare the type since Go can guess it
+ //by looking at the function being assigned to it.
+ add1 := func(x int) int{
+ return x+1
+ }
+
+ n := 6
+ fmt.Println("n = ", n)
+ n = add1(n)
+ fmt.Println("add1(n) = ", n)
+ }
+
+Output:
+
+.. container:: output
+
+ | n = 6
+ | add1(n) = 7
+