| 1 | <h2>Comments</h2> |
| 2 | <pre><code>// This is a comment |
| 3 | /* This is a comment |
| 4 | on multiple lines */</code></pre> |
| 5 | |
| 6 | <h2>Numbers</h2> |
| 7 | <pre><code>42 |
| 8 | 0600 |
| 9 | 0xBadFace |
| 10 | 170141183460469231731687303715884105727 |
| 11 | 0. |
| 12 | 72.40 |
| 13 | 072.40 |
| 14 | 2.71828 |
| 15 | 1.e+0 |
| 16 | 6.67428e-11 |
| 17 | 1E6 |
| 18 | .25 |
| 19 | .12345E+5 |
| 20 | 0i |
| 21 | 011i |
| 22 | 0.i |
| 23 | 2.71828i |
| 24 | 1.e+0i |
| 25 | 6.67428e-11i |
| 26 | 1E6i |
| 27 | .25i |
| 28 | .12345E+5i</code></pre> |
| 29 | |
| 30 | <h2>Runes and strings</h2> |
| 31 | <pre><code>'\t' |
| 32 | '\000' |
| 33 | '\x07' |
| 34 | '\u12e4' |
| 35 | '\U00101234' |
| 36 | `abc` |
| 37 | `multi-line |
| 38 | string` |
| 39 | "Hello, world!" |
| 40 | "multi-line |
| 41 | string"</code></pre> |
| 42 | |
| 43 | <h2>Functions</h2> |
| 44 | <pre><code>func(a, b int, z float64) bool { return a*b < int(z) }</code></pre> |
| 45 | |
| 46 | <h2>Full example</h2> |
| 47 | <pre><code>package main |
| 48 | import "fmt" |
| 49 | |
| 50 | func sum(a []int, c chan int) { |
| 51 | sum := 0 |
| 52 | for _, v := range a { |
| 53 | sum += v |
| 54 | } |
| 55 | c <- sum // send sum to c |
| 56 | } |
| 57 | |
| 58 | func main() { |
| 59 | a := []int{7, 2, 8, -9, 4, 0} |
| 60 | |
| 61 | c := make(chan int) |
| 62 | go sum(a[:len(a)/2], c) |
| 63 | go sum(a[len(a)/2:], c) |
| 64 | x, y := <-c, <-c // receive from c |
| 65 | |
| 66 | fmt.Println(x, y, x+y) |
| 67 | } |
| 68 | </code></pre> |