-
Notifications
You must be signed in to change notification settings - Fork 0
/
visib.go
83 lines (69 loc) · 1.23 KB
/
visib.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// START1 OMIT
package main
import (
"errors"
"fmt"
)
//A is exported and visible form outside this package
var A int
var (
B string = "hello"
x, y, z float32
//p is not exported and not visible outside this package
p *int
)
// STOP1 OMIT
// STARTF OMIT
const (
C int = iota //0
D //1
E //2
Big = 1 << 100
)
func F(a, b int) (int, float32) {
return f(a, b), float32(a) / float32(b) // no implicit conversion
}
func f(p, q int) int {
res := p + q //shorthand variable declaration
return res
}
// STOPF OMIT
// START2 OMIT
type Q struct { //exported type
a, b, c int //not exported fields
D int //exported field
buf [256]byte
}
func (q Q) SumABC() int {
return q.a + q.b + q.c
}
func (q Q) A() int {
return q.a
}
func (q *Q) SetFlag(offset int, flag byte) (err error) {
if offset > 255 || offset < 0 {
err = errors.New("wrong offset")
return
} else {
q.buf[uint8(offset)] = flag
return nil
}
}
// STOP2 OMIT
/*
// START3 OMIT
type error interface {
Error() string
}
// STOP3 OMIT
*/
// START4 OMIT
type CoolError struct {
A int
B float64
C complex128
}
func (ce CoolError) Error() string {
return fmt.Sprintf("Error %d, %f, f%", ce.A, ce.B, ce.C)
}
// STOP4 OMIT