<pre>
struct {
- T // conflicts with anonymous field *T and *P.T
- *T // conflicts with anonymous field T and *P.T
- *P.T // conflicts with anonymous field T and *T
+ T // conflicts with anonymous field *T and *P.T
+ *T // conflicts with anonymous field T and *P.T
+ *P.T // conflicts with anonymous field T and *T
}
</pre>
<pre>
*int
-*map[string] *chan int
+*map[string]*chan int
</pre>
<h3 id="Function_types">Function types</h3>
</p>
<pre>
-map [string] int
-map [*T] struct { x, y float64 }
-map [string] interface {}
+map[string]int
+map[*T]struct{ x, y float64 }
+map[string]interface{}
</pre>
<p>
</p>
<pre>
-make(map[string] int)
-make(map[string] int, 100)
+make(map[string]int)
+make(map[string]int, 100)
</pre>
<p>
</p>
<pre>
-chan T // can be used to send and receive values of type T
-chan<- float64 // can only be used to send float64s
-<-chan int // can only be used to receive ints
+chan T // can be used to send and receive values of type T
+chan<- float64 // can only be used to send float64s
+<-chan int // can only be used to receive ints
</pre>
<p>
</p>
<pre>
-chan<- chan int // same as chan<- (chan int)
-chan<- <-chan int // same as chan<- (<-chan int)
-<-chan <-chan int // same as <-chan (<-chan int)
+chan<- chan int // same as chan<- (chan int)
+chan<- <-chan int // same as chan<- (<-chan int)
+<-chan <-chan int // same as <-chan (<-chan int)
chan (<-chan int)
</pre>
type (
T0 []string
T1 []string
- T2 struct { a, b int }
- T3 struct { a, c int }
+ T2 struct{ a, b int }
+ T3 struct{ a, c int }
T4 func(int, float64) *T0
T5 func(x int, y float64) *[]string
)
<pre>
T0 and T0
[]int and []int
-struct { a, b *T5 } and struct { a, b *T5 }
+struct{ a, b *T5 } and struct{ a, b *T5 }
func(x int, y float64) *[]string and func(int, float64) (result *[]string)
</pre>
<pre>
const Pi float64 = 3.14159265358979323846
-const zero = 0.0 // untyped floating-point constant
+const zero = 0.0 // untyped floating-point constant
const (
size int64 = 1024
- eof = -1 // untyped integer constant
+ eof = -1 // untyped integer constant
)
const a, b, c = 3, 4, "foo" // a = 3, b = 4, c = "foo", untyped integer and string constants
const u, v float32 = 0, 3 // u = 0.0, v = 3.0
<pre>
const (
- bit0, mask0 = 1 << iota, 1 << iota - 1 // bit0 == 1, mask0 == 0
- bit1, mask1 // bit1 == 2, mask1 == 1
- _, _ // skips iota == 2
- bit3, mask3 // bit3 == 8, mask3 == 7
+ bit0, mask0 = 1 << iota, 1<<iota - 1 // bit0 == 1, mask0 == 0
+ bit1, mask1 // bit1 == 2, mask1 == 1
+ _, _ // skips iota == 2
+ bit3, mask3 // bit3 == 8, mask3 == 7
)
</pre>
type IntArray [16]int
type (
- Point struct { x, y float64 }
+ Point struct{ x, y float64 }
Polar Point
)
var k = 0
var x, y float32 = -1, -2
var (
- i int
+ i int
u, v, s = 2.0, 3.0, "bar"
)
var re, im = complexSqrt(-1)
</p>
<pre>
-buffer := [10]string{} // len(buffer) == 10
-intSet := [6]int{1, 2, 3, 5} // len(intSet) == 6
-days := [...]string{"Sat", "Sun"} // len(days) == 2
+buffer := [10]string{} // len(buffer) == 10
+intSet := [6]int{1, 2, 3, 5} // len(intSet) == 6
+days := [...]string{"Sat", "Sun"} // len(days) == 2
</pre>
<p>
</p>
<pre>
-p.z // (*p).z
-p.y // ((*p).T1).y
-p.x // (*(*p).T0).x
+p.z // (*p).z
+p.y // ((*p).T1).y
+p.x // (*(*p).T0).x
-p.M2 // (*p).M2
-p.M1 // ((*p).T1).M1
-p.M0 // ((*p).T0).M0
+p.M2 // (*p).M2
+p.M1 // ((*p).T1).M1
+p.M0 // ((*p).T0).M0
</pre>
</p>
<pre>
-a[2:] // same a[2 : len(a)]
-a[:3] // same as a[0 : 3]
-a[:] // same as a[0 : len(a)]
+a[2:] // same a[2 : len(a)]
+a[:3] // same as a[0 : 3]
+a[:] // same as a[0 : len(a)]
</pre>
<p>
</p>
<pre>
-math.Atan2(x, y) // function call
+math.Atan2(x, y) // function call
var pt *Point
pt.Scale(3.5) // method call with receiver pt
</pre>
type T struct {
a int
}
-func (tv T) Mv(a int) int { return 0 } // value receiver
+func (tv T) Mv(a int) int { return 0 } // value receiver
func (tp *T) Mp(f float32) float32 { return 1 } // pointer receiver
var t T
</pre>
the range of valid Unicode code points are converted to <code>"\uFFFD"</code>.
<pre>
-string('a') // "a"
-string(-1) // "\ufffd" == "\xef\xbf\xbd "
-string(0xf8) // "\u00f8" == "ø" == "\xc3\xb8"
+string('a') // "a"
+string(-1) // "\ufffd" == "\xef\xbf\xbd "
+string(0xf8) // "\u00f8" == "ø" == "\xc3\xb8"
type MyString string
-MyString(0x65e5) // "\u65e5" == "日" == "\xe6\x97\xa5"
+MyString(0x65e5) // "\u65e5" == "日" == "\xe6\x97\xa5"
</pre>
</li>
the slice value is <code>nil</code>, the result is the empty string.
<pre>
-string([]byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}) // "hellø"
+string([]byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}) // "hellø"
type MyBytes []byte
string(MyBytes{'h', 'e', 'l', 'l', '\xc3', '\xb8'}) // "hellø"
result is the empty string.
<pre>
-string([]rune{0x767d, 0x9d6c, 0x7fd4}) // "\u767d\u9d6c\u7fd4" == "白鵬翔"
+string([]rune{0x767d, 0x9d6c, 0x7fd4}) // "\u767d\u9d6c\u7fd4" == "白鵬翔"
type MyRunes []rune
string(MyRunes{0x767d, 0x9d6c, 0x7fd4}) // "\u767d\u9d6c\u7fd4" == "白鵬翔"
If the string is empty, the result is <code>[]byte(nil)</code>.
<pre>
-[]byte("hellø") // []byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}
-MyBytes("hellø") // []byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}
+[]byte("hellø") // []byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}
+MyBytes("hellø") // []byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}
</pre>
</li>
</p>
<pre>
-uint(-1) // -1 cannot be represented as a uint
-int(3.14) // 3.14 cannot be represented as an int
-int64(Huge) // 1<<100 cannot be represented as an int64
-Four * 300 // 300 cannot be represented as an int8
-Four * 100 // 400 cannot be represented as an int8
+uint(-1) // -1 cannot be represented as a uint
+int(3.14) // 3.14 cannot be represented as an int
+int64(Huge) // 1<<100 cannot be represented as an int64
+Four * 300 // 300 cannot be represented as an int8
+Four * 100 // 400 cannot be represented as an int8
</pre>
<p>
</p>
<pre>
-^1 // untyped integer constant, equal to -2
-uint8(^1) // error, same as uint8(-2), out of range
-^uint8(1) // typed uint8 constant, same as 0xFF ^ uint8(1) = uint8(0xFE)
-int8(^1) // same as int8(-2)
-^int8(1) // same as -1 ^ int8(1) = -2
+^1 // untyped integer constant, equal to -2
+uint8(^1) // error, same as uint8(-2), out of range
+^uint8(1) // typed uint8 constant, same as 0xFF ^ uint8(1) = uint8(0xFE)
+int8(^1) // same as int8(-2)
+^int8(1) // same as -1 ^ int8(1) = -2
</pre>
<!--
For example, in the assignment
</p>
<pre>
-y[f()], ok = g(h(), i() + x[j()], <-c), k()
+y[f()], ok = g(h(), i()+x[j()], <-c), k()
</pre>
<p>
the function calls and communication happen in the order
x := []int{1, 2, 3}
i := 0
-i, x[i] = 1, 2 // set i = 1, x[0] = 2
+i, x[i] = 1, 2 // set i = 1, x[0] = 2
i = 0
x[i], i = 2, 1 // set x[0] = 2, i = 1
x[0], x[0] = 1, 2 // set x[0] = 1, then x[0] = 2 (so x[0] = 2 at end)
-x[1], x[3] = 4, 5 // set x[1] = 4, then panic setting x[3] = 5.
+x[1], x[3] = 4, 5 // set x[1] = 4, then panic setting x[3] = 5.
type Point struct { x, y int }
var p *Point
}
}
-select { } // block forever
+select {} // block forever
</pre>
</p>
<pre>
-s := make([]int, 10, 100) // slice with len(s) == 10, cap(s) == 100
-s := make([]int, 10) // slice with len(s) == cap(s) == 10
-c := make(chan int, 10) // channel with a buffer size of 10
-m := make(map[string] int, 100) // map with initial space for 100 elements
+s := make([]int, 10, 100) // slice with len(s) == 10, cap(s) == 100
+s := make([]int, 10) // slice with len(s) == cap(s) == 10
+c := make(chan int, 10) // channel with a buffer size of 10
+m := make(map[string]int, 100) // map with initial space for 100 elements
</pre>
t = append(t, 42, 3.1415, "foo") t == []interface{}{42, 3.1415, "foo"}
var b []byte
-b = append(b, "bar"...) // append string contents b == []byte{'b', 'a', 'r' }
+b = append(b, "bar"...) // append string contents b == []byte{'b', 'a', 'r' }
</pre>
<p>
// Copy the values from channel 'src' to channel 'dst',
// removing those divisible by 'prime'.
func filter(src <-chan int, dst chan<- int, prime int) {
- for i := range src { // Loop over values received from 'src'.
+ for i := range src { // Loop over values received from 'src'.
if i%prime != 0 {
dst <- i // Send 'i' to channel 'dst'.
}