<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Go on Nansen Li's Blog
李楠森的博客</title><link>https://nansenli.com/tags/go/</link><description>Recent content in Go on Nansen Li's Blog
李楠森的博客</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>Nansen Li 🌈 （李楠森）</copyright><lastBuildDate>Sat, 07 Feb 2026 16:52:42 +0000</lastBuildDate><atom:link href="https://nansenli.com/tags/go/index.xml" rel="self" type="application/rss+xml"/><item><title>Openclaw Was Too Buggy, So I Built My Own Bot: Nagobot</title><link>https://nansenli.com/post/2026/02/nagobot-launch/</link><pubDate>Sat, 07 Feb 2026 16:52:42 +0000</pubDate><guid>https://nansenli.com/post/2026/02/nagobot-launch/</guid><description>&lt;p>I had been using Openclaw for a while, but the bug rate was just too high. Flows would randomly break, and debugging cost more time than it should.&lt;/p>
&lt;p>On top of that, token cost was not great. Compared with options like DeepSeek and Kimi K2.5, the price-performance ratio felt weak.&lt;/p>
&lt;p>I then tried nanobot, hoping to migrate. But support for newer models was still limited, and K2.5 kept failing with &amp;ldquo;tool execution failed.&amp;rdquo; After several rounds of trial and error, I stopped waiting for a perfect off-the-shelf solution and decided to build one myself.&lt;/p>
&lt;p>After hundreds of back-and-forths with Opus and Codex on architecture choices, I built a new bot in Golang: &lt;strong>Nagobot&lt;/strong>. At least now I fully control the provider layer.&lt;/p>
&lt;p>Project link: &lt;a class="link" href="https://github.com/linanwx/nagobot" target="_blank" rel="noopener"
>https://github.com/linanwx/nagobot&lt;/a>&lt;/p>
&lt;p>I learned a lot during implementation, especially around:&lt;/p>
&lt;ul>
&lt;li>Threads and concurrent task execution&lt;/li>
&lt;li>Agent and Skill abstractions&lt;/li>
&lt;li>Cron-based asynchronous tasks&lt;/li>
&lt;li>Session history and context compression&lt;/li>
&lt;/ul>
&lt;p>To be honest, a lot of the code still needs deeper review. Most of the work was built in rapid loops with AI-assisted architecture discussions. Sometimes frustrating, sometimes genuinely impressive, and overall very interesting.&lt;/p>
&lt;p>So far, testing results are better than expected. The bot can already create async tasks, investigate news, and set reminders for itself, which is immediately useful in day-to-day workflows.&lt;/p>
&lt;p>Most core features are now in place. My next focus is long-term memory design.&lt;/p>
&lt;p>If this sounds useful to you, feel free to open an issue or reach out. I will keep iterating on this project.&lt;/p></description></item><item><title>Go Types Official Reference</title><link>https://nansenli.com/post/jianshu/go/go%E7%B1%BB%E5%9E%8B%E5%AE%98%E6%96%B9%E5%8F%82%E8%80%83-%E4%B8%AD%E8%8B%B1%E6%96%87%E5%AF%B9%E7%85%A7/</link><pubDate>Wed, 14 Nov 2018 08:14:00 +0000</pubDate><guid>https://nansenli.com/post/jianshu/go/go%E7%B1%BB%E5%9E%8B%E5%AE%98%E6%96%B9%E5%8F%82%E8%80%83-%E4%B8%AD%E8%8B%B1%E6%96%87%E5%AF%B9%E7%85%A7/</guid><description>&lt;h2 id="official-reference">Official Reference
&lt;/h2>&lt;p>&lt;a class="link" href="https://golang.org/ref/spec#Types" target="_blank" rel="noopener"
>https://golang.org/ref/spec#Types&lt;/a>&lt;/p>
&lt;p>The types include:&lt;/p>
&lt;p>Method sets
Boolean types
Numeric types
String types
Array types
Slice types
Struct types
Pointer types
Function types
Interface types
Map types
Channel types&lt;/p>
&lt;h2 id="method-sets">Method sets
&lt;/h2>&lt;p>A type may have a &lt;em>method set&lt;/em> associated with it. The method set of an &lt;a class="link" href="https://golang.org/ref/spec#Interface_types" target="_blank" rel="noopener"
>interface type&lt;/a> is its interface. The method set of any other type &lt;code>T&lt;/code> consists of all &lt;a class="link" href="https://golang.org/ref/spec#Method_declarations" target="_blank" rel="noopener"
>methods&lt;/a> declared with receiver type &lt;code>T&lt;/code>. The method set of the corresponding &lt;a class="link" href="https://golang.org/ref/spec#Pointer_types" target="_blank" rel="noopener"
>pointer type&lt;/a> &lt;code>*T&lt;/code> is the set of all methods declared with receiver &lt;code>*T&lt;/code> or &lt;code>T&lt;/code> (that is, it also contains the method set of &lt;code>T&lt;/code>). Further rules apply to structs containing embedded fields, as described in the section on &lt;a class="link" href="https://golang.org/ref/spec#Struct_types" target="_blank" rel="noopener"
>struct types&lt;/a>. Any other type has an empty method set. In a method set, each method must have a &lt;a class="link" href="https://golang.org/ref/spec#Uniqueness_of_identifiers" target="_blank" rel="noopener"
>unique&lt;/a> non-&lt;a class="link" href="https://golang.org/ref/spec#Blank_identifier" target="_blank" rel="noopener"
>blank&lt;/a>&lt;a class="link" href="https://golang.org/ref/spec#MethodName" target="_blank" rel="noopener"
>method name&lt;/a>.&lt;/p>
&lt;p>The method set of a type determines the interfaces that the type &lt;a class="link" href="https://golang.org/ref/spec#Interface_types" target="_blank" rel="noopener"
>implements&lt;/a> and the methods that can be &lt;a class="link" href="https://golang.org/ref/spec#Calls" target="_blank" rel="noopener"
>called&lt;/a> using a receiver of that type.&lt;/p>
&lt;h2 id="boolean-types">Boolean types
&lt;/h2>&lt;p>A &lt;em>boolean type&lt;/em> represents the set of Boolean truth values denoted by the predeclared constants &lt;code>true&lt;/code> and &lt;code>false&lt;/code>. The predeclared boolean type is &lt;code>bool&lt;/code>; it is a &lt;a class="link" href="https://golang.org/ref/spec#Type_definitions" target="_blank" rel="noopener"
>defined type&lt;/a>.&lt;/p>
&lt;h2 id="numeric-types">Numeric types
&lt;/h2>&lt;p>A numeric type represents sets of integer or floating-point values. The predeclared architecture-independent numeric types are:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">uint8 the set of all unsigned 8-bit integers (0 to 255)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">uint16 the set of all unsigned 16-bit integers (0 to 65535)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">uint32 the set of all unsigned 32-bit integers (0 to 4294967295)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">uint64 the set of all unsigned 64-bit integers (0 to 18446744073709551615)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">int8 the set of all signed 8-bit integers (-128 to 127)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">int16 the set of all signed 16-bit integers (-32768 to 32767)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">int32 the set of all signed 32-bit integers (-2147483648 to 2147483647)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">int64 the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">float32 the set of all IEEE-754 32-bit floating-point numbers
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">float64 the set of all IEEE-754 64-bit floating-point numbers
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">complex64 the set of all complex numbers with float32 real and imaginary parts
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">complex128 the set of all complex numbers with float64 real and imaginary parts
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">byte alias for uint8
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">rune alias for int32
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>The value of an &lt;em>n&lt;/em>-bit integer is &lt;em>n&lt;/em> bits wide and represented using &lt;a class="link" href="https://en.wikipedia.org/wiki/Two%27s_complement" target="_blank" rel="noopener"
>two&amp;rsquo;s complement arithmetic&lt;/a>.&lt;/p>
&lt;p>There is also a set of predeclared numeric types with implementation-specific sizes:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">uint either 32 or 64 bits
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">int same size as uint
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">uintptr an unsigned integer large enough to store the uninterpreted bits of a pointer value
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>To avoid portability issues all numeric types are &lt;a class="link" href="https://golang.org/ref/spec#Type_definitions" target="_blank" rel="noopener"
>defined types&lt;/a> and thus distinct except &lt;code>byte&lt;/code>, which is an &lt;a class="link" href="https://golang.org/ref/spec#Alias_declarations" target="_blank" rel="noopener"
>alias&lt;/a> for &lt;code>uint8&lt;/code>, and &lt;code>rune&lt;/code>, which is an alias for &lt;code>int32&lt;/code>. Conversions are required when different numeric types are mixed in an expression or assignment. For instance, &lt;code>int32&lt;/code> and &lt;code>int&lt;/code> are not the same type even though they may have the same size on a particular architecture.&lt;/p>
&lt;h2 id="string-types">String types
&lt;/h2>&lt;p>A &lt;em>string type&lt;/em> represents the set of string values. A string value is a (possibly empty) sequence of bytes. Strings are immutable: once created, it is impossible to change the contents of a string. The predeclared string type is &lt;code>string&lt;/code>; it is a &lt;a class="link" href="https://golang.org/ref/spec#Type_definitions" target="_blank" rel="noopener"
>defined type&lt;/a>.&lt;/p>
&lt;p>The length of a string &lt;code>s&lt;/code> (its size in bytes) can be discovered using the built-in function &lt;a class="link" href="https://golang.org/ref/spec#Length_and_capacity" target="_blank" rel="noopener"
>&lt;code>len&lt;/code>&lt;/a>. The length is a compile-time constant if the string is a constant. A string&amp;rsquo;s bytes can be accessed by integer &lt;a class="link" href="https://golang.org/ref/spec#Index_expressions" target="_blank" rel="noopener"
>indices&lt;/a> 0 through &lt;code>len(s)-1&lt;/code>. It is illegal to take the address of such an element; if &lt;code>s[i]&lt;/code> is the &lt;code>i&lt;/code>&amp;lsquo;th byte of a string, &lt;code>&amp;amp;s[i]&lt;/code> is invalid.&lt;/p>
&lt;h2 id="array-types">Array types
&lt;/h2>&lt;p>An array is a numbered sequence of elements of a single type, called the element type. The number of elements is called the length and is never negative.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">ArrayType = &amp;#34;[&amp;#34; ArrayLength &amp;#34;]&amp;#34; ElementType .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">ArrayLength = Expression .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">ElementType = Type .
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>The length is part of the array&amp;rsquo;s type; it must evaluate to a non-negative &lt;a class="link" href="https://golang.org/ref/spec#Constants" target="_blank" rel="noopener"
>constant&lt;/a> &lt;a class="link" href="https://golang.org/ref/spec#Representability" target="_blank" rel="noopener"
>representable&lt;/a> by a value of type &lt;code>int&lt;/code>. The length of array &lt;code>a&lt;/code> can be discovered using the built-in function &lt;a class="link" href="https://golang.org/ref/spec#Length_and_capacity" target="_blank" rel="noopener"
>&lt;code>len&lt;/code>&lt;/a>. The elements can be addressed by integer &lt;a class="link" href="https://golang.org/ref/spec#Index_expressions" target="_blank" rel="noopener"
>indices&lt;/a> 0 through &lt;code>len(a)-1&lt;/code>. Array types are always one-dimensional but may be composed to form multi-dimensional types.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">[32]byte
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">[2*N] struct { x, y int32 }
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">[1000]*float64
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">[3][5]int
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">[2][2][2]float64 // same as [2]([2]([2]float64))
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="slice-types">Slice types
&lt;/h2>&lt;p>A slice is a descriptor for a contiguous segment of an &lt;em>underlying array&lt;/em> and provides access to a numbered sequence of elements from that array. A slice type denotes the set of all slices of arrays of its element type. The value of an uninitialized slice is &lt;code>nil&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">SliceType = &amp;#34;[&amp;#34; &amp;#34;]&amp;#34; ElementType .
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Like arrays, slices are indexable and have a length. The length of a slice &lt;code>s&lt;/code> can be discovered by the built-in function &lt;a class="link" href="https://golang.org/ref/spec#Length_and_capacity" target="_blank" rel="noopener"
>&lt;code>len&lt;/code>&lt;/a>; unlike with arrays it may change during execution. The elements can be addressed by integer &lt;a class="link" href="https://golang.org/ref/spec#Index_expressions" target="_blank" rel="noopener"
>indices&lt;/a> 0 through &lt;code>len(s)-1&lt;/code>. The slice index of a given element may be less than the index of the same element in the underlying array.&lt;/p>
&lt;p>A slice, once initialized, is always associated with an underlying array that holds its elements. A slice therefore shares storage with its array and with other slices of the same array; by contrast, distinct arrays always represent distinct storage.&lt;/p>
&lt;p>The array underlying a slice may extend past the end of the slice. The &lt;em>capacity&lt;/em> is a measure of that extent: it is the sum of the length of the slice and the length of the array beyond the slice; a slice of length up to that capacity can be created by &lt;a class="link" href="https://golang.org/ref/spec#Slice_expressions" target="_blank" rel="noopener"
>&lt;em>slicing&lt;/em>&lt;/a> a new one from the original slice. The capacity of a slice &lt;code>a&lt;/code> can be discovered using the built-in function &lt;a class="link" href="https://golang.org/ref/spec#Length_and_capacity" target="_blank" rel="noopener"
>&lt;code>cap(a)&lt;/code>&lt;/a>.&lt;/p>
&lt;p>A new, initialized slice value for a given element type &lt;code>T&lt;/code> is made using the built-in function &lt;a class="link" href="https://golang.org/ref/spec#Making_slices_maps_and_channels" target="_blank" rel="noopener"
>&lt;code>make&lt;/code>&lt;/a>, which takes a slice type and parameters specifying the length and optionally the capacity. A slice created with &lt;code>make&lt;/code> always allocates a new, hidden array to which the returned slice value refers. That is, executing&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">make([]T, length, capacity)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>produces the same slice as allocating an array and &lt;a class="link" href="https://golang.org/ref/spec#Slice_expressions" target="_blank" rel="noopener"
>slicing&lt;/a> it, so these two expressions are equivalent:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">make([]int, 50, 100)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">new([100]int)[0:50]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Like arrays, slices are always one-dimensional but may be composed to construct higher-dimensional objects. With arrays of arrays, the inner arrays are, by construction, always the same length; however with slices of slices (or arrays of slices), the inner lengths may vary dynamically. Moreover, the inner slices must be initialized individually.&lt;/p>
&lt;h2 id="struct-types">Struct types
&lt;/h2>&lt;p>A struct is a sequence of named elements, called fields, each of which has a name and a type. Field names may be specified explicitly (IdentifierList) or implicitly (EmbeddedField). Within a struct, non-&lt;a class="link" href="https://golang.org/ref/spec#Blank_identifier" target="_blank" rel="noopener"
>blank&lt;/a> field names must be &lt;a class="link" href="https://golang.org/ref/spec#Uniqueness_of_identifiers" target="_blank" rel="noopener"
>unique&lt;/a>.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">StructType = &amp;#34;struct&amp;#34; &amp;#34;{&amp;#34; { FieldDecl &amp;#34;;&amp;#34; } &amp;#34;}&amp;#34; .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">FieldDecl = (IdentifierList Type | EmbeddedField) [ Tag ] .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">EmbeddedField = [ &amp;#34;*&amp;#34; ] TypeName .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Tag = string_lit .
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">// An empty struct.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">struct {}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">// A struct with 6 fields.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">struct {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> x, y int
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> u float32
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> _ float32 // padding
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> A *[]int
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> F func()
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>A field declared with a type but no explicit field name is called an embedded field. An embedded field must be specified as a type name T or as a pointer to a non-interface type name *T, and T itself may not be a pointer type. The unqualified type name acts as the field name.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">// A struct with four embedded fields of types T1, *T2, P.T3 and *P.T4
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">struct {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> T1 // field name is T1
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> *T2 // field name is T2
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> P.T3 // field name is T3
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> *P.T4 // field name is T4
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> x, y int // field names are x and y
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>The following declaration is illegal because field names must be unique in a struct type:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">struct {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> T // conflicts with embedded field *T and *P.T
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> *T // conflicts with embedded field T and *P.T
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> *P.T // conflicts with embedded field T and *T
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>A field or &lt;a class="link" href="https://golang.org/ref/spec#Method_declarations" target="_blank" rel="noopener"
>method&lt;/a> &lt;code>f&lt;/code> of an embedded field in a struct &lt;code>x&lt;/code> is called &lt;em>promoted&lt;/em> if &lt;code>x.f&lt;/code> is a legal &lt;a class="link" href="https://golang.org/ref/spec#Selectors" target="_blank" rel="noopener"
>selector&lt;/a> that denotes that field or method &lt;code>f&lt;/code>.&lt;/p>
&lt;p>Promoted fields act like ordinary fields of a struct except that they cannot be used as field names in &lt;a class="link" href="https://golang.org/ref/spec#Composite_literals" target="_blank" rel="noopener"
>composite literals&lt;/a> of the struct.&lt;/p>
&lt;p>Given a struct type &lt;code>S&lt;/code> and a &lt;a class="link" href="https://golang.org/ref/spec#Type_definitions" target="_blank" rel="noopener"
>defined type&lt;/a> &lt;code>T&lt;/code>, promoted methods are included in the method set of the struct as follows:&lt;/p>
&lt;ul>
&lt;li>If &lt;code>S&lt;/code> contains an embedded field &lt;code>T&lt;/code>, the &lt;a class="link" href="https://golang.org/ref/spec#Method_sets" target="_blank" rel="noopener"
>method sets&lt;/a> of &lt;code>S&lt;/code> and &lt;code>*S&lt;/code> both include promoted methods with receiver &lt;code>T&lt;/code>. The method set of &lt;code>*S&lt;/code> also includes promoted methods with receiver &lt;code>*T&lt;/code>.&lt;/li>
&lt;li>If &lt;code>S&lt;/code> contains an embedded field &lt;code>*T&lt;/code>, the method sets of &lt;code>S&lt;/code> and &lt;code>*S&lt;/code> both include promoted methods with receiver &lt;code>T&lt;/code> or&lt;code>*T&lt;/code>.&lt;/li>
&lt;/ul>
&lt;p>A field declaration may be followed by an optional string literal &lt;em>tag&lt;/em>, which becomes an attribute for all the fields in the corresponding field declaration. An empty tag string is equivalent to an absent tag. The tags are made visible through a &lt;a class="link" href="https://golang.org/pkg/reflect/#StructTag" target="_blank" rel="noopener"
>reflection interface&lt;/a> and take part in &lt;a class="link" href="https://golang.org/ref/spec#Type_identity" target="_blank" rel="noopener"
>type identity&lt;/a> for structs but are otherwise ignored.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">struct {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> x, y float64 &amp;#34;&amp;#34; // an empty tag string is like an absent tag
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> name string &amp;#34;any string is permitted as a tag&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> _ [4]byte &amp;#34;ceci n&amp;#39;est pas un champ de structure&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">// A struct corresponding to a TimeStamp protocol buffer.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">// The tag strings define the protocol buffer field numbers;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">// they follow the convention outlined by the reflect package.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">struct {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> microsec uint64 `protobuf:&amp;#34;1&amp;#34;`
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> serverIP6 uint64 `protobuf:&amp;#34;2&amp;#34;`
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="pointer-types">Pointer types
&lt;/h2>&lt;p>A pointer type denotes the set of all pointers to variables of a given type, called the base type of the pointer. The value of an uninitialized pointer is nil.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">PointerType = &amp;#34;*&amp;#34; BaseType .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">BaseType = Type .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">*Point
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">*[4]int
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="function-types">Function types
&lt;/h2>&lt;p>A function type denotes the set of all functions with the same parameter and result types. The value of an uninitialized variable of function type is nil.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">FunctionType = &amp;#34;func&amp;#34; Signature .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Signature = Parameters [ Result ] .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Result = Parameters | Type .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Parameters = &amp;#34;(&amp;#34; [ ParameterList [ &amp;#34;,&amp;#34; ] ] &amp;#34;)&amp;#34; .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">ParameterList = ParameterDecl { &amp;#34;,&amp;#34; ParameterDecl } .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">ParameterDecl = [ IdentifierList ] [ &amp;#34;...&amp;#34; ] Type .
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Within a list of parameters or results, the names (IdentifierList) must either all be present or all be absent. If present, each name stands for one item (parameter or result) of the specified type and all non-blank names in the signature must be unique. If absent, each type stands for one item of that type. Parameter and result lists are always parenthesized except that if there is exactly one unnamed result it may be written as an unparenthesized type.&lt;/p>
&lt;p>The final incoming parameter in a function signature may have a type prefixed with &amp;hellip;. A function with such a parameter is called variadic and may be invoked with zero or more arguments for that parameter.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">func()
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">func(x int) int
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">func(a, _ int, z float32) bool
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">func(a, b int, z float32) (bool)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">func(prefix string, values ...int)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">func(a, b int, z float64, opt ...interface{}) (success bool)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">func(int, int, float64) (float64, *[]int)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">func(n int) func(p *T)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="interface-types">Interface types
&lt;/h2>&lt;p>An interface type specifies a method set called its interface. A variable of interface type can store a value of any type with a method set that is any superset of the interface. Such a type is said to implement the interface. The value of an uninitialized variable of interface type is nil.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">InterfaceType = &amp;#34;interface&amp;#34; &amp;#34;{&amp;#34; { MethodSpec &amp;#34;;&amp;#34; } &amp;#34;}&amp;#34; .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">MethodSpec = MethodName Signature | InterfaceTypeName .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">MethodName = identifier .
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">InterfaceTypeName = TypeName .
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>As with all method sets, in an interface type, each method must have a unique non-blank name.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">// A simple File interface
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">interface {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Read(b Buffer) bool
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Write(b Buffer) bool
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Close()
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>More than one type may implement an interface. For instance, if two types S1 and S2 have the method set&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-gdscript3" data-lang="gdscript3">&lt;span class="line">&lt;span class="cl">&lt;span class="k">func&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">p&lt;/span> &lt;span class="n">T&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">Read&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">b&lt;/span> &lt;span class="n">Buffer&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="ne">bool&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">return&lt;/span> &lt;span class="err">…&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">func&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">p&lt;/span> &lt;span class="n">T&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">Write&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">b&lt;/span> &lt;span class="n">Buffer&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="ne">bool&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">return&lt;/span> &lt;span class="err">…&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">func&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">p&lt;/span> &lt;span class="n">T&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">Close&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="err">…&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>(where T stands for either S1 or S2) then the File interface is implemented by both S1 and S2, regardless of what other methods S1 and S2 may have or share.&lt;/p>
&lt;p>A type implements any interface comprising any subset of its methods and may therefore implement several distinct interfaces. For instance, all types implement the empty interface:&lt;/p>
&lt;p>interface{}
Similarly, consider this interface specification, which appears within a type declaration to define an interface called Locker:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">type Locker interface {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Lock()
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Unlock()
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>If S1 and S2 also implement&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-gdscript3" data-lang="gdscript3">&lt;span class="line">&lt;span class="cl">&lt;span class="k">func&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">p&lt;/span> &lt;span class="n">T&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">Lock&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="err">…&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">func&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">p&lt;/span> &lt;span class="n">T&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">Unlock&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="err">…&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>they implement the Locker interface as well as the File interface.&lt;/p>
&lt;p>An interface T may use a (possibly qualified) interface type name E in place of a method specification. This is called embedding interface E in T; it adds all (exported and non-exported) methods of E to the interface T.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">type ReadWriter interface {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Read(b Buffer) bool
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Write(b Buffer) bool
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">type File interface {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ReadWriter // same as adding the methods of ReadWriter
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Locker // same as adding the methods of Locker
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Close()
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">type LockedFile interface {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Locker
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> File // illegal: Lock, Unlock not unique
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Lock() // illegal: Lock not unique
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>An interface type T may not embed itself or any interface type that embeds T, recursively.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">// illegal: Bad cannot embed itself
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">type Bad interface {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Bad
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">// illegal: Bad1 cannot embed itself using Bad2
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">type Bad1 interface {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Bad2
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">type Bad2 interface {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Bad1
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="map-types">Map types
&lt;/h2>&lt;p>A map is an unordered group of elements of one type, called the element type, indexed by a set of unique keys of another type, called the key type. The value of an uninitialized map is nil.&lt;/p>
&lt;p>MapType = &amp;ldquo;map&amp;rdquo; &amp;ldquo;[&amp;rdquo; KeyType &amp;ldquo;]&amp;rdquo; ElementType .
KeyType = Type .
The comparison operators == and != must be fully defined for operands of the key type; thus the key type must not be a function, map, or slice. If the key type is an interface type, these comparison operators must be defined for the dynamic key values; failure will cause a run-time panic.&lt;/p>
&lt;p>map[string]int
map[*T]struct{ x, y float64 }
map[string]interface{}
The number of map elements is called its length. For a map m, it can be discovered using the built-in function len and may change during execution. Elements may be added during execution using assignments and retrieved with index expressions; they may be removed with the delete built-in function.&lt;/p>
&lt;p>A new, empty map value is made using the built-in function make, which takes the map type and an optional capacity hint as arguments:&lt;/p>
&lt;p>make(map[string]int)
make(map[string]int, 100)
The initial capacity does not bound its size: maps grow to accommodate the number of items stored in them, with the exception of nil maps. A nil map is equivalent to an empty map except that no elements may be added.&lt;/p>
&lt;h2 id="channel-types">Channel types
&lt;/h2>&lt;p>A channel provides a mechanism for concurrently executing functions to communicate by sending and receiving values of a specified element type. The value of an uninitialized channel is nil.&lt;/p>
&lt;p>ChannelType = ( &amp;ldquo;chan&amp;rdquo; | &amp;ldquo;chan&amp;rdquo; &amp;ldquo;&amp;lt;-&amp;rdquo; | &amp;ldquo;&amp;lt;-&amp;rdquo; &amp;ldquo;chan&amp;rdquo; ) ElementType .
The optional &amp;lt;- operator specifies the channel direction, send or receive. If no direction is given, the channel is bidirectional. A channel may be constrained only to send or only to receive by conversion or assignment.&lt;/p>
&lt;p>chan T // can be used to send and receive values of type T
chan&amp;lt;- float64 // can only be used to send float64s
&amp;lt;-chan int // can only be used to receive ints
The &amp;lt;- operator associates with the leftmost chan possible:&lt;/p>
&lt;p>chan&amp;lt;- chan int // same as chan&amp;lt;- (chan int)
chan&amp;lt;- &amp;lt;-chan int // same as chan&amp;lt;- (&amp;lt;-chan int)
&amp;lt;-chan &amp;lt;-chan int // same as &amp;lt;-chan (&amp;lt;-chan int)
chan (&amp;lt;-chan int)
A new, initialized channel value can be made using the built-in function make, which takes the channel type and an optional capacity as arguments:&lt;/p>
&lt;p>make(chan int, 100)
The capacity, in number of elements, sets the size of the buffer in the channel. If the capacity is zero or absent, the channel is unbuffered and communication succeeds only when both a sender and receiver are ready. Otherwise, the channel is buffered and communication succeeds without blocking if the buffer is not full (sends) or not empty (receives). A nil channel is never ready for communication.&lt;/p>
&lt;p>A channel may be closed with the built-in function close. The multi-valued assignment form of the receive operator reports whether a received value was sent before the channel was closed.&lt;/p>
&lt;p>A single channel may be used in send statements, receive operations, and calls to the built-in functions cap and len by any number of goroutines without further synchronization. Channels act as first-in-first-out queues. For example, if one goroutine sends values on a channel and a second goroutine receives them, the values are received in the order sent.&lt;/p></description></item><item><title>2018-09-20 Go Learning Notes</title><link>https://nansenli.com/post/jianshu/go/2018-09-20-go%E5%AD%A6%E4%B9%A0%E6%8B%BE%E8%B4%9D/</link><pubDate>Wed, 07 Nov 2018 06:54:00 +0000</pubDate><guid>https://nansenli.com/post/jianshu/go/2018-09-20-go%E5%AD%A6%E4%B9%A0%E6%8B%BE%E8%B4%9D/</guid><description>&lt;h2 id="gos-pointers-and-values-behave-differently-when-used-as-receivers-and-parameters">Go&amp;rsquo;s pointers and values behave differently when used as receivers and parameters
&lt;/h2>&lt;p>Methods and pointer indirection
When comparing the first two programs, you might notice that functions with pointer parameters must accept a pointer:&lt;/p>
&lt;p>var v Vertex
ScaleFunc(v, 5) // Compile error!
ScaleFunc(&amp;amp;v, 5) // OK
However, methods with pointer receivers can be called with both values and pointers:&lt;/p>
&lt;p>var v Vertex
v.Scale(5) // OK
p := &amp;amp;v
p.Scale(10) // OK
For the statement v.Scale(5), even though v is a value and not a pointer, methods with pointer receivers can still be called directly. In other words, since the Scale method has a pointer receiver, for convenience, Go interprets the statement v.Scale(5) as (&amp;amp;v).Scale(5).&lt;/p>
&lt;p>Additionally, Go automatically interprets the . operation on pointers as (*).&lt;/p></description></item><item><title>2018-08-30 Go Learning Notes</title><link>https://nansenli.com/post/jianshu/go/2018-08-30-go%E5%AD%A6%E4%B9%A0%E6%8B%BE%E8%B4%9D/</link><pubDate>Sat, 01 Sep 2018 13:40:00 +0000</pubDate><guid>https://nansenli.com/post/jianshu/go/2018-08-30-go%E5%AD%A6%E4%B9%A0%E6%8B%BE%E8%B4%9D/</guid><description>&lt;ul>
&lt;li>In functions, the short assignment statement := can replace var declarations where the type is clear. However, constants must be declared using const&lt;/li>
&lt;li>Outside of functions, every statement must start with a keyword (var, func, etc.), therefore := syntax cannot be used outside of functions.&lt;/li>
&lt;li>Why Go uses trailing type declarations: &lt;a class="link" href="https://blog.go-zh.org/gos-declaration-syntax" target="_blank" rel="noopener"
>https://blog.go-zh.org/gos-declaration-syntax&lt;/a>&lt;/li>
&lt;li>Go has the following types:&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">bool
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">string
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">int int8 int16 int32 int64
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">uint uint8 uint16 uint32 uint64 uintptr
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">byte // alias for uint8
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">rune // alias for int32
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> // represents a Unicode code point
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">float32 float64
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">complex64 complex128
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;ul>
&lt;li>When you need an integer value, you should use the int type, unless you have a specific reason to use a fixed size or unsigned integer type.&lt;/li>
&lt;li>Go does not support implicit type conversion&lt;/li>
&lt;/ul></description></item></channel></rss>