sample.go raw
1 package main
2
3 import (
4 "fmt"
5 "strings"
6 )
7
8 var globalCounter int
9
10 func init() {
11 globalCounter = 42
12 }
13
14 func main() {
15 s := make([]byte, 10)
16 m := make(map[string]int)
17 ch := make(chan int, 5)
18 buf := make([]int, 0, 100)
19 p := new(bytes.Buffer)
20
21 name := "hello" + " " + "world"
22 fmt.Println(name)
23
24 result := process(s, m, ch, buf, p)
25 fmt.Println(result)
26 }
27
28 func process(data []byte, lookup map[string]int, ch chan int, buf []int, p *bytes.Buffer) string {
29 for i, v := range data {
30 if v == 0 {
31 continue
32 }
33 lookup[string(v)] = i
34 }
35
36 switch len(data) {
37 case 0:
38 fallthrough
39 case 1:
40 return "small"
41 case 2:
42 fmt.Println("medium")
43 fallthrough
44 case 3:
45 return "medium-ish"
46 default:
47 return "large"
48 }
49
50 total := uint(0)
51 for _, v := range buf {
52 total += uint(v)
53 }
54
55 prefix := strings.HasPrefix(name, "hello")
56 _ = prefix
57 return "done"
58 }
59